diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-01-31 23:44:53 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-01-31 23:44:53 -0800 |
commit | c176ee050e0ce0010802154ff3e588aab3a67ae3 (patch) | |
tree | 557d268670a4e5f7bd96ce6e6e49c54fa5bd9019 | |
parent | 7e2addeabe1056da2a94ec8f6302c13bf916a1dc (diff) | |
download | txr-c176ee050e0ce0010802154ff3e588aab3a67ae3.tar.gz txr-c176ee050e0ce0010802154ff3e588aab3a67ae3.tar.bz2 txr-c176ee050e0ce0010802154ff3e588aab3a67ae3.zip |
New functions chmod-rec and chown-rec.
* lisplib.c (copy_file_set_entries): Add chown-rec and
chmod-rec to list of symbols that trigger auto-load of
copy-file.tl.
* share/txr/stdlib/copy-file.tl (chmod-rec, chown-rec): Neew
functions.
* txr.1: Documented.
-rw-r--r-- | lisplib.c | 1 | ||||
-rwxr-xr-x | share/txr/stdlib/copy-file.tl | 29 | ||||
-rw-r--r-- | txr.1 | 43 |
3 files changed, 73 insertions, 0 deletions
@@ -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)) @@ -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 |