diff options
| author | Michael Albinus | 2019-08-04 12:47:43 +0200 |
|---|---|---|
| committer | Michael Albinus | 2019-08-04 12:47:43 +0200 |
| commit | 2abcca23910d1fa5fe0bcac3ebc5b62df8e0a741 (patch) | |
| tree | e52558def53505247a8c4402cbb697bb9b63ef50 | |
| parent | 5ec3f70527e330abf4c0c3519fa4914c5f094358 (diff) | |
| download | emacs-2abcca23910d1fa5fe0bcac3ebc5b62df8e0a741.tar.gz emacs-2abcca23910d1fa5fe0bcac3ebc5b62df8e0a741.zip | |
Implement set-file-* functions for tramp-gvfs.el
* lisp/net/tramp-gvfs.el (tramp-gvfs-gio-mapping):
Add "gvfs-set-attribute".
(tramp-gvfs-file-name-handler-alist):
Add `tramp-gvfs-handle-set-file-modes',
`tramp-gvfs-handle-set-file-times' and
`tramp-gvfs-handle-set-file-uid-gid'.
(tramp-gvfs-handle-set-file-modes)
(tramp-gvfs-handle-set-file-times)
(tramp-sh-handle-set-file-uid-gid): New defuns.
* lisp/net/tramp.el (tramp-handle-write-region): Set file modes.
* test/lisp/net/tramp-tests.el (tramp-test20-file-modes)
(tramp-test22-file-times): Do not skip for tramp-gvfs.el.
| -rw-r--r-- | lisp/net/tramp-gvfs.el | 49 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 9 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 11 |
3 files changed, 63 insertions, 6 deletions
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 9d45e6a8ce9..a606ba67177 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el | |||
| @@ -471,6 +471,7 @@ It has been changed in GVFS 1.14.") | |||
| 471 | ("gvfs-mount" . "mount") | 471 | ("gvfs-mount" . "mount") |
| 472 | ("gvfs-move" . "move") | 472 | ("gvfs-move" . "move") |
| 473 | ("gvfs-rm" . "remove") | 473 | ("gvfs-rm" . "remove") |
| 474 | ("gvfs-set-attribute" . "set") | ||
| 474 | ("gvfs-trash" . "trash")) | 475 | ("gvfs-trash" . "trash")) |
| 475 | "List of cons cells, mapping \"gvfs-<command>\" to \"gio <command>\".") | 476 | "List of cons cells, mapping \"gvfs-<command>\" to \"gio <command>\".") |
| 476 | 477 | ||
| @@ -590,15 +591,15 @@ It has been changed in GVFS 1.14.") | |||
| 590 | (process-file . ignore) | 591 | (process-file . ignore) |
| 591 | (rename-file . tramp-gvfs-handle-rename-file) | 592 | (rename-file . tramp-gvfs-handle-rename-file) |
| 592 | (set-file-acl . ignore) | 593 | (set-file-acl . ignore) |
| 593 | (set-file-modes . ignore) | 594 | (set-file-modes . tramp-gvfs-handle-set-file-modes) |
| 594 | (set-file-selinux-context . ignore) | 595 | (set-file-selinux-context . ignore) |
| 595 | (set-file-times . ignore) | 596 | (set-file-times . tramp-gvfs-handle-set-file-times) |
| 596 | (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) | 597 | (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) |
| 597 | (shell-command . ignore) | 598 | (shell-command . ignore) |
| 598 | (start-file-process . ignore) | 599 | (start-file-process . ignore) |
| 599 | (substitute-in-file-name . tramp-handle-substitute-in-file-name) | 600 | (substitute-in-file-name . tramp-handle-substitute-in-file-name) |
| 600 | (temporary-file-directory . tramp-handle-temporary-file-directory) | 601 | (temporary-file-directory . tramp-handle-temporary-file-directory) |
| 601 | (tramp-set-file-uid-gid . ignore) | 602 | (tramp-set-file-uid-gid . tramp-gvfs-handle-set-file-uid-gid) |
| 602 | (unhandled-file-name-directory . ignore) | 603 | (unhandled-file-name-directory . ignore) |
| 603 | (vc-registered . ignore) | 604 | (vc-registered . ignore) |
| 604 | (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) | 605 | (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime) |
| @@ -1325,6 +1326,48 @@ file-notify events." | |||
| 1325 | (tramp-run-real-handler | 1326 | (tramp-run-real-handler |
| 1326 | #'rename-file (list filename newname ok-if-already-exists)))) | 1327 | #'rename-file (list filename newname ok-if-already-exists)))) |
| 1327 | 1328 | ||
| 1329 | (defun tramp-gvfs-handle-set-file-modes (filename mode) | ||
| 1330 | "Like `set-file-modes' for Tramp files." | ||
| 1331 | (with-parsed-tramp-file-name filename nil | ||
| 1332 | (tramp-flush-file-properties v (file-name-directory localname)) | ||
| 1333 | (tramp-flush-file-properties v localname) | ||
| 1334 | (tramp-gvfs-send-command | ||
| 1335 | v "gvfs-set-attribute" "-t" "uint32" | ||
| 1336 | (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v)) | ||
| 1337 | "unix::mode" (number-to-string mode)))) | ||
| 1338 | |||
| 1339 | (defun tramp-gvfs-handle-set-file-times (filename &optional time) | ||
| 1340 | "Like `set-file-times' for Tramp files." | ||
| 1341 | (with-parsed-tramp-file-name filename nil | ||
| 1342 | (tramp-flush-file-properties v (file-name-directory localname)) | ||
| 1343 | (tramp-flush-file-properties v localname) | ||
| 1344 | (let ((time | ||
| 1345 | (if (or (null time) | ||
| 1346 | (tramp-compat-time-equal-p time tramp-time-doesnt-exist) | ||
| 1347 | (tramp-compat-time-equal-p time tramp-time-dont-know)) | ||
| 1348 | (current-time) | ||
| 1349 | time))) | ||
| 1350 | (tramp-gvfs-send-command | ||
| 1351 | v "gvfs-set-attribute" "-t" "uint64" | ||
| 1352 | (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v)) | ||
| 1353 | "time::modified" (format-time-string "%s" time))))) | ||
| 1354 | |||
| 1355 | (defun tramp-gvfs-set-file-uid-gid (filename &optional uid gid) | ||
| 1356 | "Like `tramp-set-file-uid-gid' for Tramp files." | ||
| 1357 | (with-parsed-tramp-file-name filename nil | ||
| 1358 | (tramp-flush-file-properties v (file-name-directory localname)) | ||
| 1359 | (tramp-flush-file-properties v localname) | ||
| 1360 | (when (natnump uid) | ||
| 1361 | (tramp-gvfs-send-command | ||
| 1362 | v "gvfs-set-attribute" "-t" "uint32" | ||
| 1363 | (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v)) | ||
| 1364 | "unix::uid" (number-to-string uid))) | ||
| 1365 | (when (natnump gid) | ||
| 1366 | (tramp-gvfs-send-command | ||
| 1367 | v "gvfs-set-attribute" "-t" "uint32" | ||
| 1368 | (tramp-gvfs-url-file-name (tramp-make-tramp-file-name v)) | ||
| 1369 | "unix::gid" (number-to-string gid))))) | ||
| 1370 | |||
| 1328 | 1371 | ||
| 1329 | ;; File name conversions. | 1372 | ;; File name conversions. |
| 1330 | 1373 | ||
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 717ced80f28..c589557132a 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -3772,9 +3772,16 @@ of." | |||
| 3772 | (format "File %s exists; overwrite anyway? " filename))))) | 3772 | (format "File %s exists; overwrite anyway? " filename))))) |
| 3773 | (tramp-error v 'file-already-exists filename)) | 3773 | (tramp-error v 'file-already-exists filename)) |
| 3774 | 3774 | ||
| 3775 | (let ((tmpfile (tramp-compat-make-temp-file filename))) | 3775 | (let ((tmpfile (tramp-compat-make-temp-file filename)) |
| 3776 | (modes (save-excursion (tramp-default-file-modes filename)))) | ||
| 3776 | (when (and append (file-exists-p filename)) | 3777 | (when (and append (file-exists-p filename)) |
| 3777 | (copy-file filename tmpfile 'ok)) | 3778 | (copy-file filename tmpfile 'ok)) |
| 3779 | ;; The permissions of the temporary file should be set. If | ||
| 3780 | ;; FILENAME does not exist (eq modes nil) it has been | ||
| 3781 | ;; renamed to the backup file. This case `save-buffer' | ||
| 3782 | ;; handles permissions. | ||
| 3783 | ;; Ensure that it is still readable. | ||
| 3784 | (set-file-modes tmpfile (logior (or modes 0) #o0400)) | ||
| 3778 | ;; We say `no-message' here because we don't want the visited file | 3785 | ;; We say `no-message' here because we don't want the visited file |
| 3779 | ;; modtime data to be clobbered from the temp file. We call | 3786 | ;; modtime data to be clobbered from the temp file. We call |
| 3780 | ;; `set-visited-file-modtime' ourselves later on. | 3787 | ;; `set-visited-file-modtime' ourselves later on. |
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 1404ef39d55..f60dea36bf5 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -3143,7 +3143,13 @@ They might differ only in access time." | |||
| 3143 | "Check `file-modes'. | 3143 | "Check `file-modes'. |
| 3144 | This tests also `file-executable-p', `file-writable-p' and `set-file-modes'." | 3144 | This tests also `file-executable-p', `file-writable-p' and `set-file-modes'." |
| 3145 | (skip-unless (tramp--test-enabled)) | 3145 | (skip-unless (tramp--test-enabled)) |
| 3146 | (skip-unless (or (tramp--test-sh-p) (tramp--test-sudoedit-p))) | 3146 | (skip-unless |
| 3147 | (or (tramp--test-sh-p) (tramp--test-sudoedit-p) | ||
| 3148 | ;; Not all tramp-gvfs.el methods support changing the file mode. | ||
| 3149 | (and | ||
| 3150 | (tramp--test-gvfs-p) | ||
| 3151 | (string-match-p | ||
| 3152 | "ftp" (file-remote-p tramp-test-temporary-file-directory 'method))))) | ||
| 3147 | 3153 | ||
| 3148 | (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) | 3154 | (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) |
| 3149 | (let ((tmp-name (tramp--test-make-temp-name nil quoted))) | 3155 | (let ((tmp-name (tramp--test-make-temp-name nil quoted))) |
| @@ -3443,7 +3449,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3443 | "Check `set-file-times' and `file-newer-than-file-p'." | 3449 | "Check `set-file-times' and `file-newer-than-file-p'." |
| 3444 | (skip-unless (tramp--test-enabled)) | 3450 | (skip-unless (tramp--test-enabled)) |
| 3445 | (skip-unless | 3451 | (skip-unless |
| 3446 | (or (tramp--test-adb-p) (tramp--test-sh-p) (tramp--test-sudoedit-p))) | 3452 | (or (tramp--test-adb-p) (tramp--test-gvfs-p) |
| 3453 | (tramp--test-sh-p) (tramp--test-sudoedit-p))) | ||
| 3447 | 3454 | ||
| 3448 | (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) | 3455 | (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) |
| 3449 | (let ((tmp-name1 (tramp--test-make-temp-name nil quoted)) | 3456 | (let ((tmp-name1 (tramp--test-make-temp-name nil quoted)) |