diff --git a/lib/backend.py b/lib/backend.py index 68b1653d1bd2502f50074c7a961f1de6a76fb02f..f157c196f16151cc802cdbe268384db908bce6a0 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -1655,14 +1655,25 @@ def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir): return result -def JobQueueUpdate(file_name, content): - """Updates a file in the queue directory. +def _IsJobQueueFile(file_name): + """Checks whether the given filename is in the queue directory. """ queue_dir = os.path.normpath(constants.QUEUE_DIR) - if os.path.commonprefix([queue_dir, file_name]) != queue_dir: + result = (os.path.commonprefix([queue_dir, file_name]) == queue_dir) + + if not result: logging.error("'%s' is not a file in the queue directory", file_name) + + return result + + +def JobQueueUpdate(file_name, content): + """Updates a file in the queue directory. + + """ + if not _IsJobQueueFile(file_name): return False # Write and replace the file atomically