From 38c726b324bf13e1d1b9e7cc52d4cea108fe31ce Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 20 Feb 2023 11:38:40 -0700 Subject: add FILE:EMPTY-DIRECTORY-DOES-NOT-EXIST Signed-off-by: Sean Whitton --- src/package.lisp | 1 + src/property/file.lisp | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/package.lisp b/src/package.lisp index 856d75a..6b72a1b 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -432,6 +432,7 @@ #:has-ownership #:does-not-exist #:directory-does-not-exist + #:empty-directory-does-not-exist #:data-uploaded #:host-data-uploaded #:secret-uploaded diff --git a/src/property/file.lisp b/src/property/file.lisp index 38c3780..251d8b0 100644 --- a/src/property/file.lisp +++ b/src/property/file.lisp @@ -1,6 +1,6 @@ ;;; Consfigurator -- Lisp declarative configuration management system -;;; Copyright (C) 2020-2022 Sean Whitton +;;; Copyright (C) 2020-2023 Sean Whitton ;;; This file is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by @@ -146,6 +146,24 @@ any of the regular expressions PATTERNS." (:check (not (apply #'remote-exists-p directories))) (:apply (mrun "rm" "-rf" directories))) +(defprop empty-directory-does-not-exist :posix (&rest directories) + "Ensure that none of DIRECTORIES exist as empty directories." + (:desc #?"@{directories} removed if empty") + (:apply + (aif (runlines + :input (unlines directories) + #.(sh-script-to-single-line + "set -e; while read -r dir; do + if [ -d \"$dir\" ]; then + ( cd \"$dir\" + if [ -z \"$(find . ! -name . -print -prune)\" ]; then + echo \"$dir\" + fi ) + fi + done")) + (mrun "rmdir" it) + :no-change))) + (defprop data-uploaded :posix (iden1 iden2 destination) (:desc #?"${destination} installed") (:hostattrs -- cgit v1.2.3