From dc31eae31c57be2ffd79a6b561b519875cf26423 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 8 Aug 2008 11:21:00 +0000 Subject: [PATCH] backend: Add function to check whether file is in queue dir Another function will need to check whether its parameters are job queue files. Reviewed-by: iustinp --- lib/backend.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 68b1653d1..f157c196f 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 -- GitLab