Copy files or directories, with recoverable errors.
(copy from to &key (recursive 'nil)
(overwrite 'nil)
(limit '1000)
(state 'state))
→
(mv error state)This is a nice, higher-level wrapper around the low-level copy-file routine, which acts more like the unix
Copying files can fail for a variety of reasons. This function attempts to gracefully catch errors and return them in a form that you can recover from. See also copy!, an alternative that just causes a hard error if there is any problem.
Examples:
Function:
(defun copy-fn (from to recursive overwrite limit state) (declare (xargs :stobjs (state))) (declare (xargs :guard (and (stringp from) (stringp to) (booleanp recursive) (booleanp overwrite) (natp limit)))) (let ((__function__ 'copy)) (declare (ignorable __function__)) (b* (((mv from-err from-kind state) (file-kind from)) ((when from-err) (mv (msg "~s0: can't copy ~s1: ~@2" 'copy from from-err) state)) ((unless from-kind) (mv (msg "~s0: no such file: ~s1" 'copy from) state)) ((when (eq from-kind :regular-file)) (nice-copy-single-file from to :overwrite overwrite)) ((when (eq from-kind :directory)) (if (not recursive) (mv (msg "~s0: can't copy directory (in non-recursive mode): ~s1" 'copy from) state) (nice-copy-single-directory from to :limit limit)))) (mv (msg "~s0: unsupported file type ~s1: ~s2" 'copy from-kind from) state))))
Theorem:
(defthm state-p1-of-copy.state (implies (force (state-p1 state)) (b* (((mv common-lisp::?error acl2::?state) (copy-fn from to recursive overwrite limit state))) (state-p1 state))) :rule-classes :rewrite)