Mercurial > emacs
comparison lisp/net/tramp-smb.el @ 49995:a0e8a85259ed
Version 2.0.30 released.
Replace term "path" with "localname" unless it is used for a
search path.
(tramp-handle-expand-file-name): Allow ".." to cross host
boundaries.
(tramp-open-connection-setup-interactive-shell): Unset $ENV in
addition to setting $PS1 when starting the Bourne-ish shell. Some
sh implementations (eg, bash when called as sh) read the file
named there on startup, which could clobber $PS1.
(tramp-do-copy-or-rename-file-one-local): New function. Not
implemented. Not used. Should invoke rcp or scp directly to keep
the time.
author | Kai Großjohann <kgrossjo@eu.uu.net> |
---|---|
date | Fri, 28 Feb 2003 18:28:47 +0000 |
parents | 407d6516031a |
children | 155b4b78aa3b |
comparison
equal
deleted
inserted
replaced
49994:dcf78d005b68 | 49995:a0e8a85259ed |
---|---|
223 (when (and (not ok-if-already-exists) | 223 (when (and (not ok-if-already-exists) |
224 (file-exists-p newname)) | 224 (file-exists-p newname)) |
225 (error "copy-file: file %s already exists" newname)) | 225 (error "copy-file: file %s already exists" newname)) |
226 | 226 |
227 ; (with-parsed-tramp-file-name newname nil | 227 ; (with-parsed-tramp-file-name newname nil |
228 (let (user host path) | 228 (let (user host localname) |
229 (with-parsed-tramp-file-name newname l | 229 (with-parsed-tramp-file-name newname l |
230 (setq user l-user host l-host path l-path)) | 230 (setq user l-user host l-host localname l-localname)) |
231 (save-excursion | 231 (save-excursion |
232 (let ((share (tramp-smb-get-share path)) | 232 (let ((share (tramp-smb-get-share localname)) |
233 (file (tramp-smb-get-path path t))) | 233 (file (tramp-smb-get-localname localname t))) |
234 (unless share | 234 (unless share |
235 (error "Target `%s' must contain a share name" filename)) | 235 (error "Target `%s' must contain a share name" filename)) |
236 (tramp-smb-maybe-open-connection user host share) | 236 (tramp-smb-maybe-open-connection user host share) |
237 (tramp-message-for-buffer | 237 (tramp-message-for-buffer |
238 nil tramp-smb-method user host | 238 nil tramp-smb-method user host |
248 "Like `delete-directory' for tramp files." | 248 "Like `delete-directory' for tramp files." |
249 (setq directory (directory-file-name (expand-file-name directory))) | 249 (setq directory (directory-file-name (expand-file-name directory))) |
250 (unless (file-exists-p directory) | 250 (unless (file-exists-p directory) |
251 (error "Cannot delete non-existing directory `%s'" directory)) | 251 (error "Cannot delete non-existing directory `%s'" directory)) |
252 ; (with-parsed-tramp-file-name directory nil | 252 ; (with-parsed-tramp-file-name directory nil |
253 (let (user host path) | 253 (let (user host localname) |
254 (with-parsed-tramp-file-name directory l | 254 (with-parsed-tramp-file-name directory l |
255 (setq user l-user host l-host path l-path)) | 255 (setq user l-user host l-host localname l-localname)) |
256 (save-excursion | 256 (save-excursion |
257 (let ((share (tramp-smb-get-share path)) | 257 (let ((share (tramp-smb-get-share localname)) |
258 (dir (tramp-smb-get-path (file-name-directory path) t)) | 258 (dir (tramp-smb-get-localname (file-name-directory localname) t)) |
259 (file (file-name-nondirectory path))) | 259 (file (file-name-nondirectory localname))) |
260 (tramp-smb-maybe-open-connection user host share) | 260 (tramp-smb-maybe-open-connection user host share) |
261 (if (and | 261 (if (and |
262 (tramp-smb-send-command user host (format "cd \"%s\"" dir)) | 262 (tramp-smb-send-command user host (format "cd \"%s\"" dir)) |
263 (tramp-smb-send-command user host (format "rmdir \"%s\"" file))) | 263 (tramp-smb-send-command user host (format "rmdir \"%s\"" file))) |
264 ;; Go Home | 264 ;; Go Home |
271 "Like `delete-file' for tramp files." | 271 "Like `delete-file' for tramp files." |
272 (setq filename (expand-file-name filename)) | 272 (setq filename (expand-file-name filename)) |
273 (unless (file-exists-p filename) | 273 (unless (file-exists-p filename) |
274 (error "Cannot delete non-existing file `%s'" filename)) | 274 (error "Cannot delete non-existing file `%s'" filename)) |
275 ; (with-parsed-tramp-file-name filename nil | 275 ; (with-parsed-tramp-file-name filename nil |
276 (let (user host path) | 276 (let (user host localname) |
277 (with-parsed-tramp-file-name filename l | 277 (with-parsed-tramp-file-name filename l |
278 (setq user l-user host l-host path l-path)) | 278 (setq user l-user host l-host localname l-localname)) |
279 (save-excursion | 279 (save-excursion |
280 (let ((share (tramp-smb-get-share path)) | 280 (let ((share (tramp-smb-get-share localname)) |
281 (dir (tramp-smb-get-path (file-name-directory path) t)) | 281 (dir (tramp-smb-get-localname (file-name-directory localname) t)) |
282 (file (file-name-nondirectory path))) | 282 (file (file-name-nondirectory localname))) |
283 (unless (file-exists-p filename) | 283 (unless (file-exists-p filename) |
284 (error "Cannot delete non-existing file `%s'" filename)) | 284 (error "Cannot delete non-existing file `%s'" filename)) |
285 (tramp-smb-maybe-open-connection user host share) | 285 (tramp-smb-maybe-open-connection user host share) |
286 (if (and | 286 (if (and |
287 (tramp-smb-send-command user host (format "cd \"%s\"" dir)) | 287 (tramp-smb-send-command user host (format "cd \"%s\"" dir)) |
295 (defun tramp-smb-handle-directory-files | 295 (defun tramp-smb-handle-directory-files |
296 (directory &optional full match nosort) | 296 (directory &optional full match nosort) |
297 "Like `directory-files' for tramp files." | 297 "Like `directory-files' for tramp files." |
298 (setq directory (directory-file-name (expand-file-name directory))) | 298 (setq directory (directory-file-name (expand-file-name directory))) |
299 ; (with-parsed-tramp-file-name directory nil | 299 ; (with-parsed-tramp-file-name directory nil |
300 (let (user host path) | 300 (let (user host localname) |
301 (with-parsed-tramp-file-name directory l | 301 (with-parsed-tramp-file-name directory l |
302 (setq user l-user host l-host path l-path)) | 302 (setq user l-user host l-host localname l-localname)) |
303 (save-excursion | 303 (save-excursion |
304 (let* ((share (tramp-smb-get-share path)) | 304 (let* ((share (tramp-smb-get-share localname)) |
305 (file (tramp-smb-get-path path nil)) | 305 (file (tramp-smb-get-localname localname nil)) |
306 (entries (tramp-smb-get-file-entries user host share file))) | 306 (entries (tramp-smb-get-file-entries user host share file))) |
307 ;; Just the file names are needed | 307 ;; Just the file names are needed |
308 (setq entries (mapcar 'car entries)) | 308 (setq entries (mapcar 'car entries)) |
309 ;; Discriminate with regexp | 309 ;; Discriminate with regexp |
310 (when match | 310 (when match |
311 (setq entries | 311 (setq entries |
312 (delete nil | 312 (delete nil |
313 (mapcar (lambda (x) (when (string-match match x) x)) | 313 (mapcar (lambda (x) (when (string-match match x) x)) |
314 entries)))) | 314 entries)))) |
315 ;; Make absolute paths if necessary | 315 ;; Make absolute localnames if necessary |
316 (when full | 316 (when full |
317 (setq entries | 317 (setq entries |
318 (mapcar (lambda (x) | 318 (mapcar (lambda (x) |
319 (concat (file-name-as-directory directory) x)) | 319 (concat (file-name-as-directory directory) x)) |
320 entries))) | 320 entries))) |
329 (mapcar | 329 (mapcar |
330 (lambda (x) | 330 (lambda (x) |
331 (cons x (file-attributes | 331 (cons x (file-attributes |
332 (if full x (concat (file-name-as-directory directory) x))))) | 332 (if full x (concat (file-name-as-directory directory) x))))) |
333 (directory-files directory full match nosort))) | 333 (directory-files directory full match nosort))) |
334 | 334 |
335 (defun tramp-smb-handle-file-attributes (filename &optional nonnumeric) | 335 (defun tramp-smb-handle-file-attributes (filename &optional nonnumeric) |
336 "Like `file-attributes' for tramp files. | 336 "Like `file-attributes' for tramp files. |
337 Optional argument NONNUMERIC means return user and group name | 337 Optional argument NONNUMERIC means return user and group name |
338 rather than as numbers." | 338 rather than as numbers." |
339 ; (with-parsed-tramp-file-name filename nil | 339 ; (with-parsed-tramp-file-name filename nil |
340 (let (user host path) | 340 (let (user host localname) |
341 (with-parsed-tramp-file-name filename l | 341 (with-parsed-tramp-file-name filename l |
342 (setq user l-user host l-host path l-path)) | 342 (setq user l-user host l-host localname l-localname)) |
343 (save-excursion | 343 (save-excursion |
344 (let* ((share (tramp-smb-get-share path)) | 344 (let* ((share (tramp-smb-get-share localname)) |
345 (file (tramp-smb-get-path path nil)) | 345 (file (tramp-smb-get-localname localname nil)) |
346 (entries (tramp-smb-get-file-entries user host share file)) | 346 (entries (tramp-smb-get-file-entries user host share file)) |
347 (entry (and entries | 347 (entry (and entries |
348 (assoc (file-name-nondirectory file) entries))) | 348 (assoc (file-name-nondirectory file) entries))) |
349 (inode (tramp-smb-get-inode share file)) | 349 (inode (tramp-smb-get-inode share file)) |
350 (device (tramp-get-device nil tramp-smb-method user host))) | 350 (device (tramp-get-device nil tramp-smb-method user host))) |
366 device)))))) ;11 file system number | 366 device)))))) ;11 file system number |
367 | 367 |
368 (defun tramp-smb-handle-file-directory-p (filename) | 368 (defun tramp-smb-handle-file-directory-p (filename) |
369 "Like `file-directory-p' for tramp files." | 369 "Like `file-directory-p' for tramp files." |
370 ; (with-parsed-tramp-file-name filename nil | 370 ; (with-parsed-tramp-file-name filename nil |
371 (let (user host path) | 371 (let (user host localname) |
372 (with-parsed-tramp-file-name filename l | 372 (with-parsed-tramp-file-name filename l |
373 (setq user l-user host l-host path l-path)) | 373 (setq user l-user host l-host localname l-localname)) |
374 (save-excursion | 374 (save-excursion |
375 (let* ((share (tramp-smb-get-share path)) | 375 (let* ((share (tramp-smb-get-share localname)) |
376 (file (tramp-smb-get-path path nil)) | 376 (file (tramp-smb-get-localname localname nil)) |
377 (entries (tramp-smb-get-file-entries user host share file)) | 377 (entries (tramp-smb-get-file-entries user host share file)) |
378 (entry (and entries | 378 (entry (and entries |
379 (assoc (file-name-nondirectory file) entries)))) | 379 (assoc (file-name-nondirectory file) entries)))) |
380 (and entry | 380 (and entry |
381 (string-match "d" (nth 1 entry)) | 381 (string-match "d" (nth 1 entry)) |
382 t))))) | 382 t))))) |
383 | 383 |
384 (defun tramp-smb-handle-file-exists-p (filename) | 384 (defun tramp-smb-handle-file-exists-p (filename) |
385 "Like `file-exists-p' for tramp files." | 385 "Like `file-exists-p' for tramp files." |
386 ; (with-parsed-tramp-file-name filename nil | 386 ; (with-parsed-tramp-file-name filename nil |
387 (let (user host path) | 387 (let (user host localname) |
388 (with-parsed-tramp-file-name filename l | 388 (with-parsed-tramp-file-name filename l |
389 (setq user l-user host l-host path l-path)) | 389 (setq user l-user host l-host localname l-localname)) |
390 (save-excursion | 390 (save-excursion |
391 (let* ((share (tramp-smb-get-share path)) | 391 (let* ((share (tramp-smb-get-share localname)) |
392 (file (tramp-smb-get-path path nil)) | 392 (file (tramp-smb-get-localname localname nil)) |
393 (entries (tramp-smb-get-file-entries user host share file))) | 393 (entries (tramp-smb-get-file-entries user host share file))) |
394 (and entries | 394 (and entries |
395 (member (file-name-nondirectory file) (mapcar 'car entries)) | 395 (member (file-name-nondirectory file) (mapcar 'car entries)) |
396 t))))) | 396 t))))) |
397 | 397 |
398 (defun tramp-smb-handle-file-local-copy (filename) | 398 (defun tramp-smb-handle-file-local-copy (filename) |
399 "Like `file-local-copy' for tramp files." | 399 "Like `file-local-copy' for tramp files." |
400 (with-parsed-tramp-file-name filename nil | 400 (with-parsed-tramp-file-name filename nil |
401 (save-excursion | 401 (save-excursion |
402 (let ((share (tramp-smb-get-share path)) | 402 (let ((share (tramp-smb-get-share localname)) |
403 (file (tramp-smb-get-path path t)) | 403 (file (tramp-smb-get-localname localname t)) |
404 (tmpfil (tramp-make-temp-file))) | 404 (tmpfil (tramp-make-temp-file))) |
405 (unless (file-exists-p filename) | 405 (unless (file-exists-p filename) |
406 (error "Cannot make local copy of non-existing file `%s'" filename)) | 406 (error "Cannot make local copy of non-existing file `%s'" filename)) |
407 (tramp-message-for-buffer | 407 (tramp-message-for-buffer |
408 nil tramp-smb-method user host | 408 nil tramp-smb-method user host |
419 ;; This function should return "foo/" for directories and "bar" for | 419 ;; This function should return "foo/" for directories and "bar" for |
420 ;; files. | 420 ;; files. |
421 (defun tramp-smb-handle-file-name-all-completions (filename directory) | 421 (defun tramp-smb-handle-file-name-all-completions (filename directory) |
422 "Like `file-name-all-completions' for tramp files." | 422 "Like `file-name-all-completions' for tramp files." |
423 ; (with-parsed-tramp-file-name directory nil | 423 ; (with-parsed-tramp-file-name directory nil |
424 (let (user host path) | 424 (let (user host localname) |
425 (with-parsed-tramp-file-name directory l | 425 (with-parsed-tramp-file-name directory l |
426 (setq user l-user host l-host path l-path)) | 426 (setq user l-user host l-host localname l-localname)) |
427 (save-match-data | 427 (save-match-data |
428 (save-excursion | 428 (save-excursion |
429 (let* ((share (tramp-smb-get-share path)) | 429 (let* ((share (tramp-smb-get-share localname)) |
430 (file (tramp-smb-get-path path nil)) | 430 (file (tramp-smb-get-localname localname nil)) |
431 (entries (tramp-smb-get-file-entries user host share file))) | 431 (entries (tramp-smb-get-file-entries user host share file))) |
432 | 432 |
433 (all-completions | 433 (all-completions |
434 filename | 434 filename |
435 (mapcar | 435 (mapcar |
449 (file-attributes file1))))) | 449 (file-attributes file1))))) |
450 | 450 |
451 (defun tramp-smb-handle-file-writable-p (filename) | 451 (defun tramp-smb-handle-file-writable-p (filename) |
452 "Like `file-writable-p' for tramp files." | 452 "Like `file-writable-p' for tramp files." |
453 ; (with-parsed-tramp-file-name filename nil | 453 ; (with-parsed-tramp-file-name filename nil |
454 (let (user host path) | 454 (let (user host localname) |
455 (with-parsed-tramp-file-name filename l | 455 (with-parsed-tramp-file-name filename l |
456 (setq user l-user host l-host path l-path)) | 456 (setq user l-user host l-host localname l-localname)) |
457 (save-excursion | 457 (save-excursion |
458 (let* ((share (tramp-smb-get-share path)) | 458 (let* ((share (tramp-smb-get-share localname)) |
459 (file (tramp-smb-get-path path nil)) | 459 (file (tramp-smb-get-localname localname nil)) |
460 (entries (tramp-smb-get-file-entries user host share file)) | 460 (entries (tramp-smb-get-file-entries user host share file)) |
461 (entry (and entries | 461 (entry (and entries |
462 (assoc (file-name-nondirectory file) entries)))) | 462 (assoc (file-name-nondirectory file) entries)))) |
463 (and entry | 463 (and entry |
464 (string-match "w" (nth 1 entry)) | 464 (string-match "w" (nth 1 entry)) |
472 (when (file-directory-p filename) | 472 (when (file-directory-p filename) |
473 ;; This check is a little bit strange, but in `dired-add-entry' | 473 ;; This check is a little bit strange, but in `dired-add-entry' |
474 ;; this function is called with a non-directory ... | 474 ;; this function is called with a non-directory ... |
475 (setq filename (file-name-as-directory filename))) | 475 (setq filename (file-name-as-directory filename))) |
476 ; (with-parsed-tramp-file-name filename nil | 476 ; (with-parsed-tramp-file-name filename nil |
477 (let (user host path) | 477 (let (user host localname) |
478 (with-parsed-tramp-file-name filename l | 478 (with-parsed-tramp-file-name filename l |
479 (setq user l-user host l-host path l-path)) | 479 (setq user l-user host l-host localname l-localname)) |
480 (save-match-data | 480 (save-match-data |
481 (let* ((share (tramp-smb-get-share path)) | 481 (let* ((share (tramp-smb-get-share localname)) |
482 (file (tramp-smb-get-path path nil)) | 482 (file (tramp-smb-get-localname localname nil)) |
483 (entries (tramp-smb-get-file-entries user host share file))) | 483 (entries (tramp-smb-get-file-entries user host share file))) |
484 | 484 |
485 ;; Delete dummy "" entry, useless entries | 485 ;; Delete dummy "" entry, useless entries |
486 (setq entries | 486 (setq entries |
487 (if (file-directory-p filename) | 487 (if (file-directory-p filename) |
488 (delq (assoc "" entries) entries) | 488 (delq (assoc "" entries) entries) |
489 ;; We just need the only and only entry FILENAME. | 489 ;; We just need the only and only entry FILENAME. |
490 (list (assoc (file-name-nondirectory filename) entries)))) | 490 (list (assoc (file-name-nondirectory filename) entries)))) |
491 | 491 |
525 "Like `make-directory' for tramp files." | 525 "Like `make-directory' for tramp files." |
526 (setq dir (directory-file-name (expand-file-name dir))) | 526 (setq dir (directory-file-name (expand-file-name dir))) |
527 (unless (file-name-absolute-p dir) | 527 (unless (file-name-absolute-p dir) |
528 (setq dir (concat default-directory dir))) | 528 (setq dir (concat default-directory dir))) |
529 ; (with-parsed-tramp-file-name dir nil | 529 ; (with-parsed-tramp-file-name dir nil |
530 (let (user host path) | 530 (let (user host localname) |
531 (with-parsed-tramp-file-name dir l | 531 (with-parsed-tramp-file-name dir l |
532 (setq user l-user host l-host path l-path)) | 532 (setq user l-user host l-host localname l-localname)) |
533 (save-match-data | 533 (save-match-data |
534 (let* ((share (tramp-smb-get-share path)) | 534 (let* ((share (tramp-smb-get-share localname)) |
535 (ldir (file-name-directory dir))) | 535 (ldir (file-name-directory dir))) |
536 ;; Make missing directory parts | 536 ;; Make missing directory parts |
537 (when (and parents share (not (file-directory-p ldir))) | 537 (when (and parents share (not (file-directory-p ldir))) |
538 (make-directory ldir parents)) | 538 (make-directory ldir parents)) |
539 ;; Just do it | 539 ;; Just do it |
546 "Like `make-directory-internal' for tramp files." | 546 "Like `make-directory-internal' for tramp files." |
547 (setq directory (directory-file-name (expand-file-name directory))) | 547 (setq directory (directory-file-name (expand-file-name directory))) |
548 (unless (file-name-absolute-p directory) | 548 (unless (file-name-absolute-p directory) |
549 (setq ldir (concat default-directory directory))) | 549 (setq ldir (concat default-directory directory))) |
550 ; (with-parsed-tramp-file-name directory nil | 550 ; (with-parsed-tramp-file-name directory nil |
551 (let (user host path) | 551 (let (user host localname) |
552 (with-parsed-tramp-file-name directory l | 552 (with-parsed-tramp-file-name directory l |
553 (setq user l-user host l-host path l-path)) | 553 (setq user l-user host l-host localname l-localname)) |
554 (save-match-data | 554 (save-match-data |
555 (let* ((share (tramp-smb-get-share path)) | 555 (let* ((share (tramp-smb-get-share localname)) |
556 (file (tramp-smb-get-path path nil))) | 556 (file (tramp-smb-get-localname localname nil))) |
557 (when (file-directory-p (file-name-directory directory)) | 557 (when (file-directory-p (file-name-directory directory)) |
558 (tramp-smb-maybe-open-connection user host share) | 558 (tramp-smb-maybe-open-connection user host share) |
559 (tramp-smb-send-command user host (format "mkdir \"%s\"" file))) | 559 (tramp-smb-send-command user host (format "mkdir \"%s\"" file))) |
560 (unless (file-directory-p directory) | 560 (unless (file-directory-p directory) |
561 (error "Couldn't make directory %s" directory)))))) | 561 (error "Couldn't make directory %s" directory)))))) |
579 (when (and (not ok-if-already-exists) | 579 (when (and (not ok-if-already-exists) |
580 (file-exists-p newname)) | 580 (file-exists-p newname)) |
581 (error "rename-file: file %s already exists" newname)) | 581 (error "rename-file: file %s already exists" newname)) |
582 | 582 |
583 ; (with-parsed-tramp-file-name newname nil | 583 ; (with-parsed-tramp-file-name newname nil |
584 (let (user host path) | 584 (let (user host localname) |
585 (with-parsed-tramp-file-name newname l | 585 (with-parsed-tramp-file-name newname l |
586 (setq user l-user host l-host path l-path)) | 586 (setq user l-user host l-host localname l-localname)) |
587 (save-excursion | 587 (save-excursion |
588 (let ((share (tramp-smb-get-share path)) | 588 (let ((share (tramp-smb-get-share localname)) |
589 (file (tramp-smb-get-path path t))) | 589 (file (tramp-smb-get-localname localname t))) |
590 (tramp-smb-maybe-open-connection user host share) | 590 (tramp-smb-maybe-open-connection user host share) |
591 (tramp-message-for-buffer | 591 (tramp-message-for-buffer |
592 nil tramp-smb-method user host | 592 nil tramp-smb-method user host |
593 5 "Copying file %s to file %s..." filename newname) | 593 5 "Copying file %s to file %s..." filename newname) |
594 (if (tramp-smb-send-command | 594 (if (tramp-smb-send-command |
611 confirm (file-exists-p filename)) | 611 confirm (file-exists-p filename)) |
612 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " | 612 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " |
613 filename)) | 613 filename)) |
614 (error "File not overwritten"))) | 614 (error "File not overwritten"))) |
615 ; (with-parsed-tramp-file-name filename nil | 615 ; (with-parsed-tramp-file-name filename nil |
616 (let (user host path) | 616 (let (user host localname) |
617 (with-parsed-tramp-file-name filename l | 617 (with-parsed-tramp-file-name filename l |
618 (setq user l-user host l-host path l-path)) | 618 (setq user l-user host l-host localname l-localname)) |
619 (save-excursion | 619 (save-excursion |
620 (let ((share (tramp-smb-get-share path)) | 620 (let ((share (tramp-smb-get-share localname)) |
621 (file (tramp-smb-get-path path t)) | 621 (file (tramp-smb-get-localname localname t)) |
622 (curbuf (current-buffer)) | 622 (curbuf (current-buffer)) |
623 ;; We use this to save the value of `last-coding-system-used' | 623 ;; We use this to save the value of `last-coding-system-used' |
624 ;; after writing the tmp file. At the end of the function, | 624 ;; after writing the tmp file. At the end of the function, |
625 ;; we set `last-coding-system-used' to this saved value. | 625 ;; we set `last-coding-system-used' to this saved value. |
626 ;; This way, any intermediary coding systems used while | 626 ;; This way, any intermediary coding systems used while |
664 (setq last-coding-system-used coding-system-used)))))) | 664 (setq last-coding-system-used coding-system-used)))))) |
665 | 665 |
666 | 666 |
667 ;; Internal file name functions | 667 ;; Internal file name functions |
668 | 668 |
669 (defun tramp-smb-get-share (path) | 669 (defun tramp-smb-get-share (localname) |
670 "Returns the share name of PATH." | 670 "Returns the share name of LOCALNAME." |
671 (save-match-data | 671 (save-match-data |
672 (when (string-match "^/?\\([^/]+\\)/" path) | 672 (when (string-match "^/?\\([^/]+\\)/" localname) |
673 (match-string 1 path)))) | 673 (match-string 1 localname)))) |
674 | 674 |
675 (defun tramp-smb-get-path (path convert) | 675 (defun tramp-smb-get-localname (localname convert) |
676 "Returns the file name of PATH. | 676 "Returns the file name of LOCALNAME. |
677 If CONVERT is non-nil exchange \"/\" by \"\\\\\"." | 677 If CONVERT is non-nil exchange \"/\" by \"\\\\\"." |
678 (save-match-data | 678 (save-match-data |
679 (let ((res path)) | 679 (let ((res localname)) |
680 | 680 |
681 (setq | 681 (setq |
682 res (if (string-match "^/?[^/]+/\\(.*\\)" res) | 682 res (if (string-match "^/?[^/]+/\\(.*\\)" res) |
683 (if convert | 683 (if convert |
684 (mapconcat | 684 (mapconcat |
695 | 695 |
696 res))) | 696 res))) |
697 | 697 |
698 ;; Share names of a host are cached. It is very unlikely that the | 698 ;; Share names of a host are cached. It is very unlikely that the |
699 ;; shares do change during connection. | 699 ;; shares do change during connection. |
700 (defun tramp-smb-get-file-entries (user host share path) | 700 (defun tramp-smb-get-file-entries (user host share localname) |
701 "Read entries which match PATH. | 701 "Read entries which match LOCALNAME. |
702 Either the shares are listed, or the `dir' command is executed. | 702 Either the shares are listed, or the `dir' command is executed. |
703 Only entries matching the path are returned. | 703 Only entries matching the localname are returned. |
704 Result is a list of (PATH MODE SIZE MONTH DAY TIME YEAR)." | 704 Result is a list of (LOCALNAME MODE SIZE MONTH DAY TIME YEAR)." |
705 (save-excursion | 705 (save-excursion |
706 (save-match-data | 706 (save-match-data |
707 (let ((base (or (and (> (length path) 0) | 707 (let ((base (or (and (> (length localname) 0) |
708 (string-match "\\([^/]+\\)$" path) | 708 (string-match "\\([^/]+\\)$" localname) |
709 (regexp-quote (match-string 1 path))) | 709 (regexp-quote (match-string 1 localname))) |
710 "")) | 710 "")) |
711 res entry) | 711 res entry) |
712 (set-buffer (tramp-get-buffer nil tramp-smb-method user host)) | 712 (set-buffer (tramp-get-buffer nil tramp-smb-method user host)) |
713 (if (and (not share) tramp-smb-share-cache) | 713 (if (and (not share) tramp-smb-share-cache) |
714 ;; Return cached shares | 714 ;; Return cached shares |
717 (tramp-smb-maybe-open-connection user host share) | 717 (tramp-smb-maybe-open-connection user host share) |
718 (when share | 718 (when share |
719 (tramp-smb-send-command | 719 (tramp-smb-send-command |
720 user host | 720 user host |
721 (format "dir %s" | 721 (format "dir %s" |
722 (if (zerop (length path)) "" (concat "\"" path "*\""))))) | 722 (if (zerop (length localname)) "" (concat "\"" localname "*\""))))) |
723 (goto-char (point-min)) | 723 (goto-char (point-min)) |
724 ;; Loop the listing | 724 ;; Loop the listing |
725 (unless (re-search-forward tramp-smb-errors nil t) | 725 (unless (re-search-forward tramp-smb-errors nil t) |
726 (while (not (eobp)) | 726 (while (not (eobp)) |
727 (setq entry (tramp-smb-read-file-entry share)) | 727 (setq entry (tramp-smb-read-file-entry share)) |
778 ;; | 778 ;; |
779 ;; So we try to analyze backwards. | 779 ;; So we try to analyze backwards. |
780 (defun tramp-smb-read-file-entry (share) | 780 (defun tramp-smb-read-file-entry (share) |
781 "Parse entry in SMB output buffer. | 781 "Parse entry in SMB output buffer. |
782 If SHARE is result, entries are of type dir. Otherwise, shares are listed. | 782 If SHARE is result, entries are of type dir. Otherwise, shares are listed. |
783 Result is the list (PATH MODE SIZE MTIME)." | 783 Result is the list (LOCALNAME MODE SIZE MTIME)." |
784 (let ((line (buffer-substring (point) (tramp-point-at-eol))) | 784 (let ((line (buffer-substring (point) (tramp-point-at-eol))) |
785 path mode size month day hour min sec year mtime) | 785 localname mode size month day hour min sec year mtime) |
786 | 786 |
787 (if (not share) | 787 (if (not share) |
788 | 788 |
789 ; Read share entries | 789 ; Read share entries |
790 (when (string-match "^\\s-+\\(\\S-+\\)\\s-+Disk" line) | 790 (when (string-match "^\\s-+\\(\\S-+\\)\\s-+Disk" line) |
791 (setq path (match-string 1 line) | 791 (setq localname (match-string 1 line) |
792 mode "dr-xr-xr-x" | 792 mode "dr-xr-xr-x" |
793 size 0)) | 793 size 0)) |
794 | 794 |
795 ; Real listing | 795 ; Real listing |
796 (block nil | 796 (block nil |
845 (lambda (x) "") " " | 845 (lambda (x) "") " " |
846 (concat "r" (if (string-match "R" mode) "-" "w") "x")))) | 846 (concat "r" (if (string-match "R" mode) "-" "w") "x")))) |
847 line (substring line 0 (- (1+ (length (match-string 2 line)))))) | 847 line (substring line 0 (- (1+ (length (match-string 2 line)))))) |
848 (return)) | 848 (return)) |
849 | 849 |
850 ;; path | 850 ;; localname |
851 (if (string-match "^\\s-+\\(\\S-\\(.*\\S-\\)?\\)\\s-+$" line) | 851 (if (string-match "^\\s-+\\(\\S-\\(.*\\S-\\)?\\)\\s-+$" line) |
852 (setq path (match-string 1 line)) | 852 (setq localname (match-string 1 line)) |
853 (return)))) | 853 (return)))) |
854 | 854 |
855 (when (and path mode size) | 855 (when (and localname mode size) |
856 (setq mtime | 856 (setq mtime |
857 (if (and sec min hour day month year) | 857 (if (and sec min hour day month year) |
858 (encode-time | 858 (encode-time |
859 sec min hour day | 859 sec min hour day |
860 (cdr (assoc (downcase month) tramp-smb-parse-time-months)) | 860 (cdr (assoc (downcase month) tramp-smb-parse-time-months)) |
861 year) | 861 year) |
862 '(0 0))) | 862 '(0 0))) |
863 (list path mode size mtime)))) | 863 (list localname mode size mtime)))) |
864 | 864 |
865 ;; Inodes don't exist for SMB files. Therefore we must generate virtual ones. | 865 ;; Inodes don't exist for SMB files. Therefore we must generate virtual ones. |
866 ;; Used in `find-buffer-visiting'. | 866 ;; Used in `find-buffer-visiting'. |
867 ;; The method applied might be not so efficient (Ange-FTP uses hashes). But | 867 ;; The method applied might be not so efficient (Ange-FTP uses hashes). But |
868 ;; performance isn't the major issue given that file transfer will take time. | 868 ;; performance isn't the major issue given that file transfer will take time. |