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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@TACIXAT
Copy link

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
Contributor

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 NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Jun 17, 2020
@bcmills bcmills added this to the Backlog milestone Jun 17, 2020
@alexbrainman
Copy link
Member

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

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

@golang golang locked and limited conversation to collaborators Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

4 participants