-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
os: Remove/RemoveAll should remove read-only folders on Windows #26295
Comments
By analogy with #9606 it seems that we should do this. |
I'm working on it |
Change https://golang.org/cl/125261 mentions this issue: |
Change https://golang.org/cl/203599 mentions this issue: |
This issue is only half fixed. As stated in the title, package main
import (
"fmt"
"io/ioutil"
"os"
)
func main() {
path := "./folder_with_icon"
fmt.Println(count_files(path))
err := os.Remove(path + "/desktop.ini")
if err != nil {
panic(err)
}
fmt.Println(count_files(path)) // works fine up to here
err = os.Remove(path)
if err != nil {
panic(err)
}
}
func count_files(path string) int {
files, _ := ioutil.ReadDir(path)
return len(files)
} As before,
|
The analogy to #9606 does not seem to hold: while Unix systems do allow read-only files to be removed from read-write directories, they do not generally allow files to be removed from within a read-only directory without first making the directory writable. That subtlety is what led us to add the |
The difference of behavior between Remove and RemoveAll is stated in the documentation
os.Remove will only attempt removal and return the error. |
@iwdgo, my point is that the proposed change here makes If folks want to argue that the behavior on Unix should be expanded to be consistent with the documentation, that's fine by me, but then this issue would not be Windows-specific. |
@bcmills The original issue was on Windows and the difference with Unix seems to start in Go1.12 as #29983 details. The comment in _at code and what follows does not seem to consider an update of permissions in RemoveAll. This test expects read-only directories to remain. It is skipped on Windows for the same reason. If this would change, an error would be returned when permission is insufficient although |
@bcmills IMHO, RemoveAll on Unix should attempt a permission update but it was not in the scope of the issue as originally filed. Such a change for Unix would seem along the line of past comments. |
That seems fine to me, but that should be a separate issue — and implementing the behavior described in this issue should probably wait for a decision on the broader (cross-platform) |
Moving to Go1.17. |
Allows Remove to remove directory with read-only attribute in Windows Fixes golang#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)
Change https://go.dev/cl/448315 mentions this issue: |
For the sake of completeness, here's the official Microsoft documentation on read-only attributes on Windows folders:
Excerpt from the linked article:
|
(CC @golang/windows) |
Looking at what other frameworks do, and there are a few that discard the readonly attribute for either files and folders:
|
What version of Go are you using (
go version
)?go version go1.10.2 windows/amd64
Does this issue reproduce with the latest release?
Untested, but I don't see any changes that would have fixed it
What operating system and processor architecture are you using (
go env
)?windows/amd64
What did you do?
folder_with_icon
is an empty folder that has had a custom icon added via Windows Explorer's interface (Properties
=>Customize
=>Change Icon...
).What did you expect to see?
folder_with_icon
should be deleted.What did you see instead?
Notes
This is similar to #9606.
Setting a custom folder icon on Windows sets the
read-only
attribute on the folder and creates adesktop.ini
file with thesystem
attribute inside the folder. Despite being read-only, the folder can be deleted both through File Explorer and byrd /s folder_with_icon
by its owner, even if the owner is not an administrator account. The above Go program will not delete the folder, even if it is run with administrator privileges.os.RemoveAll()
removes thedesktop.ini
but does not delete the folder.The text was updated successfully, but these errors were encountered: