comparison lisp/net/tramp.el @ 100922:2b84620022aa

* net/tramp.el (tramp-handle-load) (tramp-do-copy-or-rename-file-directly) (tramp-handle-file-local-copy, tramp-handle-insert-file-contents) (tramp-handle-write-region): Delete temporary file in case of error.
author Michael Albinus <michael.albinus@gmx.de>
date Mon, 05 Jan 2009 19:37:01 +0000
parents 793052a5fdaf
children 7d332b05e8ac
comparison
equal deleted inserted replaced
100921:ae6c8a6fe386 100922:2b84620022aa
2261 (if (not (file-exists-p file)) 2261 (if (not (file-exists-p file))
2262 nil 2262 nil
2263 (unless nomessage (tramp-message v 0 "Loading %s..." file)) 2263 (unless nomessage (tramp-message v 0 "Loading %s..." file))
2264 (let ((local-copy (file-local-copy file))) 2264 (let ((local-copy (file-local-copy file)))
2265 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil. 2265 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
2266 (load local-copy noerror t t) 2266 (unwind-protect
2267 (delete-file local-copy)) 2267 (load local-copy noerror t t)
2268 (delete-file local-copy)))
2268 (unless nomessage (tramp-message v 0 "Loading %s...done" file)) 2269 (unless nomessage (tramp-message v 0 "Loading %s...done" file))
2269 t))) 2270 t)))
2270 2271
2271 ;; Localname manipulation functions that grok Tramp localnames... 2272 ;; Localname manipulation functions that grok Tramp localnames...
2272 (defun tramp-handle-file-name-as-directory (file) 2273 (defun tramp-handle-file-name-as-directory (file)
3256 (tramp-get-local-uid 'integer) 3257 (tramp-get-local-uid 'integer)
3257 (tramp-get-local-gid 'integer))) 3258 (tramp-get-local-gid 'integer)))
3258 3259
3259 ;; We need a temporary file in between. 3260 ;; We need a temporary file in between.
3260 (t 3261 (t
3261 ;; Create the temporary file. 3262 (condition-case err
3262 (let ((tmpfile (tramp-compat-make-temp-file localname1))) 3263 ;; Create the temporary file.
3263 (cond 3264 (let ((tmpfile (tramp-compat-make-temp-file localname1)))
3264 (t1 3265 (cond
3265 (tramp-send-command 3266 (t1
3266 v (format 3267 (tramp-send-command
3267 "%s %s %s" cmd 3268 v (format
3268 (tramp-shell-quote-argument localname1) 3269 "%s %s %s" cmd
3269 (tramp-shell-quote-argument tmpfile))) 3270 (tramp-shell-quote-argument localname1)
3270 ;; We must change the ownership as remote user. 3271 (tramp-shell-quote-argument tmpfile)))
3271 (tramp-set-file-uid-gid 3272 ;; We must change the ownership as remote user.
3272 (concat prefix tmpfile) 3273 (tramp-set-file-uid-gid
3273 (tramp-get-local-uid 'integer) 3274 (concat prefix tmpfile)
3274 (tramp-get-local-gid 'integer))) 3275 (tramp-get-local-uid 'integer)
3275 (t2 3276 (tramp-get-local-gid 'integer)))
3276 (if (eq op 'copy) 3277 (t2
3277 (tramp-compat-copy-file 3278 (if (eq op 'copy)
3278 localname1 tmpfile ok-if-already-exists 3279 (tramp-compat-copy-file
3279 keep-date preserve-uid-gid) 3280 localname1 tmpfile ok-if-already-exists
3280 (tramp-run-real-handler 3281 keep-date preserve-uid-gid)
3281 'rename-file (list localname1 tmpfile ok-if-already-exists))) 3282 (tramp-run-real-handler
3282 ;; We must change the ownership as local user. 3283 'rename-file
3283 (tramp-set-file-uid-gid 3284 (list localname1 tmpfile ok-if-already-exists)))
3284 tmpfile 3285 ;; We must change the ownership as local user.
3285 (tramp-get-remote-uid v 'integer) 3286 (tramp-set-file-uid-gid
3286 (tramp-get-remote-gid v 'integer)))) 3287 tmpfile
3287 3288 (tramp-get-remote-uid v 'integer)
3288 ;; Move the temporary file to its destination. 3289 (tramp-get-remote-gid v 'integer))))
3289 (cond 3290
3290 (t2 3291 ;; Move the temporary file to its destination.
3291 (tramp-send-command 3292 (cond
3292 v (format 3293 (t2
3293 "mv -f %s %s" 3294 (tramp-send-command
3294 (tramp-shell-quote-argument tmpfile) 3295 v (format
3295 (tramp-shell-quote-argument localname2)))) 3296 "mv -f %s %s"
3296 (t1 3297 (tramp-shell-quote-argument tmpfile)
3297 (tramp-run-real-handler 3298 (tramp-shell-quote-argument localname2))))
3298 'rename-file 3299 (t1
3299 (list tmpfile localname2 ok-if-already-exists)))))))))) 3300 (tramp-run-real-handler
3301 'rename-file
3302 (list tmpfile localname2 ok-if-already-exists)))))
3303
3304 ;; Error handling.
3305 (error (delete-file tmpfile)
3306 (signal (car err) (cdr err)))))))))
3300 3307
3301 ;; Set the time and mode. Mask possible errors. 3308 ;; Set the time and mode. Mask possible errors.
3302 ;; Won't be applied for 'rename. 3309 ;; Won't be applied for 'rename.
3303 (condition-case nil 3310 (condition-case nil
3304 (when (and keep-date (not preserve-uid-gid)) 3311 (when (and keep-date (not preserve-uid-gid))
4049 (let ((coding-system-for-write 'binary)) 4056 (let ((coding-system-for-write 'binary))
4050 (write-region (point-min) (point-max) tmpfile2)) 4057 (write-region (point-min) (point-max) tmpfile2))
4051 (tramp-message 4058 (tramp-message
4052 v 5 "Decoding remote file %s with command %s..." 4059 v 5 "Decoding remote file %s with command %s..."
4053 filename loc-dec) 4060 filename loc-dec)
4054 (tramp-call-local-coding-command loc-dec tmpfile2 tmpfile) 4061 (unwind-protect
4055 (delete-file tmpfile2))) 4062 (tramp-call-local-coding-command loc-dec tmpfile2 tmpfile)
4063 (delete-file tmpfile2))))
4056 (tramp-message v 5 "Decoding remote file %s...done" filename) 4064 (tramp-message v 5 "Decoding remote file %s...done" filename)
4057 ;; Set proper permissions. 4065 ;; Set proper permissions.
4058 (set-file-modes tmpfile (file-modes filename)) 4066 (set-file-modes tmpfile (file-modes filename))
4059 ;; Set local user ownership. 4067 ;; Set local user ownership.
4060 (tramp-set-file-uid-gid tmpfile))) 4068 (tramp-set-file-uid-gid tmpfile)))
4132 'file-local-copy))) 4140 'file-local-copy)))
4133 (file-local-copy filename)))) 4141 (file-local-copy filename))))
4134 (tramp-message v 4 "Inserting local temp file `%s'..." local-copy) 4142 (tramp-message v 4 "Inserting local temp file `%s'..." local-copy)
4135 ;; We must ensure that `file-coding-system-alist' matches 4143 ;; We must ensure that `file-coding-system-alist' matches
4136 ;; `local-copy'. 4144 ;; `local-copy'.
4137 (let ((file-coding-system-alist 4145 (unwind-protect
4138 (tramp-find-file-name-coding-system-alist 4146 (let ((file-coding-system-alist
4139 filename local-copy))) 4147 (tramp-find-file-name-coding-system-alist
4140 (setq result 4148 filename local-copy)))
4141 (insert-file-contents local-copy nil beg end replace)) 4149 (setq result
4142 ;; Now `last-coding-system-used' has right value. Remember it. 4150 (insert-file-contents local-copy nil beg end replace))
4143 (when (boundp 'last-coding-system-used) 4151 ;; Now `last-coding-system-used' has right value. Remember it.
4144 (setq coding-system-used 4152 (when (boundp 'last-coding-system-used)
4145 (symbol-value 'last-coding-system-used)))) 4153 (setq coding-system-used
4154 (symbol-value 'last-coding-system-used))))
4155 (delete-file local-copy))
4146 (tramp-message 4156 (tramp-message
4147 v 4 "Inserting local temp file `%s'...done" local-copy) 4157 v 4 "Inserting local temp file `%s'...done" local-copy)
4148 (delete-file local-copy)
4149 (when (boundp 'last-coding-system-used) 4158 (when (boundp 'last-coding-system-used)
4150 (set 'last-coding-system-used coding-system-used)))) 4159 (set 'last-coding-system-used coding-system-used))))
4151 4160
4152 (when visit 4161 (when visit
4153 (setq buffer-read-only (not (file-writable-p filename))) 4162 (setq buffer-read-only (not (file-writable-p filename)))
4331 ;; file. We call `set-visited-file-modtime' ourselves later 4340 ;; file. We call `set-visited-file-modtime' ourselves later
4332 ;; on. We must ensure that `file-coding-system-alist' 4341 ;; on. We must ensure that `file-coding-system-alist'
4333 ;; matches `tmpfile'. 4342 ;; matches `tmpfile'.
4334 (let ((file-coding-system-alist 4343 (let ((file-coding-system-alist
4335 (tramp-find-file-name-coding-system-alist filename tmpfile))) 4344 (tramp-find-file-name-coding-system-alist filename tmpfile)))
4336 (tramp-run-real-handler 4345 (condition-case err
4337 'write-region 4346 (tramp-run-real-handler
4338 (list start end tmpfile append 'no-message lockname confirm)) 4347 'write-region
4348 (list start end tmpfile append 'no-message lockname confirm))
4349 (error (delete-file tmpfile)
4350 (signal (car err) (cdr err))))
4351
4339 ;; Now, `last-coding-system-used' has the right value. Remember it. 4352 ;; Now, `last-coding-system-used' has the right value. Remember it.
4340 (when (boundp 'last-coding-system-used) 4353 (when (boundp 'last-coding-system-used)
4341 (setq coding-system-used 4354 (setq coding-system-used
4342 (symbol-value 'last-coding-system-used)))) 4355 (symbol-value 'last-coding-system-used))))
4343 4356
4358 ;; `rename-file' handles direct copy and out-of-band methods. 4371 ;; `rename-file' handles direct copy and out-of-band methods.
4359 ((or (tramp-local-host-p v) 4372 ((or (tramp-local-host-p v)
4360 (and (tramp-method-out-of-band-p v) 4373 (and (tramp-method-out-of-band-p v)
4361 (> (- (or end (point-max)) (or start (point-min))) 4374 (> (- (or end (point-max)) (or start (point-min)))
4362 tramp-copy-size-limit))) 4375 tramp-copy-size-limit)))
4363 (rename-file tmpfile filename t)) 4376 (condition-case err
4377 (rename-file tmpfile filename t)
4378 (error (delete-file tmpfile)
4379 (signal (car err) (cdr err)))))
4364 4380
4365 ;; Use inline file transfer. 4381 ;; Use inline file transfer.
4366 (rem-dec 4382 (rem-dec
4367 ;; Encode tmpfile. 4383 ;; Encode tmpfile.
4368 (tramp-message v 5 "Encoding region...") 4384 (tramp-message v 5 "Encoding region...")