emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/lisp/net tramp-smb.el


From: Michael Albinus
Subject: [Emacs-diffs] emacs/lisp/net tramp-smb.el
Date: Wed, 21 Oct 2009 11:27:27 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Michael Albinus <albinus>       09/10/21 11:27:27

Modified files:
        lisp/net       : tramp-smb.el 

Log message:
        * net/tramp-smb.el (tramp-smb-get-stat-capability): New defun.
        (tramp-smb-handle-file-attributes): Use it.
        (tramp-smb-do-file-attributes-with-stat): Don't raise an error.
        (tramp-smb-handle-insert-directory): Use `mapc' rather than
        `mapcar'.  Use `tramp-smb-get-stat-capability'.  Add
        `dired-filename' text properties.
        (tramp-smb-get-cifs-capabilities): Apply `save-match-data'.
        (tramp-smb-maybe-open-connection): Simplify check for smbclient
        version.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/net/tramp-smb.el?cvsroot=emacs&r1=1.59&r2=1.60

Patches:
Index: tramp-smb.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/tramp-smb.el,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- tramp-smb.el        16 Oct 2009 14:36:02 -0000      1.59
+++ tramp-smb.el        21 Oct 2009 11:27:26 -0000      1.60
@@ -481,7 +481,7 @@
   (unless id-format (setq id-format 'integer))
   (with-parsed-tramp-file-name filename nil
     (with-file-property v localname (format "file-attributes-%s" id-format)
-      (if (and (tramp-smb-get-share v) (tramp-smb-get-cifs-capabilities v))
+      (if (and (tramp-smb-get-share v) (tramp-smb-get-stat-capability v))
          (tramp-smb-do-file-attributes-with-stat v id-format)
        ;; Reading just the filename entry via "dir localname" is not
        ;; possible, because when filename is a directory, some
@@ -519,15 +519,8 @@
    vec 5 "file attributes with stat: %s" (tramp-file-name-localname vec))
   (with-current-buffer (tramp-get-buffer vec)
     (let* (size id link uid gid atime mtime ctime mode inode)
-      (unless
-         (tramp-smb-send-command
+      (when (tramp-smb-send-command
           vec (format "stat \"%s\"" (tramp-smb-get-localname vec)))
-       ;; Error.
-       (with-current-buffer (tramp-get-connection-buffer vec)
-         (goto-char (point-min))
-         (search-forward-regexp tramp-smb-errors nil t)
-         (tramp-error
-          vec 'file-error "%s" (match-string 0))))
 
       ;; Loop the listing.
       (goto-char (point-min))
@@ -583,7 +576,7 @@
          (forward-line))
        ;; Return the result.
        (list id link uid gid atime mtime ctime size mode nil inode
-             (tramp-get-device vec))))))
+               (tramp-get-device vec)))))))
 
 (defun tramp-smb-handle-file-directory-p (filename)
   "Like `file-directory-p' for Tramp files."
@@ -709,30 +702,33 @@
           entries))
 
        ;; Print entries.
