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: why must Chmod mode be non-zero on Windows? #20858

Open
bradfitz opened this Issue Jun 30, 2017 · 6 comments

Comments

Projects
None yet
7 participants
@bradfitz
Copy link
Member

bradfitz commented Jun 30, 2017

From the beginning of Go until at least Go 1.9, the os.Chmod mode parameter must be non-zero on Windows.

I don't see why, though. syscall.Chmod returns EINVAL otherwise. Can we remove that?

I documented this in CL 47254 at least.

/cc @alexbrainman @ianlancetaylor

@bradfitz bradfitz added this to the Go1.10 milestone Jun 30, 2017

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jun 30, 2017

CL https://golang.org/cl/47254 mentions this issue.

gopherbot pushed a commit that referenced this issue Jun 30, 2017

os: add documentation for Windows users
Updates #18581
Updates #20858

Change-Id: I6b5ce0e255a42c028d46815fff5a5aca68690fd9
Reviewed-on: https://go-review.googlesource.com/47254
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@bradfitz

This comment has been minimized.

Copy link
Member Author

bradfitz commented Nov 30, 2017

@rsc, the @golang/proposal-review NeedsDecision queries aren't working if old things like this are still open.

Bumping to Go 1.11.

@bradfitz bradfitz modified the milestones: Go1.10, Go1.11 Nov 30, 2017

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jun 27, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Nov 14, 2018

Let's try changing this at the start of Go 1.13 and see what breaks. I can't explain it.

@rsc rsc modified the milestones: Go1.12, Go1.13 Nov 14, 2018

@odeke-em

This comment has been minimized.

Copy link
Member

odeke-em commented Mar 11, 2019

Great question @bradfitz!

I just looked at https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/chmod?view=vs-2017 which points to https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/chmod-wchmod?view=vs-2017 and there is seems to have a relaxed opinion and by allusion that *mode can be zero by using "simply ignores those". Quoting that page:
Screen Shot 2019-03-11 at 4 20 29 PM

"If pmode is not a combination of one of the manifest constants or incorporates an alternate set of constants, the function simply ignores those. "

Kindly paging @jordanrh1 @alexbrainman @brendandburns, what do y'all think?

@alexbrainman

This comment has been minimized.

Copy link
Member

alexbrainman commented Mar 14, 2019

I don't have strong opinion on this.

I believe @mattn added that code in https://golang.org/cl/4175049 Maybe he remembers why the code worked that way.

Alex

@mattn

This comment has been minimized.

Copy link
Member

mattn commented Mar 14, 2019

Sorry, I don't remember why I ignored 0. Probably, I read the part of doc here:

This function validates its parameters. If pmode is not a combination of one of the manifest constants or incorporates an alternate set of constants, the function simply ignores those. If filename is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, errno is set to EINVAL and the function returns -1.

And added the check. Now I confirmed chmod(filename, 0) works fine.

#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <errno.h>
#include <error.h>

int
main(int argc, char* argv[]) {
  int r;
  r = open("dummy", O_CREAT);
  if (r < 0) {
    fprintf(stderr, "creat: %s\n", strerror(errno));
	return 1;
  }
  close(r);

  r = _chmod("dummy", 0);
  if (r < 0) {
    fprintf(stderr, "chmod: %s\n", strerror(errno));
	return 1;
  }

  unlink("dummy");
  return 0;
}

So we can change this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.