peterbourgon / diskv

A disk-backed key-value store.
http://godoc.org/github.com/peterbourgon/diskv
MIT License
1.41k stars 102 forks source link

(*File).Chmod on Windows #59

Closed mchtech closed 4 years ago

mchtech commented 4 years ago

https://github.com/golang/go/blob/bba88467f86472764a656e61f5f3265ed6853692/src/syscall/syscall_windows.go#L1094

os.Chmod always return syscall.EWINDOWS error on Windows.

peterbourgon commented 4 years ago

How do you change file perms on Windows, then?

mchtech commented 4 years ago

golang does not support chmod (*File).Chmod on Windows (so far) and ioutil.TempFile always creates file with 0600. So, one solution is to create the tmpfile with specified FilePerm directly.

peterbourgon commented 4 years ago

os.Chmod works fine on Windows, it just requires a restricted set of file modes. If you're using diskv on Windows, you can change diskv.FilePerm to one of those supported modes.

peterbourgon commented 4 years ago

@mchtech Will that solve your problem?

mchtech commented 4 years ago

It seems a problem of golang 😂

os.Chmod works fine on Windows, but (*File).Chmod will return syscall.EWINDOWS.

on Windows:

peterbourgon commented 4 years ago

Does os.Chmod still return an error when you use one of the supported FileModes listed in the documentation?

mchtech commented 4 years ago

I just tested it on Windows:

os.Chmod works fine on Windows and does not return any error but (*File).Chmod not

So, another solution is to change f.Chmod(perm) to os.Chmod(f.Name(), perm)

peterbourgon commented 4 years ago

OK, I believe this is safe.