Commit dc31eae3 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

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
parent 7f30777b
...@@ -1655,14 +1655,25 @@ def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir): ...@@ -1655,14 +1655,25 @@ def RenameFileStorageDir(old_file_storage_dir, new_file_storage_dir):
return result return result
def JobQueueUpdate(file_name, content): def _IsJobQueueFile(file_name):
"""Updates a file in the queue directory. """Checks whether the given filename is in the queue directory.
""" """
queue_dir = os.path.normpath(constants.QUEUE_DIR) 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", logging.error("'%s' is not a file in the queue directory",
file_name) file_name)
return result
def JobQueueUpdate(file_name, content):
"""Updates a file in the queue directory.
"""
if not _IsJobQueueFile(file_name):
return False return False
# Write and replace the file atomically # Write and replace the file atomically
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment