From 715a90b33ca051127509f07aaff3b469755632a9 Mon Sep 17 00:00:00 2001 From: Unrud Date: Mon, 24 Jul 2017 02:31:57 +0200 Subject: [PATCH] Export: Check if export path exists Prevent ``shutil.move`` from moving to .../root --- radicale/__main__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/radicale/__main__.py b/radicale/__main__.py index 36f0dd91..60f9ce3e 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -130,8 +130,11 @@ def export_storage(config, path, debug=False): traceback.print_exc() exit(1) try: + # This check is prone to a race condition + if os.path.exists(path): + raise Exception("Destination path %r already exists" % path) shutil.move(os.path.join(temp, "root"), path) - except (OSError, shutil.Error) as e: + except Exception as e: print("ERROR: Can't create %r directory: %s" % (path, e)) if debug: traceback.print_exc()