From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Toru TSUNEYOSHI Newsgroups: gmane.emacs.devel Subject: Re: ange-ftp-file-size Date: Fri, 16 Oct 2009 13:31:38 +0900 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Fri_Oct_16_13_31_38_2009_716)--" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1255667553 13115 80.91.229.12 (16 Oct 2009 04:32:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 16 Oct 2009 04:32:33 +0000 (UTC) Cc: emacs-devel@gnu.org To: monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 16 06:32:25 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MyeUL-0003ZL-C8 for ged-emacs-devel@m.gmane.org; Fri, 16 Oct 2009 06:32:25 +0200 Original-Received: from localhost ([127.0.0.1]:54436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MyeUK-0005LL-TF for ged-emacs-devel@m.gmane.org; Fri, 16 Oct 2009 00:32:24 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MyeUF-0005KX-30 for emacs-devel@gnu.org; Fri, 16 Oct 2009 00:32:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MyeUA-0005Hv-AW for emacs-devel@gnu.org; Fri, 16 Oct 2009 00:32:18 -0400 Original-Received: from [199.232.76.173] (port=43866 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MyeU9-0005HV-TW for emacs-devel@gnu.org; Fri, 16 Oct 2009 00:32:13 -0400 Original-Received: from blu0-omc4-s24.blu0.hotmail.com ([65.55.111.163]:12161) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MyeU9-00070W-Ji for emacs-devel@gnu.org; Fri, 16 Oct 2009 00:32:13 -0400 Original-Received: from BLU0-SMTP98 ([65.55.111.135]) by blu0-omc4-s24.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 15 Oct 2009 21:32:12 -0700 X-Originating-IP: [124.155.30.210] X-Originating-Email: [t_tuneyosi@hotmail.com] Original-Received: from localhost ([124.155.30.210]) by BLU0-SMTP98.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 15 Oct 2009 21:32:12 -0700 In-Reply-To: X-Mailer: Mew version 6.2 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) X-OriginalArrivalTime: 16 Oct 2009 04:32:12.0228 (UTC) FILETIME=[A1637840:01CA4E19] X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:116177 Archived-At: ----Next_Part(Fri_Oct_16_13_31_38_2009_716)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Thank you for your replying. I revised the code on your advice, and made a patch of ange-ftp.el on Emacs 23.1.1. Would you like to check it? BTW, about save-match-data, I used it because of inhibiting changing old match data. Using it is wrong (as the style) ? ----Next_Part(Fri_Oct_16_13_31_38_2009_716)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ange-ftp.el.diff" --- ange-ftp.el.orig Sun Jun 21 13:37:58 2009 +++ ange-ftp.el Fri Oct 16 11:45:55 2009 @@ -2338,7 +2338,7 @@ ;; Second argument is the remote name ((or (memq cmd0 '(append put chmod)) - (and (eq cmd0 'quote) (string= cmd1 "mdtm"))) + (and (eq cmd0 'quote) (string-match-p "^\\(mdtm\\|size\\)$" cmd1))) (setq cmd2 (funcall fix-name-func cmd2))) ;; Both arguments are remote names ((eq cmd0 'rename) @@ -3455,7 +3455,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 @@ -3557,6 +3557,32 @@ (or (zerop (car file-mdtm)) (<= (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. ----Next_Part(Fri_Oct_16_13_31_38_2009_716)----