Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MkdirAll() returns unhelpful error message if the parent directory is / #1637

Closed
msolo opened this issue Mar 23, 2011 · 2 comments
Closed

MkdirAll() returns unhelpful error message if the parent directory is / #1637

msolo opened this issue Mar 23, 2011 · 2 comments

Comments

@msolo
Copy link
Contributor

msolo commented Mar 23, 2011

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
1. os.MkdirAll("/nonexistant", 0755)
2.
3.

What is the expected output?
[mike]voltron:~> ./mkdir_test 
mkdir /zk: permission denied

What do you see instead?
[mike]voltron:~> ./mkdir_test 
mkdir : no such file or directory

Which operating system are you using?
Linux.


Here's the fix:


diff -r 9add7892ac1d src/pkg/os/path.go
--- a/src/pkg/os/path.go    Tue Mar 22 11:52:41 2011 -0700
+++ b/src/pkg/os/path.go    Wed Mar 23 14:34:09 2011 -0700
@@ -33,7 +33,7 @@
        j--
    }
 
-   if j > 0 {
+   if j > 1 {
        // Create parent
        err = MkdirAll(path[0:j-1], perm)
        if err != nil {
diff -r 9add7892ac1d src/pkg/os/path_test.go
--- a/src/pkg/os/path_test.go   Tue Mar 22 11:52:41 2011 -0700
+++ b/src/pkg/os/path_test.go   Wed Mar 23 14:34:09 2011 -0700
@@ -179,3 +179,22 @@
        t.Errorf("MkdirAll %q: %s", path, err)
    }
 }
+
+func TestMkdirAllAtSlash(t *testing.T) {
+   if runtime.GOOS == "windows" {
+       t.Log("Skipping test: does windows have /?")
+       return
+   }
+
+   err := MkdirAll("/_test/dir", 0755)
+   if err != nil {
+       pathErr, ok := err.(*PathError)
+       // common for users not to be able to write to /
+       // previously reported erroneously as ENOENT
+       if ok && pathErr.Error == EACCES {
+           return
+       }
+       t.Fatalf(`MkdirAll "/_test/dir": %v`, err)
+   }
+   defer RemoveAll("/_test/dir")
+}
@adg
Copy link
Contributor

adg commented Mar 24, 2011

Comment 1:

If you like, you can submit this fix yourself:
  http://golang.org/doc/contribute.html
Otherwise, I can submit it. Let me know.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Apr 4, 2011

Comment 2:

This issue was closed by revision 492039a.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants