From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?=C3=93scar?= Fuentes Newsgroups: gmane.emacs.bugs Subject: bug#10733: 24.0.93; w32 file truncation Date: Tue, 07 Feb 2012 06:22:12 +0100 Message-ID: <877gzz43qz.fsf@wanadoo.es> References: <20120205.143400.416428493.Takaaki.Ota@am.sony.com> <20120205.161623.484163522.Takaaki.Ota@am.sony.com> <83zkcwbo7t.fsf@gnu.org> <874nv45y9f.fsf@wanadoo.es> <87zkcw3pjf.fsf@wanadoo.es> <83vcnjc1yj.fsf@gnu.org> <87r4y74zew.fsf@wanadoo.es> <83sjinbyez.fsf@gnu.org> <87fwen4k6s.fsf@wanadoo.es> <83ipjjb89i.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1328592196 13836 80.91.229.3 (7 Feb 2012 05:23:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Feb 2012 05:23:16 +0000 (UTC) Cc: lekktu@gmail.com, Takaaki.Ota@am.sony.com, 10733@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Feb 07 06:23:15 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RudWM-0007bh-QL for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Feb 2012 06:23:15 +0100 Original-Received: from localhost ([::1]:41917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RudWM-0003S3-2Q for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Feb 2012 00:23:14 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:35410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RudWJ-0003Ry-3A for bug-gnu-emacs@gnu.org; Tue, 07 Feb 2012 00:23:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RudWH-0000GV-QI for bug-gnu-emacs@gnu.org; Tue, 07 Feb 2012 00:23:11 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RudWH-0000GR-OV for bug-gnu-emacs@gnu.org; Tue, 07 Feb 2012 00:23:09 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1RudX9-0007A2-42 for bug-gnu-emacs@gnu.org; Tue, 07 Feb 2012 00:24:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C3=93scar?= Fuentes Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Feb 2012 05:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10733-submit@debbugs.gnu.org id=B10733.132859224227523 (code B ref 10733); Tue, 07 Feb 2012 05:24:02 +0000 Original-Received: (at 10733) by debbugs.gnu.org; 7 Feb 2012 05:24:02 +0000 Original-Received: from localhost ([127.0.0.1]:58041 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RudX7-00079n-1v for submit@debbugs.gnu.org; Tue, 07 Feb 2012 00:24:01 -0500 Original-Received: from impaqm1.telefonica.net ([213.4.138.17]:2417 helo=telefonica.net) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RudX2-00079X-5A for 10733@debbugs.gnu.org; Tue, 07 Feb 2012 00:23:59 -0500 Original-Received: from IMPmailhost2.adm.correo ([10.20.102.39]) by IMPaqm1.telefonica.net with bizsmtp id WtMw1i00n0r0BT63MtNEWL; Tue, 07 Feb 2012 06:22:14 +0100 Original-Received: from qcore ([88.11.106.32]) by IMPmailhost2.adm.correo with BIZ IMP id WtND1i0010hxhHC1itNDNH; Tue, 07 Feb 2012 06:22:14 +0100 X-Brightmail-Tracker: AAAAAA== X-original-sender: 981711563@telefonica.net In-Reply-To: <83ipjjb89i.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 07 Feb 2012 06:02:49 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:56623 Archived-At: Eli Zaretskii writes: >> Maybe it can be integrated in the >> >> if (!(NILP(Vw32_get_true_file_attributes) ... >> >> hence reusing the calls to CreateFile and GetFileInformationByHandle and >> shortening the patch, but as I don't know what >> Vw32_get_true_file_attributes does, preferread to follow the safe way. > > You did right: w32-get-true-file-attributes can be set by the user to > nil, if she wants her file ops faster. I was thinking on something like diff --git a/src/w32.c b/src/w32.c index 3d3d334..418be63 100644 --- a/src/w32.c +++ b/src/w32.c @@ -3447,8 +3447,12 @@ stat (const char * path, struct stat * buf) } } - if (!(NILP (Vw32_get_true_file_attributes) - || (EQ (Vw32_get_true_file_attributes, Qlocal) && is_slow_fs (name))) + buf->st_size = 0; + + if ((!(NILP (Vw32_get_true_file_attributes) + || (EQ (Vw32_get_true_file_attributes, Qlocal) && is_slow_fs (name))) + || ((wfd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && + (wfd.dwReserved0 == IO_REPARSE_TAG_SYMLINK))) /* No access rights required to get info. */ && (fh = CreateFile (name, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL)) @@ -3461,6 +3465,9 @@ stat (const char * path, struct stat * buf) if (GetFileInformationByHandle (fh, &info)) { + buf->st_size = info.nFileSizeHigh; + buf->st_size <<= 32; + buf->st_size += info.nFileSizeLow; buf->st_nlink = info.nNumberOfLinks; /* Might as well use file index to fake inode values, but this is not guaranteed to be unique unless we keep a handle open @@ -3535,9 +3542,12 @@ stat (const char * path, struct stat * buf) buf->st_dev = volume_info.serialnum; buf->st_rdev = volume_info.serialnum; - buf->st_size = wfd.nFileSizeHigh; - buf->st_size <<= 32; - buf->st_size += wfd.nFileSizeLow; + if (!buf->st_size) + { + buf->st_size = wfd.nFileSizeHigh; + buf->st_size <<= 32; + buf->st_size += wfd.nFileSizeLow; + } /* Convert timestamps to Unix format. */ buf->st_mtime = convert_time (wfd.ftLastWriteTime); That is not as robust, though, because if GetFileInformationByHandle fails the function does not return with an error code. >> And the fix is just for the size. Don't know if there are other >> attributes suffer from the same problem. Possibly the right thing is to >> do what MSVCRT does: >> >> if is-symlink? >> use fstat >> fi > > Since fstat is also reimplemented, I'd rather do what it does inline. > > For that, we need to know which other attributes are reported > different. Or maybe just test for the reparse point up front and do > all the work for the target instead. Since Emacs' fstat reimplementation is based on GetFileInformationByHandle, and that the handle points to the linked file (CreateFile follows the link unless told otherwise), we should be safe delegating all work to `fstat' when a symlink is detected on `stat' (the executable bit must be setted on `stat', but that's no problem.)