From 5c6dfda09fcfde929216eb7f389283b9a545543d Mon Sep 17 00:00:00 2001 From: Cristiano Urban Date: Fri, 9 Apr 2021 17:22:20 +0200 Subject: [PATCH] Minor improvements. Signed-off-by: Cristiano Urban --- transfer_service/cleaner.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/transfer_service/cleaner.py b/transfer_service/cleaner.py index d656063..2577ac1 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 -- GitLab