-
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
syscall, os: opening hidden file for write access on Windows gives ACCESS_DENIED_ERROR #25923
Comments
Someone on the gophers slack confirmed having the same result under windows 7 with my code. So either my code is wrong, or there really is an issue. |
Thank you for the report @FabienTregan! I'll page some some wizards /cc @alexbrainman @ianlancetaylor |
trying to investigate the problem with people on gophers' slack,
But the flags to File.Open do not seem to contain a bit for visibility. |
What happens with the C |
@ianlancetaylor I've not been writting any C for at least 15 years, but made this test :
It writes |
It seems that fopen on windows calls CreateFile, which documentation says :
|
@FabienTregan Thanks, we also call It looks like the use of |
I think others suggest you use syscall.CreateFile directly in your program as you see fit.
Sure, we, probably, could do that. I changed: diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.goindex 5cfdb76e2b..d46ce1a0c4 100644
--- a/src/syscall/syscall_windows.go
+++ b/src/syscall/syscall_windows.go
@@ -286,7 +286,7 @@ func Open(path string, mode int, perm uint32) (fd Handle, err error) {
default:
createmode = OPEN_EXISTING
}
- h, e := CreateFile(pathp, access, sharemode, sa, createmode, FILE_ATTRIBUTE_NORMAL, 0)
+ h, e := CreateFile(pathp, access, sharemode, sa, createmode, 0, 0)
return h, e
} and that still passes on my computer. But, according to the documentation:
and I don't see how my change above will help here - the documentation requires us to pass "the same attributes as the existing file". I also not sure, if we want to change the way we treat hidden files. Alex |
What version of Go are you using (
go version
)?go version go1.10.2 windows/amd64
also reproduces on go version go1.8.7 windows/386
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?set GOARCH=amd64
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
What did you do?
I try to make a write access to an hidden text file on windows 10.
I made separate project to reproduce the issue here : https://github.com/FabienTregan/TestWritingToHiddenFilesInGo (with a bit more informations in the readme.md file)
What did you expect to see?
Some text written in the file
What did you see instead?
Received unexpected error:
open C:\Users[USER NAME]\AppData\Local\Temp\write_to_hidden_file_test_204946587: Access is denied.
The text was updated successfully, but these errors were encountered: