Skip to content
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.Chmod file.Chmod different behavior on Windows #39606

Closed
TACIXAT opened this issue Jun 16, 2020 · 3 comments
Closed

os.Chmod file.Chmod different behavior on Windows #39606

TACIXAT opened this issue Jun 16, 2020 · 3 comments

Comments

@TACIXAT
Copy link

@TACIXAT TACIXAT commented Jun 16, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.2 windows/amd64

Does this issue reproduce with the latest release?

Didn't try.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOHOSTARCH=amd64
set GOHOSTOS=windows

What did you do?

It does not work with file.Chmod().

	f, err := os.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()

	fi, err := f.Stat()
	if err != nil {
		return err
	}

	m := fi.Mode()

	err = f.Chmod(m | 0222)
	if err != nil {
		return err
	}

What did you expect to see?

Success.

What did you see instead?

chmod C:\Users\me\prog\proj\file.txt: not supported by windows

It does work with os.Chmod().

	f, err := os.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()

	fi, err := f.Stat()
	if err != nil {
		return err
	}

	m := fi.Mode()

	err = os.Chmod(path, m | 0222)
	if err != nil {
		return err
	}

I am sure there is some technical explanation for this, but from an API perspective it is a bit annoying.

@bcmills
Copy link
Member

@bcmills bcmills commented Jun 17, 2020

CC @alexbrainman @mattn

Could this be due to other stray bits in m? (What happens if you use (m&os.ModePerm)|0222 instead?

@bcmills bcmills added this to the Backlog milestone Jun 17, 2020
@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jun 21, 2020

I briefly looked at this, and it appears that syscall.Fchmod is not implemented, while syscall.Chmod is. I don't remember why it happened this way.

I also noticed that os.TestChmod is skipped on windows. os.TestChmod actually checks that os.File.Chmod works. So, I would start by making os.TestChmod run on windows, and see where it gets you.

I don't see problem implementing syscall.Fchmod, given that we already have syscall.Chmod implementation.

Alex

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 23, 2020

Change https://golang.org/cl/250077 mentions this issue: os: implement File.Chmod on Windows

@gopherbot gopherbot closed this in d7384f3 Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.