Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
8959851a
Commit
8959851a
authored
Dec 10, 2010
by
Ryan Hitchman
Committed by
Andrew Gerrand
Dec 10, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os: make MkdirAll work with symlinks
Fixes #1149. R=adg CC=golang-dev
https://golang.org/cl/3564041
parent
ae605268
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
10 deletions
+34
-10
src/pkg/os/os_test.go
src/pkg/os/os_test.go
+3
-4
src/pkg/os/path.go
src/pkg/os/path.go
+1
-1
src/pkg/os/path_test.go
src/pkg/os/path_test.go
+30
-5
No files found.
src/pkg/os/os_test.go
View file @
8959851a
...
...
@@ -863,13 +863,14 @@ func TestAppend(t *testing.T) {
}
func
TestStatDirWithTrailingSlash
(
t
*
testing
.
T
)
{
// Create new dir, in _
obj
so it will get
// Create new dir, in _
test
so it will get
// cleaned up by make if not by us.
path
:=
"_
obj
/_TestStatDirWithSlash_"
path
:=
"_
test
/_TestStatDirWithSlash_"
err
:=
MkdirAll
(
path
,
0777
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll %q: %s"
,
path
,
err
)
}
defer
RemoveAll
(
path
)
// Stat of path should succeed.
_
,
err
=
Stat
(
path
)
...
...
@@ -882,6 +883,4 @@ func TestStatDirWithTrailingSlash(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
"stat failed:"
,
err
)
}
RemoveAll
(
"_obj/_TestMkdirAll_"
)
}
src/pkg/os/path.go
View file @
8959851a
...
...
@@ -14,7 +14,7 @@ package os
// and returns nil.
func
MkdirAll
(
path
string
,
perm
uint32
)
Error
{
// If path exists, stop with success or error.
dir
,
err
:=
Ls
tat
(
path
)
dir
,
err
:=
S
tat
(
path
)
if
err
==
nil
{
if
dir
.
IsDirectory
()
{
return
nil
...
...
src/pkg/os/path_test.go
View file @
8959851a
...
...
@@ -7,17 +7,19 @@ package os_test
import
(
.
"os"
"testing"
"runtime"
"syscall"
)
func
TestMkdirAll
(
t
*
testing
.
T
)
{
// Create new dir, in _
obj
so it will get
// Create new dir, in _
test
so it will get
// cleaned up by make if not by us.
path
:=
"_
obj
/_TestMkdirAll_/dir/./dir2"
path
:=
"_
test
/_TestMkdirAll_/dir/./dir2"
err
:=
MkdirAll
(
path
,
0777
)
if
err
!=
nil
{
t
.
Fatalf
(
"MkdirAll %q: %s"
,
path
,
err
)
}
defer
RemoveAll
(
"_test/_TestMkdirAll_"
)
// Already exists, should succeed.
err
=
MkdirAll
(
path
,
0777
)
...
...
@@ -58,13 +60,11 @@ func TestMkdirAll(t *testing.T) {
if
perr
.
Path
!=
fpath
{
t
.
Fatalf
(
"MkdirAll %q returned wrong error path: %q not %q"
,
ffpath
,
perr
.
Path
,
fpath
)
}
RemoveAll
(
"_obj/_TestMkdirAll_"
)
}
func
TestRemoveAll
(
t
*
testing
.
T
)
{
// Work directory.
path
:=
"_
obj
/_TestRemoveAll_"
path
:=
"_
test
/_TestRemoveAll_"
fpath
:=
path
+
"/file"
dpath
:=
path
+
"/dir"
...
...
@@ -154,3 +154,28 @@ func TestRemoveAll(t *testing.T) {
t
.
Fatalf
(
"Lstat %q succeeded after RemoveAll (final)"
,
path
)
}
}
func
TestMkdirAllWithSymlink
(
t
*
testing
.
T
)
{
if
runtime
.
GOOS
==
"windows"
{
t
.
Log
(
"Skipping test: symlinks don't exist under Windows"
)
return
}
err
:=
Mkdir
(
"_test/dir"
,
0755
)
if
err
!=
nil
{
t
.
Fatal
(
`Mkdir "_test/dir":`
,
err
)
}
defer
RemoveAll
(
"_test/dir"
)
err
=
Symlink
(
"dir"
,
"_test/link"
)
if
err
!=
nil
{
t
.
Fatal
(
`Symlink "dir", "_test/link":`
,
err
)
}
defer
RemoveAll
(
"_test/link"
)
path
:=
"_test/link/foo"
err
=
MkdirAll
(
path
,
0755
)
if
err
!=
nil
{
t
.
Errorf
(
"MkdirAll %q: %s"
,
path
,
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment