Changeset 8343
- Timestamp:
- Jan 28, 2008, 4:49:47 PM (17 years ago)
- Location:
- trunk/source
- Files:
-
- 2 edited
-
level-1/linux-files.lisp (modified) (8 diffs)
-
lib/pathnames.lisp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/level-1/linux-files.lisp
r8271 r8343 201 201 (cwd path)) 202 202 203 (defmacro with-filename-cstrs (&rest rest) 204 `(#+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ,@rest)) 205 203 206 (defun %chdir (dirname) 204 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((dirname dirname))207 (with-filename-cstrs ((dirname dirname)) 205 208 (syscall syscalls::chdir dirname))) 206 209 … … 210 213 (when (and (> len 0) (eql (char name (1- len)) #\/)) 211 214 (setq name (subseq name 0 (1- len)))) 212 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((name name))215 (with-filename-cstrs ((name name)) 213 216 (syscall syscalls::mkdir name mode)))) 214 217 215 218 (defun %rmdir (name) 216 219 (let* ((last (1- (length name)))) 217 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((name name))220 (with-filename-cstrs ((name name)) 218 221 (when (and (>= last 0) 219 222 (eql (%get-byte name last) (char-code #\/))) … … 269 272 (pref stat :stat.st_ino) 270 273 (pref stat :stat.st_uid) 271 (pref stat :stat.st_blksize)) 274 (pref stat :stat.st_blksize) 275 #+linux-target 276 (pref stat :stat.st_mtim.tv_usec) 277 #-linux-target 278 (round (pref stat :stat.st_mtimespec.tv_nsec) 1000) 279 (pref stat :stat.st_gid)) 272 280 (values nil nil nil nil nil nil nil))) 273 281 274 282 275 283 (defun %%stat (name stat) 276 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((cname name))284 (with-filename-cstrs ((cname name)) 277 285 (%stat-values 278 286 #+linux-target … … 291 299 292 300 (defun %%lstat (name stat) 293 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((cname name))301 (with-filename-cstrs ((cname name)) 294 302 (%stat-values 295 303 #+linux-target … … 341 349 "unknown")) 342 350 351 (defun try-hard-to-get-errno (err) 352 (when (eq err -1) 353 (let ((nerr (%get-errno))) 354 (unless (eq nerr 0) (setq err nerr)))) 355 #+darwin-target 356 (when (eq err -1) 357 ;; Not thread safe, but what else can I do?? 358 (let ((nerr (pref (foreign-symbol-address "_errno") :signed))) 359 (unless (eq nerr 0) (setq err nerr)))) 360 err) 361 362 (defun copy-file-attributes (source-path dest-path) 363 "Copy the mode, owner, group and modification time of source-path to dest-path. 364 Returns T if succeeded, NIL if some of the attributes couldn't be copied due to 365 permission problems. Any other failures cause an error to be signalled" 366 (multiple-value-bind (win mode ignore mtime-sec ignore uid ignore mtime-usec gid) 367 (%stat (native-translated-namestring source-path) t) 368 (declare (ignore ignore)) 369 (unless win 370 (error "Cannot get attributes of ~s" source-path)) 371 (with-filename-cstrs ((cnamestr (native-translated-namestring dest-path))) 372 (macrolet ((errchk (form) 373 `(let ((err ,form)) 374 (unless (eql err 0) 375 (setq win nil) 376 ;; We need the real errno so we can tell if it's a permission 377 ;; error or something else... 378 (when (eql err -1) 379 (setq err (try-hard-to-get-errno err))) 380 (unless (eql err #$EPERM) (%errno-disp err dest-path)))))) 381 (errchk (#_chmod cnamestr mode)) 382 (errchk (%stack-block ((times (record-length (:array (:struct :timeval) 2)))) 383 (setf (pref times :timeval.tv_sec) mtime-sec) 384 (setf (pref times :timeval.tv_usec) mtime-usec) 385 (%incf-ptr times (record-length :timeval)) 386 (setf (pref times :timeval.tv_sec) mtime-sec) 387 (setf (pref times :timeval.tv_usec) mtime-usec) 388 (%incf-ptr times (- (record-length :timeval))) 389 (#_utimes cnamestr times))) 390 (errchk (#_chown cnamestr uid gid)))) 391 win)) 343 392 344 393 #+linux-target … … 406 455 (setq namestring (current-directory-name))) 407 456 (%stack-block ((resultbuf #$PATH_MAX)) 408 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((name namestring #|(tilde-expand namestring)|#))457 (with-filename-cstrs ((name namestring #|(tilde-expand namestring)|#)) 409 458 (let* ((result (#_realpath name resultbuf))) 410 459 (declare (dynamic-extent result)) … … 477 526 478 527 (defun %utimes (namestring) 479 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((cnamestring namestring))528 (with-filename-cstrs ((cnamestring namestring)) 480 529 (let* ((err (#_utimes cnamestring (%null-ptr)))) 481 530 (declare (fixnum err)) … … 495 544 496 545 (defun %open-dir (namestring) 497 ( #+darwin-target with-utf-8-cstrs #-darwin-target with-cstrs ((name namestring))546 (with-filename-cstrs ((name namestring)) 498 547 (let* ((DIR (#_opendir name))) 499 548 (unless (%null-ptr-p DIR) -
trunk/source/lib/pathnames.lisp
r8174 r8343 110 110 (values new-name original (truename new-name)))))) 111 111 112 113 112 (defun copy-file (source-path dest-path &key (if-exists :error) 114 113 (preserve-attributes nil)) 115 114 (let* ((original (truename source-path)) 116 (original-namestring (native-translated-namestring original))117 115 (new-name (merge-pathnames dest-path original)) 118 (new-namestring (native-translated-namestring new-name)) 119 (flags (if preserve-attributes "-pf" "-f"))) 120 (unless new-namestring 121 (error "~S can't be created." new-name)) 122 (unless (and (probe-file new-name) 123 (not (if-exists if-exists new-name))) 124 (let* ((proc (run-program "/bin/cp" 125 `(,flags ,original-namestring ,new-namestring) 126 :wait t)) 127 (exit-code (external-process-%exit-code proc))) 128 (unless (zerop exit-code) 129 (error "Error copying ~s to ~s: ~a" 130 source-path dest-path (%strerror exit-code))) 131 (values new-name original (truename new-name)))))) 116 (buffer (make-array 4096 :element-type '(unsigned-byte 8)))) 117 (with-open-file (in original :direction :input 118 :element-type '(unsigned-byte 8)) 119 (with-open-file (out new-name :direction :output 120 :if-exists if-exists 121 :element-type '(unsigned-byte 8)) 122 (loop 123 as n = (stream-read-vector in buffer 0 4096) until (eql n 0) 124 do (stream-write-vector out buffer 0 n)))) 125 (when preserve-attributes 126 (copy-file-attributes original new-name)) 127 (values new-name original (truename new-name)))) 132 128 133 129 (defun recursive-copy-directory (source-path dest-path &key test (if-exists :error))
Note:
See TracChangeset
for help on using the changeset viewer.
