aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2007-10-04 20:09:32 +0000
committerMichael Albinus2007-10-04 20:09:32 +0000
commit258800f85f19157263bfdbb96c526f108009364c (patch)
tree623c3c678bdab109194db9454abe399c2c75dc6c
parentbbe6f2aa1141fe2d2d45a8b79e4eaa646bcd7c4f (diff)
downloademacs-258800f85f19157263bfdbb96c526f108009364c.tar.gz
emacs-258800f85f19157263bfdbb96c526f108009364c.zip
* net/tramp.el (tramp-make-temp-file): Move to tramp-compat.el.
(tramp-do-copy-or-rename-file-directly): Handle tmpfile only in the cond clauses where needed. (tramp-handle-write-region): Rearrange code for proper handling of tmpfile. * net/tramp-compat.el (tramp-compat-make-temp-file): New defsubst. * net/tramp.el: * net/tramp-fish.el: * net/tramp-ftp.el: * net/tramp-smb.el: Rename `tramp-make-temp-file' to `tramp-compat-make-temp-file'.
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/net/tramp-compat.el36
-rw-r--r--lisp/net/tramp-fish.el2
-rw-r--r--lisp/net/tramp-ftp.el2
-rw-r--r--lisp/net/tramp-smb.el4
-rw-r--r--lisp/net/tramp.el145
6 files changed, 123 insertions, 82 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0b3adf28023..4abf79b3457 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12007-10-04 Michael Albinus <michael.albinus@gmx.de>
2
3 * net/tramp.el (tramp-make-temp-file): Move to tramp-compat.el.
4 (tramp-do-copy-or-rename-file-directly): Handle tmpfile only in
5 the cond clauses where needed.
6 (tramp-handle-write-region): Rearrange code for proper handling of
7 tmpfile.
8
9 * net/tramp-compat.el (tramp-compat-make-temp-file): New defsubst.
10
11 * net/tramp.el:
12 * net/tramp-fish.el:
13 * net/tramp-ftp.el:
14 * net/tramp-smb.el: Rename `tramp-make-temp-file' to
15 `tramp-compat-make-temp-file'.
16
12007-10-04 Juanma Barranquero <lekktu@gmail.com> 172007-10-04 Juanma Barranquero <lekktu@gmail.com>
2 18
3 * image-dired.el (image-dired-image-at-point-p): Fix typo in docstring. 19 * image-dired.el (image-dired-image-at-point-p): Fix typo in docstring.
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 620384eaf38..9808888399f 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -117,6 +117,42 @@ this is the function `temp-directory'."
117 "`temp-directory' is defined -- using /tmp.")) 117 "`temp-directory' is defined -- using /tmp."))
118 (file-name-as-directory "/tmp")))) 118 (file-name-as-directory "/tmp"))))
119 119
120;; `make-temp-file' exists in Emacs only. The third parameter SUFFIX
121;; has been introduced with Emacs 22. We try it, if it fails, we fall
122;; back to `make-temp-name', creating the temporary file immediately
123;; in order to avoid a security hole.
124(defsubst tramp-compat-make-temp-file (filename)
125 "Create a temporary file (compat function).
126Add the extension of FILENAME, if existing."
127 (let ((prefix (expand-file-name
128 (symbol-value 'tramp-temp-name-prefix)
129 (tramp-compat-temporary-file-directory)))
130 (extension (file-name-extension filename t))
131 result)
132 (condition-case nil
133 (setq result
134 (funcall (symbol-function 'make-temp-file) prefix nil extension))
135 (error
136 ;; We use our own implementation, taken from files.el.
137 (while
138 (condition-case ()
139 (progn
140 (setq result (concat (make-temp-name prefix) extension))
141 (write-region
142 "" nil result nil 'silent nil
143 ;; 7th parameter is MUSTBENEW in Emacs, and
144 ;; CODING-SYSTEM in XEmacs. It is not a security
145 ;; hole in XEmacs if we cannot use this parameter,
146 ;; because XEmacs uses a user-specific subdirectory
147 ;; with 0700 permissions.
148 (when (not (featurep 'xemacs)) 'excl))
149 nil)
150 (file-already-exists t))
151 ;; The file was somehow created by someone else between
152 ;; `make-temp-name' and `write-region', let's try again.
153 nil)))
154 result))
155
120;; `most-positive-fixnum' arrived in Emacs 22. Before, and in XEmacs, 156;; `most-positive-fixnum' arrived in Emacs 22. Before, and in XEmacs,
121;; it is a fixed value. 157;; it is a fixed value.
122(defsubst tramp-compat-most-positive-fixnum () 158(defsubst tramp-compat-most-positive-fixnum ()
diff --git a/lisp/net/tramp-fish.el b/lisp/net/tramp-fish.el
index 8ae6af76d6b..055d6c9f5e2 100644
--- a/lisp/net/tramp-fish.el
+++ b/lisp/net/tramp-fish.el
@@ -475,7 +475,7 @@ pass to the OPERATION."
475 (tramp-error 475 (tramp-error
476 v 'file-error 476 v 'file-error
477 "Cannot make local copy of non-existing file `%s'" filename)) 477 "Cannot make local copy of non-existing file `%s'" filename))
478 (let ((tmpfile (tramp-make-temp-file filename))) 478 (let ((tmpfile (tramp-compat-make-temp-file filename)))
479 (tramp-message v 4 "Fetching %s to tmp file %s..." filename tmpfile) 479 (tramp-message v 4 "Fetching %s to tmp file %s..." filename tmpfile)
480 (when (tramp-fish-retrieve-data v) 480 (when (tramp-fish-retrieve-data v)
481 ;; Save file 481 ;; Save file
diff --git a/lisp/net/tramp-ftp.el b/lisp/net/tramp-ftp.el
index cf98ecba7d5..85416d308d3 100644
--- a/lisp/net/tramp-ftp.el
+++ b/lisp/net/tramp-ftp.el
@@ -158,7 +158,7 @@ pass to the OPERATION."
158 (not (tramp-ftp-file-name-p (cadr args)))) 158 (not (tramp-ftp-file-name-p (cadr args))))
159 (let* ((filename (car args)) 159 (let* ((filename (car args))
160 (newname (cadr args)) 160 (newname (cadr args))
161 (tmpfile (tramp-make-temp-file filename)) 161 (tmpfile (tramp-compat-make-temp-file filename))
162 (args (cddr args))) 162 (args (cddr args)))
163 (apply operation filename tmpfile args) 163 (apply operation filename tmpfile args)
164 (rename-file tmpfile newname (car args)))) 164 (rename-file tmpfile newname (car args))))
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 6cbe4dbd61d..b4e68c77624 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -371,7 +371,7 @@ KEEP-DATE is not handled in case NEWNAME resides on an SMB server."
371 "Like `file-local-copy' for Tramp files." 371 "Like `file-local-copy' for Tramp files."
372 (with-parsed-tramp-file-name filename nil 372 (with-parsed-tramp-file-name filename nil
373 (let ((file (tramp-smb-get-localname localname t)) 373 (let ((file (tramp-smb-get-localname localname t))
374 (tmpfile (tramp-make-temp-file filename))) 374 (tmpfile (tramp-compat-make-temp-file filename)))
375 (unless (file-exists-p filename) 375 (unless (file-exists-p filename)
376 (tramp-error 376 (tramp-error
377 v 'file-error 377 v 'file-error
@@ -587,7 +587,7 @@ Catches errors for shares like \"C$/\", which are common in Microsoft Windows."
587 (tramp-flush-file-property v localname) 587 (tramp-flush-file-property v localname)
588 (let ((file (tramp-smb-get-localname localname t)) 588 (let ((file (tramp-smb-get-localname localname t))
589 (curbuf (current-buffer)) 589 (curbuf (current-buffer))
590 (tmpfile (tramp-make-temp-file filename))) 590 (tmpfile (tramp-compat-make-temp-file filename)))
591 ;; We say `no-message' here because we don't want the visited file 591 ;; We say `no-message' here because we don't want the visited file
592 ;; modtime data to be clobbered from the temp file. We call 592 ;; modtime data to be clobbered from the temp file. We call
593 ;; `set-visited-file-modtime' ourselves later on. 593 ;; `set-visited-file-modtime' ourselves later on.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index fcd18a2387c..b9689eba201 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1974,13 +1974,6 @@ The intent is to protect against `obsolete variable' warnings."
1974(put 'tramp-let-maybe 'lisp-indent-function 2) 1974(put 'tramp-let-maybe 'lisp-indent-function 2)
1975(put 'tramp-let-maybe 'edebug-form-spec t) 1975(put 'tramp-let-maybe 'edebug-form-spec t)
1976 1976
1977(defsubst tramp-make-temp-file (filename)
1978 (concat
1979 (make-temp-name
1980 (expand-file-name
1981 tramp-temp-name-prefix (tramp-compat-temporary-file-directory)))
1982 (file-name-extension filename t)))
1983
1984(defsubst tramp-make-tramp-temp-file (vec) 1977(defsubst tramp-make-tramp-temp-file (vec)
1985 (format 1978 (format
1986 "/tmp/%s%s" 1979 "/tmp/%s%s"
@@ -3071,8 +3064,7 @@ the uid and gid from FILENAME."
3071 (if t1 (tramp-handle-file-remote-p filename 'localname) filename)) 3064 (if t1 (tramp-handle-file-remote-p filename 'localname) filename))
3072 (localname2 3065 (localname2
3073 (if t2 (tramp-handle-file-remote-p newname 'localname) newname)) 3066 (if t2 (tramp-handle-file-remote-p newname 'localname) newname))
3074 (prefix (file-remote-p (if t1 filename newname))) 3067 (prefix (file-remote-p (if t1 filename newname))))
3075 (tmpfile (tramp-make-temp-file localname1)))
3076 3068
3077 (cond 3069 (cond
3078 ;; Both files are on a remote host, with same user. 3070 ;; Both files are on a remote host, with same user.
@@ -3124,40 +3116,41 @@ the uid and gid from FILENAME."
3124 ;; We need a temporary file in between. 3116 ;; We need a temporary file in between.
3125 (t 3117 (t
3126 ;; Create the temporary file. 3118 ;; Create the temporary file.
3127 (cond 3119 (let ((tmpfile (tramp-compat-make-temp-file localname1)))
3128 (t1 3120 (cond
3129 (tramp-send-command 3121 (t1
3130 v (format 3122 (tramp-send-command
3131 "%s %s %s" cmd 3123 v (format
3132 (tramp-shell-quote-argument localname1) 3124 "%s %s %s" cmd
3133 (tramp-shell-quote-argument tmpfile))) 3125 (tramp-shell-quote-argument localname1)
3134 ;; We must change the ownership as remote user. 3126 (tramp-shell-quote-argument tmpfile)))
3135 (tramp-set-file-uid-gid 3127 ;; We must change the ownership as remote user.
3136 (concat prefix tmpfile) 3128 (tramp-set-file-uid-gid
3137 (tramp-get-local-uid 'integer) 3129 (concat prefix tmpfile)
3138 (tramp-get-local-gid 'integer))) 3130 (tramp-get-local-uid 'integer)
3139 (t2 3131 (tramp-get-local-gid 'integer)))
3140 (if (eq op 'copy) 3132 (t2
3141 (tramp-compat-copy-file 3133 (if (eq op 'copy)
3142 localname1 tmpfile ok-if-already-exists 3134 (tramp-compat-copy-file
3143 keep-date preserve-uid-gid) 3135 localname1 tmpfile ok-if-already-exists
3144 (rename-file localname1 tmpfile ok-if-already-exists)) 3136 keep-date preserve-uid-gid)
3145 ;; We must change the ownership as local user. 3137 (rename-file localname1 tmpfile ok-if-already-exists))
3146 (tramp-set-file-uid-gid 3138 ;; We must change the ownership as local user.
3147 tmpfile 3139 (tramp-set-file-uid-gid
3148 (tramp-get-remote-uid v 'integer) 3140 tmpfile
3149 (tramp-get-remote-gid v 'integer)))) 3141 (tramp-get-remote-uid v 'integer)
3150 3142 (tramp-get-remote-gid v 'integer))))
3151 ;; Move the temporary file to its destination. 3143
3152 (cond 3144 ;; Move the temporary file to its destination.
3153 (t2 3145 (cond
3154 (tramp-send-command 3146 (t2
3155 v (format 3147 (tramp-send-command
3156 "mv -f %s %s" 3148 v (format
3157 (tramp-shell-quote-argument tmpfile) 3149 "mv -f %s %s"
3158 (tramp-shell-quote-argument localname2)))) 3150 (tramp-shell-quote-argument tmpfile)
3159 (t1 3151 (tramp-shell-quote-argument localname2))))
3160 (rename-file tmpfile localname2 ok-if-already-exists)))))))) 3152 (t1
3153 (rename-file tmpfile localname2 ok-if-already-exists)))))))))
3161 3154
3162 ;; Set the time and mode. Mask possible errors. 3155 ;; Set the time and mode. Mask possible errors.
3163 ;; Won't be applied for 'rename. 3156 ;; Won't be applied for 'rename.
@@ -3736,7 +3729,7 @@ beginning of local filename are not substituted."
3736(defun tramp-handle-call-process-region 3729(defun tramp-handle-call-process-region
3737 (start end program &optional delete buffer display &rest args) 3730 (start end program &optional delete buffer display &rest args)
3738 "Like `call-process-region' for Tramp files." 3731 "Like `call-process-region' for Tramp files."
3739 (let ((tmpfile (tramp-make-temp-file ""))) 3732 (let ((tmpfile (tramp-compat-make-temp-file "")))
3740 (write-region start end tmpfile) 3733 (write-region start end tmpfile)
3741 (when delete (delete-region start end)) 3734 (when delete (delete-region start end))
3742 (unwind-protect 3735 (unwind-protect
@@ -3798,7 +3791,7 @@ beginning of local filename are not substituted."
3798 (with-parsed-tramp-file-name filename nil 3791 (with-parsed-tramp-file-name filename nil
3799 (let ((rem-enc (tramp-get-remote-coding v "remote-encoding")) 3792 (let ((rem-enc (tramp-get-remote-coding v "remote-encoding"))
3800 (loc-dec (tramp-get-local-coding v "local-decoding")) 3793 (loc-dec (tramp-get-local-coding v "local-decoding"))
3801 (tmpfile (tramp-make-temp-file filename))) 3794 (tmpfile (tramp-compat-make-temp-file filename)))
3802 (unless (file-exists-p filename) 3795 (unless (file-exists-p filename)
3803 (tramp-error 3796 (tramp-error
3804 v 'file-error 3797 v 'file-error
@@ -3837,7 +3830,7 @@ beginning of local filename are not substituted."
3837 (write-region (point-min) (point-max) tmpfile)))) 3830 (write-region (point-min) (point-max) tmpfile))))
3838 ;; If tramp-decoding-function is not defined for this 3831 ;; If tramp-decoding-function is not defined for this
3839 ;; method, we invoke tramp-decoding-command instead. 3832 ;; method, we invoke tramp-decoding-command instead.
3840 (let ((tmpfile2 (tramp-make-temp-file filename))) 3833 (let ((tmpfile2 (tramp-compat-make-temp-file filename)))
3841 (let ((coding-system-for-write 'binary)) 3834 (let ((coding-system-for-write 'binary))
3842 (write-region (point-min) (point-max) tmpfile2)) 3835 (write-region (point-min) (point-max) tmpfile2))
3843 (tramp-message 3836 (tramp-message
@@ -4055,28 +4048,28 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
4055 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename)) 4048 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
4056 (tramp-error v 'file-error "File not overwritten"))) 4049 (tramp-error v 'file-error "File not overwritten")))
4057 4050
4058 (let ((rem-dec (tramp-get-remote-coding v "remote-decoding")) 4051 (if (and (tramp-local-host-p v)
4059 (loc-enc (tramp-get-local-coding v "local-encoding")) 4052 (file-writable-p (file-name-directory localname)))
4060 (modes (save-excursion (file-modes filename))) 4053 ;; Short track: if we are on the local host, we can run directly.
4061 ;; We use this to save the value of `last-coding-system-used' 4054 (if confirm
4062 ;; after writing the tmp file. At the end of the function, 4055 (write-region
4063 ;; we set `last-coding-system-used' to this saved value. 4056 start end localname append 'no-message lockname confirm)
4064 ;; This way, any intermediary coding systems used while 4057 (write-region start end localname append 'no-message lockname))
4065 ;; talking to the remote shell or suchlike won't hose this 4058
4066 ;; variable. This approach was snarfed from ange-ftp.el. 4059 (let ((rem-dec (tramp-get-remote-coding v "remote-decoding"))
4067 coding-system-used 4060 (loc-enc (tramp-get-local-coding v "local-encoding"))
4068 ;; Write region into a tmp file. This isn't really needed if we 4061 (modes (save-excursion (file-modes filename)))
4069 ;; use an encoding function, but currently we use it always 4062 ;; We use this to save the value of `last-coding-system-used'
4070 ;; because this makes the logic simpler. 4063 ;; after writing the tmp file. At the end of the function,
4071 (tmpfile (tramp-make-temp-file filename))) 4064 ;; we set `last-coding-system-used' to this saved value.
4072 4065 ;; This way, any intermediary coding systems used while
4073 (if (and (tramp-local-host-p v) 4066 ;; talking to the remote shell or suchlike won't hose this
4074 (file-writable-p (file-name-directory localname))) 4067 ;; variable. This approach was snarfed from ange-ftp.el.
4075 ;; Short track: if we are on the local host, we can run directly. 4068 coding-system-used
4076 (if confirm 4069 ;; Write region into a tmp file. This isn't really needed if we
4077 (write-region 4070 ;; use an encoding function, but currently we use it always
4078 start end localname append 'no-message lockname confirm) 4071 ;; because this makes the logic simpler.
4079 (write-region start end localname append 'no-message lockname)) 4072 (tmpfile (tramp-compat-make-temp-file filename)))
4080 4073
4081 ;; We say `no-message' here because we don't want the visited file 4074 ;; We say `no-message' here because we don't want the visited file
4082 ;; modtime data to be clobbered from the temp file. We call 4075 ;; modtime data to be clobbered from the temp file. We call
@@ -4201,8 +4194,13 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
4201 v 'file-error 4194 v 'file-error
4202 (concat "Method `%s' should specify both encoding and " 4195 (concat "Method `%s' should specify both encoding and "
4203 "decoding command or an rcp program") 4196 "decoding command or an rcp program")
4204 method)))) 4197 method)))
4198
4199 ;; Make `last-coding-system-used' have the right value.
4200 (when coding-system-used
4201 (set 'last-coding-system-used coding-system-used)))
4205 4202
4203 ;; Set file modification time.
4206 (when (or (eq visit t) (stringp visit)) 4204 (when (or (eq visit t) (stringp visit))
4207 (set-visited-file-modtime 4205 (set-visited-file-modtime
4208 ;; We must pass modtime explicitely, because filename can be different 4206 ;; We must pass modtime explicitely, because filename can be different
@@ -4210,9 +4208,6 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
4210 (nth 5 (file-attributes filename)))) 4208 (nth 5 (file-attributes filename))))
4211 ;; Set the ownership. 4209 ;; Set the ownership.
4212 (tramp-set-file-uid-gid filename) 4210 (tramp-set-file-uid-gid filename)
4213 ;; Make `last-coding-system-used' have the right value.
4214 (when coding-system-used
4215 (set 'last-coding-system-used coding-system-used))
4216 (when (or (eq visit t) (null visit) (stringp visit)) 4211 (when (or (eq visit t) (null visit) (stringp visit))
4217 (tramp-message v 0 "Wrote %s" filename)) 4212 (tramp-message v 0 "Wrote %s" filename))
4218 (run-hooks 'tramp-handle-write-region-hook)))) 4213 (run-hooks 'tramp-handle-write-region-hook))))
@@ -7558,12 +7553,6 @@ please ensure that the buffers are attached to your email.\n\n")
7558;; * When editing a remote CVS controlled file as a different user, VC 7553;; * When editing a remote CVS controlled file as a different user, VC
7559;; gets confused about the file locking status. Try to find out why 7554;; gets confused about the file locking status. Try to find out why
7560;; the workaround doesn't work. 7555;; the workaround doesn't work.
7561;; * Change `copy-file' to grok the case where the filename handler
7562;; for the source and the target file are different. Right now,
7563;; it looks at the source file and then calls that handler, if
7564;; there is one. But since ange-ftp, for instance, does not know
7565;; about Tramp, it does not do the right thing if the target file
7566;; name is a Tramp name.
7567;; * Username and hostname completion. 7556;; * Username and hostname completion.
7568;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode-p'. 7557;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode-p'.
7569;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'. 7558;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'.