-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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 files on Windows #9606
Comments
Code change is easy. Any objections to this idea? We will need to call out this change in the Go 1.5 release note, but BTW, once this is in, we can remove the workaround in CL 2930 and |
I object. I think there is confusion here about what Windows file "read-only" attribute does. It not just prevents from making changes to the contents of the file. It also prevents from the file to be deleted. C:\tmp\aaa>echo > a.txt C:\tmp\aaa>attrib +r a.txt C:\tmp\aaa>del a.txt C:\tmp\aaa>attrib -r a.txt C:\tmp\aaa>del a.txt C:\tmp\aaa> On linux it would be similar to: $ ls Basically you have to change the flag before you will be allowed to delete the file. Also some explanation from http://www.oreilly.com/openbook/samba/book/ch05_03.html
I don't see wining this argument, but I am trying. Alex |
You're still talking about Windows file deletion semantics, but To put it another, should the API refrain from deleting any file not Why should we have this distinction on the supposedly portable |
Your argument is "os.Remove must make every effort to delete the file". Isn't it? But, if we assume that premise, then we should do the same on every platform. For example in my example above: $ rm a/f2 should we try and change 'a' directory mode and try to delete a/f2 again? Because that is what you're effectively proposing for windows os.Remove. To me it is all about being reasonable here. The "read-only" flag is set for a reason. Lets not delete the file until we understand that reason.
I say we should leave thing as they are. We use "standard" system API. Whatever it does is most correct for general case scenario. Alex |
We can change the permission of the file itself, but we shouldn't |
In that case, let's change the documentation for os.Remove to: Remove just calls the standard os remove (delete) file to remove the file Is that acceptable to you? This is essentially your position. |
I also do not agree to this change. It's overwork. If you want, let's put makerelease_windows.go and add |
I am fine with documentation change. But I think that everyone understands that OS file / permissions might prevent you from removing file. No one complaining about inability to remove opened file on windows. Same for removing current directory. The problem is us. We assume that os package provides same behaviour everywhere. But sometimes it cannot. Alex |
Why it's overwork? When I write os.Remove(filename), I truly want it to delete the file. I don't want to write system specific code for each code, otherwise Why not just force the user to use syscall.Unlink and syscall.DeleteFile |
I think the real issue we should be discussing here (if we care), is why these files have "read-only" flag. Who set the flag and why? Perhaps, once we understand the reasoning, we can decide what to do with the issue at hand. If we care. Alex |
In generally, we have to do care for windows about file deletion. For example: when some files are opened by another applications, so the file is locked with opening file, the deletion of file should be fail. This changing spec will solve this issue. But we will get another issue. So I'm thinking we have better not do. |
Unix chmod a-w on the file itself is irrelevant for removing it; unix controls removing by directory permissions. The Windows file read-only flag is more like chattr +i (immutable) on Linux, and such a file "cannot be deleted or renamed" (see chattr(1)). I don't think os.Remove/RemoveAll should do anything extra to make the deletion succeed. What next, change ACLs to allow the delete? That road leads to madness. |
On 16 January 2015 at 12:33, mattn notifications@github.com wrote:
|
I think so. +1 |
Changing ACL is obviously out-of-question. However, I don't think windows read-only flag is equivalent to immutable For example, why should git label its pack/idx files immutable? Does git do When I use os.RemoveAll, should I remember to copy alex's Addressing this issue will not make os.Remove able to remove file currently |
On 16 January 2015 at 13:11, Minux Ma notifications@github.com wrote:
If you look in .git/objects you'll see all the files are 0222. |
There is a possibility that another problem occurs even to solve this problem. So I don't want to break/change os.Remove/RemoveAll. Let's make another function. |
On 16 January 2015 at 13:13, Andrew Gerrand adg@golang.org wrote:
And of course I mean 0444. |
On 16 January 2015 at 13:15, mattn notifications@github.com wrote:
That doesn't solve the problem. The problem is that os.Remove deletes |
On Thu, Jan 15, 2015 at 9:14 PM, Andrew Gerrand notifications@github.com
Right (assuming you meant 0444). I was arguing that the readonly flag on |
What about having a Remove() function that respects the readonly/immutable flag and a RemoveForce() that does every effort to delete it. |
If we provide two functions to do roughly the same thing, which should the If I say os.Remove(file), I really want file to be removed, so if we provide I really don't understand why someone would say os.Remove and expect I think most of uses of os.Remove is to remove temporary files. And we Anyway, we control the definition of os.Remove, and it doesn't say it will |
"Why should the programmer care" -- because the people who designed the OS thought that the distinction matters? http://msdn.microsoft.com/en-us/library/windows/desktop/aa363915(v=vs.85).aspx |
That's a weak argument. That would disallow all portable interfaces and languages which abstracted over per-CPU and per-OS differences. The whole point of having a high-level language and package like "os" is to let me do things consistently over many operating systems and architectures and knowing it'll work the same everywhere. If I wanted Windows' DeleteFile semantics, I'd use syscall.DeleteFile directly. But I don't. I want os.Remove semantics, like I'm used to everywhere else. |
No, I've made my own golang/js repo build server from scratch. Just added the work around and can finally run builds on windows with proper disk cleanup at the end :) I don't really run the server on windows except when developing it, where disk cleanup is not that important. Lucky thing that I was looking at 1.5 milestone issues for no real reason, just to find this. Notes if anyone gets this same one in the futures: I ended up using the cmd.exe work around. "del" did not work as I wanted to remove directory that had 1-N git repos inside it down the tree. The dir recursion to change the read flag is potentially heavy if you have big repos.
Ended up using that. Just make sure the folder exists or you'll get an error from |
There is an example in 3b7841b Alex |
1+ This issue makes github.com/google/codesearch unusable on Window. |
Moving to proposal process, hopefully for Go 1.7. |
+1 - This is preventing Go programs from removing directory structures created by Git (as an example), since many of the files are RO. |
@maruel, if you are still willing to cook up a CL, I'd like to see it. No rush - we won't start comitting Go 1.7 CLs until February, but if you get it queued up I'll be happy to review it sooner. |
Will look this week. |
https://go-review.googlesource.com/#/c/18235 can be reviewed once the merge window is open again. |
CL https://golang.org/cl/18235 mentions this issue. |
On Unix systems, Remove/RemoveAll will work even if the files are chmod 0600. On windows, Remove/RemoveAll will not remove a file marked as read-only. If you want to write a Go program that deletes a file, you need to take special care on windows. That's sad.
Since we determine the semantics of Remove/RemoveAll, we could make this "just work" and save our users some effort.
Discussion started here: https://go-review.googlesource.com/2930
The text was updated successfully, but these errors were encountered: