* bug#10284: "Renaming: permission denied" file-error in Windows [not found] ` <4EF6D1CE.7020101@bk.ru> @ 2011-12-25 9:39 ` Eli Zaretskii [not found] ` <E1RekZY-0003jE-FO@fencepost.gnu.org> 1 sibling, 0 replies; 9+ messages in thread From: Eli Zaretskii @ 2011-12-25 9:39 UTC (permalink / raw) To: LynX; +Cc: 10284, eggert [Redirected to the bug tracker, to keep the entire discussion archived.] > Date: Sun, 25 Dec 2011 09:33:34 +0200 > From: LynX <_LynX@bk.ru> > CC: emacs-devel@gnu.org, eggert@cs.ucla.edu > > I've opened a bug report here: > > 10284: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10284 Thanks. > result = rename (temp, newname); > > if (result < 0 > - && errno == EEXIST > - && _chmod (newname, 0666) == 0 > - && _unlink (newname) == 0) > - result = rename (temp, newname); > + && errno == EEXIST) > + { > + if (_chmod (newname, 0666) != 0) > + return result; > + if (_unlink (newname) != 0) > + return result; > + result = rename (temp, newname); > + } > + > + /* The implementation of `rename' on Windows does not return > + errno = EXDEV when you are moving a directory to a different > + storage device (ex. logical disk). It returns EACCES > + instead. So here we handle such situations and return EXDEV. */ > + > + if (result < 0 > + && errno == EACCES > + && newname_dev != oldname_dev) > + errno = EXDEV; This first removes the target, and only then compares the device numbers. Wouldn't it be better to do it the other way around, at least when the target is a directory? That way, the target is left intact if the caller doesn't want to copy over the target, and also the filesystem is left in the same state as on Posix hosts in this case, i.e. the contract of `rename' is preserved on all systems. Thanks for working on this. ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <E1RekZY-0003jE-FO@fencepost.gnu.org>]
* bug#10284: "Renaming: permission denied" file-error in Windows [not found] ` <E1RekZY-0003jE-FO@fencepost.gnu.org> @ 2011-12-28 19:53 ` LynX 2011-12-29 6:18 ` Eli Zaretskii 0 siblings, 1 reply; 9+ messages in thread From: LynX @ 2011-12-28 19:53 UTC (permalink / raw) To: 10284 Dear Eli, Thank you for your response. I just want to double check that I understood you right. > This first removes the target, and only then compares the device > numbers. Wouldn't it be better to do it the other way around, at > least when the target is a directory? That way, the target is left > intact if the caller doesn't want to copy over the target, and also > the filesystem is left in the same state as on Posix hosts in this > case, i.e. the contract of `rename' is preserved on all systems. You mean that before setting errno to EXDEV we also need to check that target is a directory (since files are moved correctly)? Regards, LX 25.12.2011 11:40, Eli Zaretskii пишет: >> Date: Sun, 25 Dec 2011 09:33:34 +0200 >> From: LynX<_LynX@bk.ru> >> Cc: eggert@cs.ucla.edu, emacs-devel@gnu.org >> >> Dear Eli, >> >> I've opened a bug report here: >> >> 10284: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10284 >> >> Here is the patch for this issue (it is done for the latest source >> package emacs-23.3b.tar.bz2): > > I've redirected this discussion to the bug tracker, > 10284@debbugs.gnu.org. > > Please respond there, not here. > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#10284: "Renaming: permission denied" file-error in Windows 2011-12-28 19:53 ` LynX @ 2011-12-29 6:18 ` Eli Zaretskii 2011-12-30 19:31 ` LynX 0 siblings, 1 reply; 9+ messages in thread From: Eli Zaretskii @ 2011-12-29 6:18 UTC (permalink / raw) To: LynX; +Cc: 10284 > Date: Wed, 28 Dec 2011 21:53:39 +0200 > From: LynX <_LynX@bk.ru> > > > This first removes the target, and only then compares the device > > numbers. Wouldn't it be better to do it the other way around, at > > least when the target is a directory? That way, the target is left > > intact if the caller doesn't want to copy over the target, and also > > the filesystem is left in the same state as on Posix hosts in this > > case, i.e. the contract of `rename' is preserved on all systems. > > You mean that before setting errno to EXDEV we also need to check that > target is a directory (since files are moved correctly)? Yes, but that's not the important part of my comment above. The important part is to move the check for different devices _before_ the call to _unlink which removes the target file/directory if it exists. In other words, we should fail and report EXDEV without risking the removal of the target, and let the caller decide what to do with the failure. (If the caller decides to leave things unchanged, it will not be The Right Thing for us to remove the target.) ^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#10284: "Renaming: permission denied" file-error in Windows 2011-12-29 6:18 ` Eli Zaretskii @ 2011-12-30 19:31 ` LynX 2011-12-30 20:23 ` Eli Zaretskii 0 siblings, 1 reply; 9+ messages in thread From: LynX @ 2011-12-30 19:31 UTC (permalink / raw) To: 10284 [-- Attachment #1: Type: text/plain, Size: 3120 bytes --] Hello Eli, Thank you for the clarification. Please review this patch. --- w32.c.orig 2011-11-26 05:20:20.000000000 +0200 +++ w32.c 2011-12-30 21:22:56.734375000 +0200 @@ -2857,6 +2857,8 @@ { BOOL result; char temp[MAX_PATH]; + int newname_dev; + int oldname_dev; /* MoveFile on Windows 95 doesn't correctly change the short file name alias in a number of circumstances (it is not easy to predict when @@ -2873,6 +2875,9 @@ strcpy (temp, map_w32_filename (oldname, NULL)); + /* volume_info is set indirectly by map_w32_filename */ + oldname_dev = volume_info.serialnum; + if (os_subtype == OS_WIN95) { char * o; @@ -2916,13 +2921,36 @@ all the permutations of shared or subst'd drives, etc.) */ newname = map_w32_filename (newname, NULL); + + /* volume_info is set indirectly by map_w32_filename */ + newname_dev = volume_info.serialnum; + result = rename (temp, newname); - if (result < 0 - && errno == EEXIST - && _chmod (newname, 0666) == 0 - && _unlink (newname) == 0) - result = rename (temp, newname); + if (result < 0) + { + + if (errno == EACCES + && newname_dev != oldname_dev) + { + /* The implementation of `rename' on Windows does not return + errno = EXDEV when you are moving a directory to a different + storage device (ex. logical disk). It returns EACCES + instead. So here we handle such situations and return EXDEV. */ + DWORD attributes; + if ((attributes = GetFileAttributes(temp)) != -1 + && attributes & FILE_ATTRIBUTE_DIRECTORY) + errno = EXDEV; + } + else if (errno == EEXIST) + { + if (_chmod (newname, 0666) != 0) + return result; + if (_unlink (newname) != 0) + return result; + result = rename (temp, newname); + } + } return result; } I've added check whether it is a directory or not, and moved all this before the unlink operation. Regards, LX 29.12.2011 8:18, Eli Zaretskii пишет: >> Date: Wed, 28 Dec 2011 21:53:39 +0200 >> From: LynX<_LynX@bk.ru> >> >> > This first removes the target, and only then compares the device >> > numbers. Wouldn't it be better to do it the other way around, at >> > least when the target is a directory? That way, the target is left >> > intact if the caller doesn't want to copy over the target, and also >> > the filesystem is left in the same state as on Posix hosts in this >> > case, i.e. the contract of `rename' is preserved on all systems. >> >> You mean that before setting errno to EXDEV we also need to check that >> target is a directory (since files are moved correctly)? > > Yes, but that's not the important part of my comment above. The > important part is to move the check for different devices _before_ the > call to _unlink which removes the target file/directory if it exists. > In other words, we should fail and report EXDEV without risking the > removal of the target, and let the caller decide what to do with the > failure. (If the caller decides to leave things unchanged, it will > not be The Right Thing for us to remove the target.) > > [-- Attachment #2: w32.c.patch --] [-- Type: text/plain, Size: 1748 bytes --] --- w32.c.orig 2011-11-26 05:20:20.000000000 +0200 +++ w32.c 2011-12-30 21:22:56.734375000 +0200 @@ -2857,6 +2857,8 @@ { BOOL result; char temp[MAX_PATH]; + int newname_dev; + int oldname_dev; /* MoveFile on Windows 95 doesn't correctly change the short file name alias in a number of circumstances (it is not easy to predict when @@ -2873,6 +2875,9 @@ strcpy (temp, map_w32_filename (oldname, NULL)); + /* volume_info is set indirectly by map_w32_filename */ + oldname_dev = volume_info.serialnum; + if (os_subtype == OS_WIN95) { char * o; @@ -2916,13 +2921,36 @@ all the permutations of shared or subst'd drives, etc.) */ newname = map_w32_filename (newname, NULL); + + /* volume_info is set indirectly by map_w32_filename */ + newname_dev = volume_info.serialnum; + result = rename (temp, newname); - if (result < 0 - && errno == EEXIST - && _chmod (newname, 0666) == 0 - && _unlink (newname) == 0) - result = rename (temp, newname); + if (result < 0) + { + + if (errno == EACCES + && newname_dev != oldname_dev) + { + /* The implementation of `rename' on Windows does not return + errno = EXDEV when you are moving a directory to a different + storage device (ex. logical disk). It returns EACCES + instead. So here we handle such situations and return EXDEV. */ + DWORD attributes; + if ((attributes = GetFileAttributes(temp)) != -1 + && attributes & FILE_ATTRIBUTE_DIRECTORY) + errno = EXDEV; + } + else if (errno == EEXIST) + { + if (_chmod (newname, 0666) != 0) + return result; + if (_unlink (newname) != 0) + return result; + result = rename (temp, newname); + } + } return result; } ^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#10284: "Renaming: permission denied" file-error in Windows 2011-12-30 19:31 ` LynX @ 2011-12-30 20:23 ` Eli Zaretskii 2011-12-30 21:35 ` LynX 0 siblings, 1 reply; 9+ messages in thread From: Eli Zaretskii @ 2011-12-30 20:23 UTC (permalink / raw) To: LynX; +Cc: 10284 > Date: Fri, 30 Dec 2011 21:31:26 +0200 > From: LynX <_LynX@bk.ru> > > Please review this patch. Looks good, thanks. Did you test it with UNC filenames, btw? ^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#10284: "Renaming: permission denied" file-error in Windows 2011-12-30 20:23 ` Eli Zaretskii @ 2011-12-30 21:35 ` LynX 2011-12-31 6:48 ` Eli Zaretskii 0 siblings, 1 reply; 9+ messages in thread From: LynX @ 2011-12-30 21:35 UTC (permalink / raw) To: 10284 Dear Eli, > Did you test it with UNC filenames, btw? Nope, but I tried it now with Cyrillic names and it worked. If you asked this because of GetFileAttributes, I think that it is mapped somewhere to GetFileAttributesW (since when I tried GetFileAttributesA with Cyrillic names it failed :). Regards, LX ^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#10284: "Renaming: permission denied" file-error in Windows 2011-12-30 21:35 ` LynX @ 2011-12-31 6:48 ` Eli Zaretskii 2012-01-06 20:46 ` LynX 0 siblings, 1 reply; 9+ messages in thread From: Eli Zaretskii @ 2011-12-31 6:48 UTC (permalink / raw) To: LynX; +Cc: 10284 > Date: Fri, 30 Dec 2011 23:35:38 +0200 > From: LynX <_LynX@bk.ru> > > > Did you test it with UNC filenames, btw? > > Nope, but I tried it now with Cyrillic names and it worked. Thanks. But "UNC" doesn't mean "Unicode", it means "Universal Naming Convention", and refers to the \\server\share\foo style of file names on remote machines. > If you asked this because of GetFileAttributes, I think that it is > mapped somewhere to GetFileAttributesW (since when I tried > GetFileAttributesA with Cyrillic names it failed :). No, I was thinking about what volume_info.serialnum will give you for UNC filenames. ^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#10284: "Renaming: permission denied" file-error in Windows 2011-12-31 6:48 ` Eli Zaretskii @ 2012-01-06 20:46 ` LynX 2012-01-07 9:54 ` Eli Zaretskii 0 siblings, 1 reply; 9+ messages in thread From: LynX @ 2012-01-06 20:46 UTC (permalink / raw) To: 10284 Dear Eli, > Thanks. But "UNC" doesn't mean "Unicode", it means "Universal Naming > Convention", and refers to the \\server\share\foo style of file names > on remote machines. Sorry now I got it :) Today I tested it and it worked fine. I was able to move non-empty directory to remote shared directory (\\remote_host\shared) and then moved it back successfuly. Regards, LX ^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#10284: "Renaming: permission denied" file-error in Windows 2012-01-06 20:46 ` LynX @ 2012-01-07 9:54 ` Eli Zaretskii 0 siblings, 0 replies; 9+ messages in thread From: Eli Zaretskii @ 2012-01-07 9:54 UTC (permalink / raw) To: LynX; +Cc: 10284-done > Date: Fri, 06 Jan 2012 22:46:00 +0200 > From: LynX <_LynX@bk.ru> > > > Thanks. But "UNC" doesn't mean "Unicode", it means "Universal Naming > > Convention", and refers to the \\server\share\foo style of file names > > on remote machines. > > Sorry now I got it :) > > Today I tested it and it worked fine. I was able to move non-empty > directory to remote shared directory (\\remote_host\shared) and then > moved it back successfuly. Thanks. I committed the changes for you (as trunk revision 106818), and I'm closing this bug. Note that this patch is as much as we can accept from you without legal papers, so if you want to continue contributing to Emacs, I encourage you to sign legal papers that assign copyright for your changes to the FSF. Thanks again for working on this. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-01-07 9:54 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <4EE3F66D.2050003@bk.ru> [not found] ` <83vcpnllo3.fsf@gnu.org> [not found] ` <4EE46AA1.9010700@cs.ucla.edu> [not found] ` <E1RZisW-0000Ok-0C@fencepost.gnu.org> [not found] ` <4EE504C3.3090701@bk.ru> [not found] ` <83obvfkmt6.fsf@gnu.org> [not found] ` <4EE5245E.3090803@bk.ru> [not found] ` <83liqilrs0.fsf@gnu.org> [not found] ` <4EF6D1CE.7020101@bk.ru> 2011-12-25 9:39 ` bug#10284: "Renaming: permission denied" file-error in Windows Eli Zaretskii [not found] ` <E1RekZY-0003jE-FO@fencepost.gnu.org> 2011-12-28 19:53 ` LynX 2011-12-29 6:18 ` Eli Zaretskii 2011-12-30 19:31 ` LynX 2011-12-30 20:23 ` Eli Zaretskii 2011-12-30 21:35 ` LynX 2011-12-31 6:48 ` Eli Zaretskii 2012-01-06 20:46 ` LynX 2012-01-07 9:54 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).