mirror of
https://github.com/golang/go
synced 2024-11-24 23:17:57 -07:00
os: remove read-only directories in Remove on Windows
Allows Remove to remove directory with read-only attribute in Windows Fixes #26295 (Read-only attribute in Windows doesn't prevent users to delete a directory, it is just used to know if the folder has custom icon or other custom properties)
This commit is contained in:
parent
1c05968c9a
commit
8f045d8146
@ -245,9 +245,20 @@ func Remove(name string) error {
|
|||||||
if e == nil {
|
if e == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
e1 := syscall.RemoveDirectory(p)
|
e1 := syscall.RemoveDirectory(p)
|
||||||
if e1 == nil {
|
if e1 == nil {
|
||||||
return nil
|
return nil
|
||||||
|
} else {
|
||||||
|
//Empty directories with "read-only" attribute on Windows can cause issues so we have to try with chmod to remove it
|
||||||
|
a, e2 := syscall.GetFileAttributes(p)
|
||||||
|
if e2 == nil && a&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 && IsPermission(e1) {
|
||||||
|
if fs, err := Stat(fixLongPath(name)); err == nil {
|
||||||
|
if err = Chmod(fixLongPath(name), FileMode(0200|int(fs.Mode()))); err == nil {
|
||||||
|
e1 = syscall.RemoveDirectory(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Both failed: figure out which error to return.
|
// Both failed: figure out which error to return.
|
||||||
|
Loading…
Reference in New Issue
Block a user