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: Sat, 17 Oct 2009 11:21:36 +0900 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Oct_17_11_21_36_2009_269)--" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1255746139 14774 80.91.229.12 (17 Oct 2009 02:22:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Oct 2009 02:22:19 +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 Sat Oct 17 04:22:09 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 1Myyvo-0003jl-HN for ged-emacs-devel@m.gmane.org; Sat, 17 Oct 2009 04:22:08 +0200 Original-Received: from localhost ([127.0.0.1]:60368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Myyvn-0003Th-MO for ged-emacs-devel@m.gmane.org; Fri, 16 Oct 2009 22:22:07 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Myyvg-0003Ru-Pz for emacs-devel@gnu.org; Fri, 16 Oct 2009 22:22:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Myyvb-0003RK-2y for emacs-devel@gnu.org; Fri, 16 Oct 2009 22:21:59 -0400 Original-Received: from [199.232.76.173] (port=37520 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Myyva-0003RH-Vw for emacs-devel@gnu.org; Fri, 16 Oct 2009 22:21:55 -0400 Original-Received: from blu0-omc4-s25.blu0.hotmail.com ([65.55.111.164]:40730) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Myyva-0005rW-Lb for emacs-devel@gnu.org; Fri, 16 Oct 2009 22:21:54 -0400 Original-Received: from BLU0-SMTP51 ([65.55.111.135]) by blu0-omc4-s25.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 16 Oct 2009 19:21:54 -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-SMTP51.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Fri, 16 Oct 2009 19:21:53 -0700 In-Reply-To: X-Mailer: Mew version 6.2 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) X-OriginalArrivalTime: 17 Oct 2009 02:21:53.0431 (UTC) FILETIME=[976F7A70:01CA4ED0] 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:116192 Archived-At: ----Next_Part(Sat_Oct_17_11_21_36_2009_269)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Thank you for your checking. >> BTW, about save-match-data, I used it because of inhibiting changing old >> match data. Using it is wrong (as the style)? > > save-match-data should only be used where it is really needed, not > defensively: 99% of the code may destroy the match-date (and could thus > use save-match-data defensively), whereas less than 1% of the code needs > the match-data to be saved. > I understand you. I will be carefull about using `save-match-data' from now on. >> - (and (eq cmd0 'quote) (string= cmd1 "mdtm"))) >> + (and (eq cmd0 'quote) (string-match-p "^\\(mdtm\\|size\\)$" cmd1))) > > I used (member cmd1 '("mdtm" "size")) instead. The regexp equivalent > would be "\\`\\(mdtm\\|size\\)\\'". > I also think it is better. >> + (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)))) > > Now that I look at it: isn't it problematic to set the mode to `ascii' > here? If the mode was binary before and we call it with ascii-mode=nil, > we end up switching to ascii mode unwittingly, don't we? > I read the code of `ange-ftp.el'. The follows is written... In comments: By default ange-ftp transfers files in ASCII mode. In code: (defun ange-ftp-... ... (unwind-protect (progn ... (if binary (ange-ftp-set-binary-mode host user)) ...) (if binary (ange-ftp-set-ascii-mode host user))) ...) So, I understood that `ASCII mode' is basic mode. I wrote after the style. (In my former patch, I should have used `unwind-protect'.) But, as you wrote, there is no guarantee that the mode is always ascii. So, I wrote the mode changing clearly. > > Stefan > Would you like to check my patch again ? ----Next_Part(Sat_Oct_17_11_21_36_2009_269)-- 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 Sat Oct 17 11:06:58 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) (member cmd1 '("mdtm" "size")))) (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,35 @@ (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 line) + (unwind-protect + (progn + (if ascii-mode + (ange-ftp-set-ascii-mode host user) + (ange-ftp-set-binary-mode host user)) + (setq res (ange-ftp-send-cmd host user (list 'quote "size" name)) + line (cdr res)) + (if (string-match "^213 \\([0-9]+\\)$" line) + (string-to-number (match-string 1 line)) + -1)) + (unless ascii-mode + (ange-ftp-set-ascii-mode host user))))) + ;;;; ------------------------------------------------------------ ;;;; File copying support... totally re-written 6/24/92. ----Next_Part(Sat_Oct_17_11_21_36_2009_269)----