summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisplib.c1
-rwxr-xr-xshare/txr/stdlib/copy-file.tl29
-rw-r--r--txr.143
3 files changed, 73 insertions, 0 deletions
diff --git a/lisplib.c b/lisplib.c
index cc4c3d8f..73e9f286 100644
--- a/lisplib.c
+++ b/lisplib.c
@@ -813,6 +813,7 @@ static val copy_file_set_entries(val dlt, val fun)
val name[] = {
lit("copy-path-opts"), lit("copy-file"), lit("copy-files"),
lit("copy-path-rec"), lit("remove-path-rec"),
+ lit("chown-rec"), lit("chmod-rec"),
nil
};
set_dlt_entries(dlt, name, fun);
diff --git a/share/txr/stdlib/copy-file.tl b/share/txr/stdlib/copy-file.tl
index 4f3eabb5..52125fd4 100755
--- a/share/txr/stdlib/copy-file.tl
+++ b/share/txr/stdlib/copy-file.tl
@@ -183,5 +183,34 @@
(retry `retry copying @path` (exc . args)))))
(logior ftw-phys ftw-depth)))
+(defun chmod-rec (path perm)
+ (ftw path
+ (lambda (path type stat . rest)
+ (while t
+ (catch**
+ (return
+ (caseql* type
+ ((ftw-dnr ftw-ns) (error "~s: unable to access ~s"
+ 'remove-rec path))
+ (ftw-sl)
+ (t (chmod path perm))))
+ (skip `skip chmod @path` (exc . args) (return))
+ (retry `retry chmod @path` (exc . args)))))
+ (logior ftw-phys)))
+
+(defun chown-rec (path uid gid)
+ (ftw path
+ (lambda (path type stat . rest)
+ (while t
+ (catch**
+ (return
+ (caseql* type
+ ((ftw-dnr ftw-ns) (error "~s: unable to access ~s"
+ 'remove-rec path))
+ (t (lchown path uid gid))))
+ (skip `skip chown @path` (exc . args) (return))
+ (retry `retry chown @path` (exc . args)))))
+ (logior ftw-phys)))
+
(eval-only
(merge-delete-package 'sys))
diff --git a/txr.1 b/txr.1
index b3457457..c00a01f9 100644
--- a/txr.1
+++ b/txr.1
@@ -58690,6 +58690,49 @@ will still exist when
.code remove-path-rec
completes and returns.
+.coNP Functions @ chmod-rec and @ chown-rec
+.synb
+.mets (chmod-rec < path << mode )
+.mets (chown-rec < path < uid << gid )
+.syne
+.desc
+The
+.code chmod-rec
+and
+.code chown-rec
+functions are recursive counterparts of
+.code chmod
+and
+.codn lchown .
+
+The filesystem object given by
+.meta path
+is recursively traversed, and each of its constituent objects
+is subject to a permission change in the case of
+.codn chown-rec ,
+or an ownership change in the case of
+.codn chown-rec .
+
+The
+.code chmod-rec
+function alters the permission of each object that is not a symbolic link
+using the
+.code chmod
+function. Each object which is a symbolic link is ignored.
+
+The
+.code chown-rec
+function alters the permission of each object encountered, including
+symbolic links, using the
+.code lchown
+function.
+
+These functions establish restart catches, similarly to
+.code remove-path-rec
+and
+.codn copy-path-rec ,
+allowing the caller to retry individual failed operations or skip the objects
+on which operations have failed.
.SS* Unix Filesystem Object Existence, Type and Access Tests