From dbef30e1b41fafdad8abacc09960ba88220a304e Mon Sep 17 00:00:00 2001 From: libook Date: Fri, 12 Aug 2022 16:10:28 +0800 Subject: [PATCH 1/2] Add --force-zero support for sync --- snapraid-runner.conf.example | 4 ++++ snapraid-runner.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/snapraid-runner.conf.example b/snapraid-runner.conf.example index bc8fca4..6ceb809 100644 --- a/snapraid-runner.conf.example +++ b/snapraid-runner.conf.example @@ -42,3 +42,7 @@ enabled = false plan = 12 ; minimum block age (in days) for scrubbing. Only used with percentage plans older-than = 10 + +[sync] +; set to true to force sync files with zero size +force-zero = false diff --git a/snapraid-runner.py b/snapraid-runner.py index 56b8e9e..cf377f6 100755 --- a/snapraid-runner.py +++ b/snapraid-runner.py @@ -133,7 +133,7 @@ def load_config(args): global config parser = configparser.RawConfigParser() parser.read(args.conf) - sections = ["snapraid", "logging", "email", "smtp", "scrub"] + sections = ["snapraid", "logging", "email", "smtp", "scrub", "sync"] config = dict((x, defaultdict(lambda: "")) for x in sections) for section in parser.sections(): for (k, v) in parser.items(section): @@ -154,6 +154,7 @@ def load_config(args): config["scrub"]["enabled"] = (config["scrub"]["enabled"].lower() == "true") config["email"]["short"] = (config["email"]["short"].lower() == "true") config["snapraid"]["touch"] = (config["snapraid"]["touch"].lower() == "true") + config["sync"]["force-zero"] = (config["sync"]["force-zero"].lower() == "true") # Migration if config["scrub"]["percentage"]: @@ -281,8 +282,11 @@ def run(): logging.info("No changes detected, no sync required") else: logging.info("Running sync...") + sync_args: dict[str, str] = {} + if config["sync"]["force-zero"]: + sync_args["force-zero"] = "" try: - snapraid_command("sync") + snapraid_command("sync", sync_args) except subprocess.CalledProcessError as e: logging.error(e) finish(False) From 8931a1863086dfdd49f022e4605ca45712a38dfc Mon Sep 17 00:00:00 2001 From: libook Date: Fri, 12 Aug 2022 17:41:57 +0800 Subject: [PATCH 2/2] Fix empty string as argument --- snapraid-runner.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snapraid-runner.py b/snapraid-runner.py index cf377f6..e12681c 100755 --- a/snapraid-runner.py +++ b/snapraid-runner.py @@ -41,7 +41,9 @@ def snapraid_command(command, args={}, *, allow_statuscodes=[]): arguments = ["--conf", config["snapraid"]["config"], "--quiet"] for (k, v) in args.items(): - arguments.extend(["--" + k, str(v)]) + arguments.append("--" + k) + if v != '': + arguments.append(str(v)) p = subprocess.Popen( [config["snapraid"]["executable"], command] + arguments, stdout=subprocess.PIPE,