Commit 94af800
committed
Lchmod(): fix for Linux/Go 1.11
Linux does not support file mode for symlinks. It does not support
flags argument for fchmodat() syscall either (the only flag described
by POSIX is AT_SYMLINK_NOFOLLOW to allow changing mode on symlink).
This is probably the reason why the standard os package from Go
does not provide Lchmod().
Go < 1.11 errorneously assumed the flags argument is supported on Linux,
and implemented syscall.Fchmodat() with flags being passed on to
the kernel. The kernel ignored the flags (as the kernel syscall doesn't
even have flags argument). The result was changing the mode on the
file that symlink points to (i.e. ignoring AT_SYMLINK_NOFOLLOW).
The above bug was fixed in Go-1.11beta1 (see [1]), and since the fix,
if any flags are set, an error is returned. This rendered Lchmod()
useless on Linux + Go 1.11, as now it always returns an error.
The best possible fix I can think of, given the constraints of
keeping the API intact, is implemented in this commit. In short,
chown() is not called for symlinks on Linux.
[1] https://go-review.googlesource.com/c/go/+/118658
Signed-off-by: Kir Kolyshkin <[email protected]>1 parent 9ab0ec6 commit 94af800
3 files changed
Lines changed: 33 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 28 | | |
35 | 29 | | |
36 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments