From ea5c42ce7c7bb229dc2ec86305790ee96a420519 Mon Sep 17 00:00:00 2001 From: Daniela Bauer Date: Tue, 10 Sep 2024 15:27:26 +0100 Subject: [PATCH] fix: check if requested path exists and return error if not --- .../scripts/dirac_dms_find_lfns.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/DIRAC/DataManagementSystem/scripts/dirac_dms_find_lfns.py b/src/DIRAC/DataManagementSystem/scripts/dirac_dms_find_lfns.py index 0ea9f6bfe4f..877e7b0a452 100755 --- a/src/DIRAC/DataManagementSystem/scripts/dirac_dms_find_lfns.py +++ b/src/DIRAC/DataManagementSystem/scripts/dirac_dms_find_lfns.py @@ -11,7 +11,7 @@ @Script() def main(): - Script.registerSwitch("", "Path=", " Path to search for") + Script.registerSwitch("", "Path=", " Directory path to search for") Script.registerSwitch("", "SE=", " (comma-separated list of) SEs/SE-groups to be searched") # Registering arguments will automatically add their description to the help menu Script.registerArgument( @@ -59,7 +59,17 @@ def main(): DIRAC.exit(-1) metaDict = result["Value"] path = metaDict.pop("Path", path) - + # check if path exists and is a directory + result = fc.isDirectory(path) + if not result["OK"]: + gLogger.error("Can not access File Catalog:", result["Message"]) + DIRAC.exit(-1) + if path not in result["Value"]["Successful"]: + gLogger.error("Failed to query path status in file catalogue.", result["Message"]) + DIRAC.exit(-1) + if not result["Value"]["Successful"][path]: + gLogger.error(f"{path} does not exist or is not a directory.") + DIRAC.exit(-1) result = fc.findFilesByMetadata(metaDict, path) if not result["OK"]: gLogger.error("Can not access File Catalog:", result["Message"])