Commit 5b951502 authored by kezzle's avatar kezzle
Browse files

Recursively create the remote safe directory

Previously if the remote safe directory wasn't fully created, the script
would crash and leave files in the remote processing directory
parent d961a32a
......@@ -357,6 +357,18 @@ def main():
class ProcessingClient(wc.Client):
def mkdir_recursive(self, path: str):
"""Loop through the parts of a path, and create them all"""
# build and create each subdirectory one path component at a time
full_path: str = ""
for component in path.split("/"):
full_path = join(full_path, component)
if not self.mkdir(full_path):
# couldn't create the directory, return an error
return False
return True
def process_path(self, folder, path):
if is_special_folder(path):
logging.debug("found special folder %s, skipping", path)
......@@ -442,8 +454,12 @@ class ProcessingClient(wc.Client):
# 6. on success, upload the sanitized file to a safe/
# folder, move the original to dangerzone/processed
remote_safe_path = join(folder, "safe", path)
remote_safe_directory = join(folder, "safe")
remote_safe_path = join(remote_safe_directory, path)
local_safe_path = join(self.sanitizer.safe_dir, path)
logging.info(f"recursively creating remote safe directory {remote_safe_directory}")
if not self.dryrun:
self.mkdir_recursive(remote_safe_directory)
logging.info(
"uploading %s to %s", local_safe_path, remote_safe_path
)
......
Supports Markdown
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