-       (mapcar
+       (mapc
         (lambda (x)
           (when (not (zerop (length (nth 0 x))))
             (let ((attr
-                   (when (tramp-smb-get-cifs-capabilities v)
+                   (when (tramp-smb-get-stat-capability v)
                      (ignore-errors
                        (file-attributes
                         (expand-file-name (nth 0 x)) 'string)))))
               (insert
                (format
-                "%10s %3d %-8s %-8s %8s %s %s\n"
+                "%10s %3d %-8s %-8s %8s %s "
                 (or (nth 8 attr) (nth 1 x)) ; mode
-                (or (nth 1 attr) 1) ; link
+                (or (nth 1 attr) 1) ; inode
                 (or (nth 2 attr) "nobody") ; uid
                 (or (nth 3 attr) "nogroup") ; gid
-                (nth 2 x) ; size
+                (or (nth 7 attr) (nth 2 x)) ; size
                 (format-time-string
                  (if (tramp-time-less-p
                       (tramp-time-subtract (current-time) (nth 3 x))
                       tramp-half-a-year)
                      "%b %e %R"
                    "%b %e  %Y")
-                 (nth 3 x)) ; date
-                (nth 0 x))) ; file name
+                 (nth 3 x)))) ; date
+              ;; We mark the filename.
+              (let ((start (point)))
+                (insert (format "%s\n" (nth 0 x))) ; file name
+                (put-text-property start (1- (point)) 'dired-filename t))
               (forward-line)
               (beginning-of-line))))
         entries)))))
@@ -1171,15 +1167,26 @@
        (and p (processp p) (memq (process-status p) '(run open))))
       (with-connection-property
          (tramp-get-connection-process vec) "cifs-capabilities"
+       (save-match-data
        (when (tramp-smb-send-command vec "posix")
          (with-current-buffer (tramp-get-buffer vec)
            (goto-char (point-min))
-           (when (re-search-forward "Server supports CIFS capabilities" nil t)
+             (when
+                 (re-search-forward "Server supports CIFS capabilities" nil t)
              (member
               "pathnames"
               (split-string
                (buffer-substring
-                (point) (tramp-compat-line-end-position)) nil t))))))))
+                  (point) (tramp-compat-line-end-position)) nil t)))))))))
+
+(defun tramp-smb-get-stat-capability (vec)
+  "Check, whether the SMB server supports the STAT command."
+  ;; When we are not logged in yet, we return nil.
+  (if (let ((p (tramp-get-connection-process vec)))
+       (and p (processp p) (memq (process-status p) '(run open))))
+      (with-connection-property
+         (tramp-get-connection-process vec) "stat-capability"
+       (tramp-smb-send-command vec "stat ."))))
 
 
 ;; Connection functions.
@@ -1204,33 +1211,30 @@
     ;; Otherwise, we must delete the connection cache, because
     ;; capabilities migh have changed.
     (unless (processp p)
-      (unless (let ((default-directory
-                     (tramp-compat-temporary-file-directory)))
-               (executable-find tramp-smb-program))
+      (let ((default-directory (tramp-compat-temporary-file-directory))
+           (command (concat tramp-smb-program " -V")))
+
+       (unless tramp-smb-version
+         (unless (executable-find tramp-smb-program)
        (tramp-error
         vec 'file-error
         "Cannot find command %s in %s" tramp-smb-program exec-path))
+         (setq tramp-smb-version (shell-command-to-string command))
+         (tramp-message vec 6 command)
+         (tramp-message vec 6 "\n%s" tramp-smb-version)
+         (if (string-match "[ \t\n\r]+\\'" tramp-smb-version)
+             (setq tramp-smb-version
+                   (replace-match "" nil nil tramp-smb-version))))
 
-      (let* ((default-directory (tramp-compat-temporary-file-directory))
-            (smbclient-version tramp-smb-version))
-       (unless smbclient-version
-         (setq smbclient-version
-               (shell-command-to-string (concat tramp-smb-program " -V")))
-         (tramp-message vec 6 (concat tramp-smb-program " -V"))
-         (tramp-message vec 6 "\n%s" smbclient-version)
-         (if (string-match "[ \t\n\r]+\\'" smbclient-version)
-             (setq smbclient-version
-                   (replace-match "" nil nil smbclient-version))))
-       (unless
-           (string-equal
-            smbclient-version
+       (unless (string-equal
+                tramp-smb-version
             (tramp-get-connection-property
-             vec "smbclient-version" smbclient-version))
+                 vec "smbclient-version" tramp-smb-version))
          (tramp-flush-directory-property vec "")
          (tramp-flush-connection-property vec))
-       (setq tramp-smb-version
+
              (tramp-set-connection-property
-              vec "smbclient-version" smbclient-version))))
+        vec "smbclient-version" tramp-smb-version)))
 
     ;; If too much time has passed since last command was sent, look
     ;; whether there has been an error message; maybe due to




reply via email to

[Prev in Thread] Current Thread [Next in Thread]