mirror of
https://github.com/minio/minio.git
synced 2025-04-21 19:14:39 -04:00
posix-utils: fix path handling in windows. (#2053)
This commit is contained in:
parent
48aa5f2199
commit
cd1c2db864
@ -42,8 +42,9 @@ func isValidVolname(volname string) bool {
|
|||||||
// for all directories that mkdirAll creates. If path is already
|
// for all directories that mkdirAll creates. If path is already
|
||||||
// a directory, mkdirAll does nothing and returns nil.
|
// a directory, mkdirAll does nothing and returns nil.
|
||||||
func mkdirAll(path string, perm os.FileMode) error {
|
func mkdirAll(path string, perm os.FileMode) error {
|
||||||
|
path = preparePath(path)
|
||||||
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
|
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
|
||||||
dir, err := os.Stat(preparePath(path))
|
dir, err := os.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if dir.IsDir() {
|
if dir.IsDir() {
|
||||||
return nil
|
return nil
|
||||||
@ -78,11 +79,11 @@ func mkdirAll(path string, perm os.FileMode) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parent now exists; invoke Mkdir and use its result.
|
// Parent now exists; invoke Mkdir and use its result.
|
||||||
err = os.Mkdir(preparePath(path), perm)
|
err = os.Mkdir(path, perm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Handle arguments like "foo/." by
|
// Handle arguments like "foo/." by
|
||||||
// double-checking that directory doesn't exist.
|
// double-checking that directory doesn't exist.
|
||||||
dir, err1 := os.Lstat(preparePath(path))
|
dir, err1 := os.Lstat(path)
|
||||||
if err1 == nil && dir.IsDir() {
|
if err1 == nil && dir.IsDir() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -96,14 +97,15 @@ func mkdirAll(path string, perm os.FileMode) error {
|
|||||||
// it encounters. If the path does not exist, RemoveAll
|
// it encounters. If the path does not exist, RemoveAll
|
||||||
// returns nil (no error).
|
// returns nil (no error).
|
||||||
func removeAll(path string) error {
|
func removeAll(path string) error {
|
||||||
|
path = preparePath(path)
|
||||||
// Simple case: if Remove works, we're done.
|
// Simple case: if Remove works, we're done.
|
||||||
err := os.Remove(preparePath(path))
|
err := os.Remove(path)
|
||||||
if err == nil || os.IsNotExist(err) {
|
if err == nil || os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, is this a directory we need to recurse into?
|
// Otherwise, is this a directory we need to recurse into?
|
||||||
dir, serr := os.Lstat(preparePath(path))
|
dir, serr := os.Lstat(path)
|
||||||
if serr != nil {
|
if serr != nil {
|
||||||
if serr, ok := serr.(*os.PathError); ok && (os.IsNotExist(serr.Err) || serr.Err == syscall.ENOTDIR) {
|
if serr, ok := serr.(*os.PathError); ok && (os.IsNotExist(serr.Err) || serr.Err == syscall.ENOTDIR) {
|
||||||
return nil
|
return nil
|
||||||
@ -116,7 +118,7 @@ func removeAll(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Directory.
|
// Directory.
|
||||||
fd, err := os.Open(preparePath(path))
|
fd, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// Race. It was deleted between the Lstat and Open.
|
// Race. It was deleted between the Lstat and Open.
|
||||||
@ -152,7 +154,7 @@ func removeAll(path string) error {
|
|||||||
fd.Close()
|
fd.Close()
|
||||||
|
|
||||||
// Remove directory.
|
// Remove directory.
|
||||||
err1 := os.Remove(preparePath(path))
|
err1 := os.Remove(path)
|
||||||
if err1 == nil || os.IsNotExist(err1) {
|
if err1 == nil || os.IsNotExist(err1) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user