diff options
| author | Richard M. Stallman | 2002-09-26 22:00:22 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-09-26 22:00:22 +0000 |
| commit | 446c63b0a26af3fe1001e5474a3ec5e88bd39b0d (patch) | |
| tree | c32da9f17249d6cc44be660635280de2854e0ca6 | |
| parent | 9475e724a2d8ab236dffc75e009e079bacccd0d4 (diff) | |
| download | emacs-446c63b0a26af3fe1001e5474a3ec5e88bd39b0d.tar.gz emacs-446c63b0a26af3fe1001e5474a3ec5e88bd39b0d.zip | |
(backup-buffer): Bind local var MODES.
Don't use renaming for a suid or sgid file.
Use backup-buffer-copy to do copying.
(backup-buffer-copy): New subroutine.
Clear suid and sgid bits for the copy.
| -rw-r--r-- | lisp/files.el | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/lisp/files.el b/lisp/files.el index 4a495aab30c..6a893d958db 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -2365,12 +2365,15 @@ BACKUPNAME is the backup file name, which is the old file renamed." | |||
| 2365 | (or (eq delete-old-versions t) (eq delete-old-versions nil)) | 2365 | (or (eq delete-old-versions t) (eq delete-old-versions nil)) |
| 2366 | (or delete-old-versions | 2366 | (or delete-old-versions |
| 2367 | (y-or-n-p (format "Delete excess backup versions of %s? " | 2367 | (y-or-n-p (format "Delete excess backup versions of %s? " |
| 2368 | real-file-name)))))) | 2368 | real-file-name))))) |
| 2369 | (modes (file-modes buffer-file-name))) | ||
| 2369 | ;; Actually write the back up file. | 2370 | ;; Actually write the back up file. |
| 2370 | (condition-case () | 2371 | (condition-case () |
| 2371 | (if (or file-precious-flag | 2372 | (if (or file-precious-flag |
| 2372 | ; (file-symlink-p buffer-file-name) | 2373 | ; (file-symlink-p buffer-file-name) |
| 2373 | backup-by-copying | 2374 | backup-by-copying |
| 2375 | ;; Don't rename a suid or sgid file. | ||
| 2376 | (< 0 (logand modes #o6000)) | ||
| 2374 | (and backup-by-copying-when-linked | 2377 | (and backup-by-copying-when-linked |
| 2375 | (> (file-nlinks real-file-name) 1)) | 2378 | (> (file-nlinks real-file-name) 1)) |
| 2376 | (and (or backup-by-copying-when-mismatch | 2379 | (and (or backup-by-copying-when-mismatch |
| @@ -2382,19 +2385,10 @@ BACKUPNAME is the backup file name, which is the old file renamed." | |||
| 2382 | (<= (nth 2 attr) backup-by-copying-when-privileged-mismatch))) | 2385 | (<= (nth 2 attr) backup-by-copying-when-privileged-mismatch))) |
| 2383 | (or (nth 9 attr) | 2386 | (or (nth 9 attr) |
| 2384 | (not (file-ownership-preserved-p real-file-name))))))) | 2387 | (not (file-ownership-preserved-p real-file-name))))))) |
| 2385 | (condition-case () | 2388 | (backup-buffer-copy real-file-name backupname modes) |
| 2386 | (copy-file real-file-name backupname t t) | ||
| 2387 | (file-error | ||
| 2388 | ;; If copying fails because file BACKUPNAME | ||
| 2389 | ;; is not writable, delete that file and try again. | ||
| 2390 | (if (and (file-exists-p backupname) | ||
| 2391 | (not (file-writable-p backupname))) | ||
| 2392 | (delete-file backupname)) | ||
| 2393 | (copy-file real-file-name backupname t t))) | ||
| 2394 | ;; rename-file should delete old backup. | 2389 | ;; rename-file should delete old backup. |
| 2395 | (rename-file real-file-name backupname t) | 2390 | (rename-file real-file-name backupname t) |
| 2396 | (setq setmodes | 2391 | (setq setmodes (cons modes backupname))) |
| 2397 | (cons (file-modes backupname) backupname))) | ||
| 2398 | (file-error | 2392 | (file-error |
| 2399 | ;; If trouble writing the backup, write it in ~. | 2393 | ;; If trouble writing the backup, write it in ~. |
| 2400 | (setq backupname (expand-file-name | 2394 | (setq backupname (expand-file-name |
| @@ -2403,15 +2397,7 @@ BACKUPNAME is the backup file name, which is the old file renamed." | |||
| 2403 | (message "Cannot write backup file; backing up in %s" | 2397 | (message "Cannot write backup file; backing up in %s" |
| 2404 | (file-name-nondirectory backupname)) | 2398 | (file-name-nondirectory backupname)) |
| 2405 | (sleep-for 1) | 2399 | (sleep-for 1) |
| 2406 | (condition-case () | 2400 | (backup-buffer-copy real-file-name backupname modes))) |
| 2407 | (copy-file real-file-name backupname t t) | ||
| 2408 | (file-error | ||
| 2409 | ;; If copying fails because file BACKUPNAME | ||
| 2410 | ;; is not writable, delete that file and try again. | ||
| 2411 | (if (and (file-exists-p backupname) | ||
| 2412 | (not (file-writable-p backupname))) | ||
| 2413 | (delete-file backupname)) | ||
| 2414 | (copy-file real-file-name backupname t t))))) | ||
| 2415 | (setq buffer-backed-up t) | 2401 | (setq buffer-backed-up t) |
| 2416 | ;; Now delete the old versions, if desired. | 2402 | ;; Now delete the old versions, if desired. |
| 2417 | (if delete-old-versions | 2403 | (if delete-old-versions |
| @@ -2423,6 +2409,18 @@ BACKUPNAME is the backup file name, which is the old file renamed." | |||
| 2423 | setmodes) | 2409 | setmodes) |
| 2424 | (file-error nil)))))) | 2410 | (file-error nil)))))) |
| 2425 | 2411 | ||
| 2412 | (defun backup-buffer-copy (from-name to-name modes) | ||
| 2413 | (condition-case () | ||
| 2414 | (copy-file from-name to-name t t) | ||
| 2415 | (file-error | ||
| 2416 | ;; If copying fails because file TO-NAME | ||
| 2417 | ;; is not writable, delete that file and try again. | ||
| 2418 | (if (and (file-exists-p to-name) | ||
| 2419 | (not (file-writable-p to-name))) | ||
| 2420 | (delete-file to-name)) | ||
| 2421 | (copy-file from-name to-name t t))) | ||
| 2422 | (set-file-modes to-name (logand modes #o1777))) | ||
| 2423 | |||
| 2426 | (defun file-name-sans-versions (name &optional keep-backup-version) | 2424 | (defun file-name-sans-versions (name &optional keep-backup-version) |
| 2427 | "Return file NAME sans backup versions or strings. | 2425 | "Return file NAME sans backup versions or strings. |
| 2428 | This is a separate procedure so your site-init or startup file can | 2426 | This is a separate procedure so your site-init or startup file can |