From 94edfe8c7b2f83650c0f6262e50063ebcdedf29d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 18 Apr 2018 15:18:05 +0200 Subject: minSleep --- nix/module.nix | 14 +++++++++++--- nix/rolling-directory.nix | 2 +- rolling-directory | 17 +++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 10c68ff..3263401 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -14,9 +14,14 @@ let type = with types; either ints.positive str; }; + minSleep = mkOption { + type = with types; nullOr ints.positive; + default = 3600; + }; + monitorTimeout = mkOption { type = with types; nullOr ints.positive; - default = 3600; + default = 3600 * 24; }; }; }; @@ -25,8 +30,11 @@ let wantedBy = [ "multi-user.target" ]; serviceConfig = { - ExecStart = '' - ${pkgs.rolling-directory}/bin/rolling-directory %I ${toString dCfg.maxSize} monitor ${optionalString (dCfg.monitorTimeout != null) (toString dCfg.monitorTimeout)} + ExecStart = let + extraArgs = optionals (dCfg.monitorTimeout != null) ["-t" (toString dCfg.monitorTimeout)] + + optionals (dCfg.minSleep != null) ["-s" (toString dCfg.minSleep)]; + in '' + ${pkgs.rolling-directory}/bin/rolling-directory %I ${toString dCfg.maxSize} monitor ${escapeShellArgs extraArgs} ''; }; }; diff --git a/nix/rolling-directory.nix b/nix/rolling-directory.nix index bb5dd53..4093c36 100644 --- a/nix/rolling-directory.nix +++ b/nix/rolling-directory.nix @@ -4,7 +4,7 @@ stdenv.mkDerivation rec { name = "rolling-directory-${version}"; - version = "0.2"; + version = "0.3"; src = ../rolling-directory; phases = [ "buildPhase" "installPhase" ]; diff --git a/rolling-directory b/rolling-directory index d85f8b7..ce97021 100644 --- a/rolling-directory +++ b/rolling-directory @@ -33,16 +33,25 @@ case "${1}" in monitor) shift + sleep="" typeset -a inotifyExtra inotifyExtra=() - if [[ "${1}" = <-> ]]; then - inotifyExtra=(-t "${1}") - shift - fi + while getopts 's:t:' opt; do + case "${opt}" in + s) + [[ "${OPTARG}" = <-> ]] || exit 2 + sleep=${OPTARG} + ;; + t) + [[ "${OPTARG}" = <-> ]] || exit 2 + inotifyExtra+=(-t "${OPTARG}") + esac + done while resize + [[ -n "$sleep" ]] && sleep ${sleep} inotifywait -qq -r ${dir} ${inotifyExtra} \ -e modify \ -e close_write \ -- cgit v1.2.3