diff --git a/transfer_service/cleaner.py b/transfer_service/cleaner.py index d656063d532cc3e75aab469840b7eb710f2ac6ae..2577ac10f941bae0e7c96cde6d779ca78171531f 100644 --- a/transfer_service/cleaner.py +++ b/transfer_service/cleaner.py @@ -32,14 +32,14 @@ fileList = dbConn.getNodesToBeDeleted() basePaths = [] for row in fileList: basePath = row["os_base_path"] - relPath = row["os_rel_path"] + relPath = row["os_rel_path"] filePath = basePath + relPath dTime = row["deleted_on"] cTime = datetime.datetime.now() phyDeletedTstamp = row["phy_deleted_on"] nodeId = row["node_id"] delta = cTime - dTime - if delta.days >= days and delta.seconds > seconds and phyDeletedTstamp is None: + if delta.days >= days and delta.seconds > seconds and phyDeletedTstamp is None: os.remove(filePath) print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ' ' + filePath) dbConn.setPhyDeletedOn(nodeId) @@ -47,10 +47,12 @@ for row in fileList: basePaths.append(basePath) for basePath in basePaths: - for root, dir, files in os.walk(basePath, topdown = False): - if root != basePath and not os.listdir(root): - os.rmdir(root) - print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ' ' + root) + for root, dirs, files in os.walk(basePath, topdown = False): + for dir in dirs: + dirPath = os.path.abspath(root) + '/' + dir + if not os.listdir(dirPath): + os.rmdir(dirPath) + print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + ' ' + dirPath) # 1) delete files and update the db # 2) check for empty dirs and delete them if different from rootPath