WSL icon indicating copy to clipboard operation
WSL copied to clipboard

rename() fails with trailing slash

Open ericeil opened this issue 10 years ago • 8 comments

Tested on rs_preview build 14905:

Run the following:

#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>

int main(void)
{
    if (mkdir("dir1", 0777) != 0)
        err(1, "mkdir errno %d", errno);

    if (rename("dir1", "dir2/") != 0)
        err(1, "rename errno %d", errno);

    return 0;
}

On Linux, this succeeds. On Windows, I get the following:

a.out: rename errno 2: No such file or directory

Without the trailing slash, the rename works as expected.

This is causing a few failures in the .NET Core tests.

ericeil avatar Aug 29 '16 19:08 ericeil

@ericeil - Thanks for reporting this. I have opened a bug to track this. It should get auto-triaged.

sunilmut avatar Aug 29 '16 21:08 sunilmut

If the oldpath has a trailing slash, Bash On Windows to hangs and the lxssmanager service can not be restarted.

#include <stdlib.h>
int main () {
    return rename ("dir1/", "dir2");
}
tmontague@AMP:/mnt/c/test$ gcc rename.c
tmontague@AMP:/mnt/c/test$ mkdir dir1
tmontague@AMP:/mnt/c/test$ ls -l
total 12
-rwxrwxrwx 1 root root 8522 Sep 13 16:34 a.out
drwxrwxrwx 2 root root    0 Sep 13 16:35 dir1
-rwxrwxrwx 1 root root   70 Sep 13 16:30 rename.c
tmontague@AMP:/mnt/c/test$ ./a.out
^C

Pressing ^c does not do anything, and all open bash terminals are unresponsive.

This only occurs when running from a Windows directory (i.e., it occurs in/mnt/c, but not /).

This bug occurs when running configure on m4 during its "checking whether rename honors trailing slash on source" autoconf test. See GNU m4 installation fails on Windows 10 bash on Ubuntu.

I am using Microsoft Windows [Version 10.0.14393]

timmontague avatar Sep 14 '16 00:09 timmontague

Both issues are gone on my latest internal build. The fixes should make its way to insider builds eventually.

misenesi avatar Nov 10 '16 20:11 misenesi

This issue was fixed in Insider build 14965, please re-open if this issue is seen again.

JasonLinMS avatar Jan 13 '17 22:01 JasonLinMS

On the anniversary build this issue can cause bash to not restart. (At work I can't switch to the insider track). Rebooting does not fix the problem. Stopping the service (sc stop lxssmanager) then running bash once as administrator does fix it. Sometimes it gets stuck though on the stop and rebooting or shutdown does not correct the issue (due to windows 10 hibernating rather than truly shutting down). In this case I've found that it is necessary to "shutdown /s" to truly shutdown, then booting back up and running bash once as administrator.

bogen avatar Jan 24 '17 17:01 bogen

Bash was unresponsive for me after a bad mv with trailing slashes. I shutdown with shutdown /s and ran bash as administrator as @bogen suggested and everything works again.

aaewong avatar Feb 19 '17 01:02 aaewong

Is there some way we can get fixed versions more quickly? ref: build 14965

davidmaxwaterman avatar Apr 05 '17 08:04 davidmaxwaterman

If you want to get fixed versions more quickly, you can sign up for Windows Insider builds. Both the Slow and the Fast Insider rings get WSL updates more frequently than regular (stable) Windows.

Alternatively, this particular fix (as well as a lot of other fixes) is scheduled to ship with the Windows Creators update on April 11, less than a week from now.

aseering avatar Apr 05 '17 12:04 aseering