emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs/lisp ChangeLog net/ange-ftp.el


From: Stefan Monnier
Subject: [Emacs-diffs] emacs/lisp ChangeLog net/ange-ftp.el
Date: Fri, 16 Oct 2009 15:20:59 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Stefan Monnier <monnier>        09/10/16 15:20:58

Modified files:
        lisp           : ChangeLog 
        lisp/net       : ange-ftp.el 

Log message:
        (ange-ftp-send-cmd): Handle `size' like `mdtm'.
        (ange-ftp-file-size): New function.
        (ange-ftp-file-attributes): Use it.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/ChangeLog?cvsroot=emacs&r1=1.16438&r2=1.16439
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/net/ange-ftp.el?cvsroot=emacs&r1=1.112&r2=1.113

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.16438
retrieving revision 1.16439
diff -u -b -r1.16438 -r1.16439
--- ChangeLog   16 Oct 2009 14:36:13 -0000      1.16438
+++ ChangeLog   16 Oct 2009 15:20:51 -0000      1.16439
@@ -1,3 +1,9 @@
+2009-10-16  Toru TSUNEYOSHI  <address@hidden>
+
+       * net/ange-ftp.el (ange-ftp-send-cmd): Handle `size' like `mdtm'.
+       (ange-ftp-file-size): New function.
+       (ange-ftp-file-attributes): Use it.
+
 2009-10-16  Michael Albinus  <address@hidden>
 
        * net/tramp-smb.el (tramp-smb-version): New defvar.

Index: net/ange-ftp.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/ange-ftp.el,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -b -r1.112 -r1.113
--- net/ange-ftp.el     2 Oct 2009 13:20:14 -0000       1.112
+++ net/ange-ftp.el     16 Oct 2009 15:20:58 -0000      1.113
@@ -2332,7 +2332,7 @@
 
      ;; Second argument is the remote name
      ((or (memq cmd0 '(append put chmod))
-          (and (eq cmd0 'quote) (string= cmd1 "mdtm")))
+          (and (eq cmd0 'quote) (member cmd1 '("mdtm" "size"))))
       (setq cmd2 (funcall fix-name-func cmd2)))
      ;; Both arguments are remote names
      ((eq cmd0 'rename)
@@ -2971,6 +2971,8 @@
 
 (defun ange-ftp-set-binary-mode (host user)
   "Tell the FTP process for the given HOST & USER to switch to binary mode."
+  ;; FIXME: We should keep track of the current mode, so as to avoid
+  ;; unnecessary roundtrips.
   (let ((result (ange-ftp-send-cmd host user '(type "binary"))))
     (if (not (car result))
        (ange-ftp-error host user (concat "BINARY failed: " (cdr result)))
@@ -2981,6 +2983,8 @@
 
 (defun ange-ftp-set-ascii-mode (host user)
   "Tell the FTP process for the given HOST & USER to switch to ASCII mode."
+  ;; FIXME: We should keep track of the current mode, so as to avoid
+  ;; unnecessary roundtrips.
   (let ((result (ange-ftp-send-cmd host user '(type "ascii"))))
     (if (not (car result))
        (ange-ftp-error host user (concat "ASCII failed: " (cdr result)))
@@ -3449,7 +3453,7 @@
                      '(0 0)            ;4 atime
                      (ange-ftp-file-modtime file) ;5 mtime
                      '(0 0)            ;6 ctime
-                     -1                ;7 size
+                     (ange-ftp-file-size file) ;7 size
                      (concat (if (stringp dirp) "l" (if dirp "d" "-"))
                              "?????????") ;8 mode
                      nil               ;9 gid weird
@@ -3552,6 +3556,32 @@
               (<= (float-time file-mdtm) (float-time buf-mdtm))))
       (ange-ftp-real-verify-visited-file-modtime buf))))
 
+(defun ange-ftp-file-size (file &optional ascii-mode)
+  "Return the size of remote file FILE. Return -1 if can't get it.
+If ascii-mode is non-nil, return the size with the extra octets that
+need to be inserted, one at the end of each line, to provide correct
+end-of-line semantics for a transfer using TYPE=A. The default is nil,
+so return the size on the remote host exactly. See RFC 3659."
+  (let* ((parsed (ange-ftp-ftp-name file))
+        (host (nth 0 parsed))
+        (user (nth 1 parsed))
+        (name (ange-ftp-quote-string (nth 2 parsed)))
+        ;; At least one FTP server (wu-ftpd) can return a "226
+        ;; Transfer complete" before the "213 SIZE".  Let's skip
+        ;; that.
+        (ange-ftp-skip-msgs (concat ange-ftp-skip-msgs "\\|^226"))
+        (res (prog2
+                 (unless ascii-mode
+                   (ange-ftp-set-binary-mode host user))
+                 (ange-ftp-send-cmd host user (list 'quote "size" name))
+               (unless ascii-mode
+                 (ange-ftp-set-ascii-mode host user))))
+        (line (cdr res)))
+    (if (string-match "^213 \\([0-9]+\\)$" line)
+       (string-to-number (match-string 1 line))
+      -1)))
+
+
 ;;;; ------------------------------------------------------------
 ;;;; File copying support... totally re-written 6/24/92.
 ;;;; ------------------------------------------------------------




reply via email to

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