1
0
mirror of https://github.com/golang/go synced 2024-10-01 09:28:37 -06:00
Commit Graph

539 Commits

Author SHA1 Message Date
Clément Chigot
b3cfb0b322 os/user: allow build on aix/ppc64 with cgo
This commit adds C support for os/user package for aix/ppc64.

Updates #30563

Change-Id: Id07646998a7243b1335b85b5d4fe5bc4114e2a88
Reviewed-on: https://go-review.googlesource.com/c/go/+/164039
Run-TryBot: Mikio Hara <mikioh.public.networking@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-19 03:20:43 +00:00
Elias Naur
bedb6a18d8 os: only fallback to root directory if $HOME fails for UserHomeDir
UserHomeDir always returns "/" for platforms where the home directory
is not always well defined. However, the user might set HOME before
running a Go program on those platforms and on at least iOS, HOME
is actually set to something useful (the root of the app specific
writable directory).

This CL changes UserHomeDir to use the root directory "/" only if
$HOME is empty.

Change-Id: Icaa01de53cd585d527d9a23b1629375d6b7f67e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/167802
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-03-17 19:13:01 +00:00
Baokun Lee
d039e12b54 os: consistently return PathError from RemoveAll
Fixes #30491

Change-Id: If4070e5d39d8649643d7e90f6f3eb499642e25ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/164720
Run-TryBot: Baokun Lee <nototon@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-03-15 03:56:32 +00:00
Tobias Klauser
21a634e2e9 os: drop special case for FreeBSD 10.4 in newFile
Support for FreeBSD 10 will be dropped with Go 1.13, so revert the
workaround introduced in CL 157099.

Updates #29633
Updates #27619

Change-Id: I1a2e50d3f807a411389f3db07c0f4535a590da02
Reviewed-on: https://go-review.googlesource.com/c/go/+/165801
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-12 06:33:01 +00:00
Wèi Cōngruì
a60b56adbe internal/poll: make FD.isFile mean whether it isn't socket on Windows
Before this change, if a directory was closed twice on Windows,
the returning error would be "use of closed network connection".

Some code assumes FD.isFile means whether the fd isn't a network
socket, which is true on Unix. But isFile reports whether
the fd is a normal file rather than directory or console on Windows.

With this change, isFile will have the same meaning on different
platforms. And the change adds a new field kind to replace isConsole
and isDir.

Change-Id: Ib12265f1e12fa3d0239ae925291128a84be59cc2
GitHub-Last-Rev: 3f031756de
GitHub-Pull-Request: golang/go#30589
Reviewed-on: https://go-review.googlesource.com/c/go/+/165257
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-06 18:04:33 +00:00
Daniel Martí
ebdc24c3d3 os: add UserConfigDir
After UserCacheDir and UserHomeDir, the only remaining piece which is
commonly needed and portable is a per-user directory to store persistent
files.

For that purpose, UserCacheDir is wrong, as it's meant only for
temporary files. UserHomeDir is also far from ideal, as that clutters
the user's home directory.

Add UserConfigDir, which is implemented in a similar manner to
UserConfigDir.

Fixes #29960.

Change-Id: I7d7a56615103cf76e2b5e2bab2029a6b09d19f0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/160877
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-05 15:14:36 +00:00
Leon Klingele
4e20d999ec os: simplify check whether to run subtest of TestRemoveAll
Change-Id: Ic5b46cfb393f5ba7b91b3fb73b158b0bc238a532
GitHub-Last-Rev: e5c5db51bc
GitHub-Pull-Request: golang/go#30019
Reviewed-on: https://go-review.googlesource.com/c/go/+/160443
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-05 02:42:51 +00:00
Baokun Lee
c74659290a os: remove unreadable directories in RemoveAll
Fixes #30555

Change-Id: Ib894b4f3cdba23a18a69c9470cf69ceb83591a4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/165057
Run-TryBot: Baokun Lee <nototon@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-04 20:01:35 +00:00
Daniel Martí
d1887676d9 os/exec: less allocs in the common case
When Stdin, Stdout, and Stderr are nil, there are no goroutines to keep
track of, so we don't need a channel.

And in startProcess, preallocate the right size for sysattr.Files,
saving a bit of space and a couple of slice growth allocs.

name            old time/op    new time/op    delta
ExecHostname-8     419µs ± 0%     417µs ± 1%    ~     (p=0.093 n=6+6)

name            old alloc/op   new alloc/op   delta
ExecHostname-8    6.40kB ± 0%    6.28kB ± 0%  -1.86%  (p=0.002 n=6+6)

name            old allocs/op  new allocs/op  delta
ExecHostname-8      34.0 ± 0%      31.0 ± 0%  -8.82%  (p=0.002 n=6+6)

Change-Id: Ic1d617f29e9c6431cdcadc7f9bb992750a6d5f48
Reviewed-on: https://go-review.googlesource.com/c/164801
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-04 09:45:46 +00:00
Daniel Martí
83610c90bb os/exec: don't use the echo binary for a benchmark
Most notably, it's missing on Windows machines. For example,
windows-amd64-race started failing consistently:

	--- FAIL: BenchmarkExecEcho
	    bench_test.go:15: could not find echo: exec: "echo": executable file not found in %PATH%

We can also reproduce this from Linux with Wine:

	$ GOOS=windows go test -bench=. -benchtime=1x -run=- -exec wine
	--- FAIL: BenchmarkExecEcho
	    bench_test.go:15: could not find echo: exec: "echo": executable file not found in %PATH%

Instead, use the "hostname" program, which is available on Windows too.
Interestingly enough, it's also slightly faster than "echo". Any program
is fine as long as it's close enough to a no-op, though.

	name        old time/op    new time/op    delta
	ExecEcho-8     422µs ± 0%     395µs ± 0%  -6.39%  (p=0.004 n=6+5)

	name        old alloc/op   new alloc/op   delta
	ExecEcho-8    6.39kB ± 0%    6.42kB ± 0%  +0.53%  (p=0.002 n=6+6)

	name        old allocs/op  new allocs/op  delta
	ExecEcho-8      36.0 ± 0%      36.0 ± 0%    ~     (all equal)

Change-Id: I772864d69979172b5cf807552c84d0e165e73051
Reviewed-on: https://go-review.googlesource.com/c/164704
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-03 18:43:53 +00:00
Daniel Martí
59712fd03d os/exec: preallocate for Cmd.childFiles
We're always going to add stdin, stdout, and stderr to childFiles, so
its length will be at least three. The final length will be those three
elements plus however many files were given via ExtraFiles.

Allocate for that final length directly, saving two slice growth allocs
in the common case where ExtraFiles is empty.

name        old time/op    new time/op    delta
ExecEcho-8     435µs ± 0%     435µs ± 0%    ~     (p=0.394 n=6+6)

name        old alloc/op   new alloc/op   delta
ExecEcho-8    6.39kB ± 0%    6.37kB ± 0%  -0.39%  (p=0.002 n=6+6)

name        old allocs/op  new allocs/op  delta
ExecEcho-8      36.0 ± 0%      34.0 ± 0%  -5.56%  (p=0.002 n=6+6)

Change-Id: Ib702c0da1e43f0a55ed937af6d45fca6a170e8f3
Reviewed-on: https://go-review.googlesource.com/c/164898
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-03 17:45:46 +00:00
Josh Bleecher Snyder
beadf433c3 os/exec: provide map size hint in dedupEnvCase
The common case is that most env vars are distinct;
optimize for that.

name        old time/op    new time/op    delta
ExecEcho-8    2.16ms ± 3%    2.14ms ± 1%     ~     (p=0.315 n=10+10)

name        old alloc/op   new alloc/op   delta
ExecEcho-8    7.87kB ± 0%    6.35kB ± 0%  -19.31%  (p=0.000 n=9+10)

name        old allocs/op  new allocs/op  delta
ExecEcho-8      72.0 ± 0%      69.0 ± 0%   -4.17%  (p=0.000 n=10+10)

Change-Id: I42bb696c6862f2ea12c5cbd2f24c64336a7a759a
Reviewed-on: https://go-review.googlesource.com/c/164960
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-02 20:11:47 +00:00
Josh Bleecher Snyder
37b84e2782 os/exec: add BenchmarkExecEcho
Change-Id: Ie955cdc505766447f70b8f262160fe05b60a5b0c
Reviewed-on: https://go-review.googlesource.com/c/164959
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-02 19:37:02 +00:00
Alex Brainman
2edd559223 os: make Readlink work with symlinks with target like \??\Volume{ABCD}\
windows-arm TMP directory live inside such link (see
https://github.com/golang/go/issues/29746#issuecomment-456526811 for
details), so symlinks like that will be common at least on windows-arm.

This CL builds on current syscall.Readlink implementation. Main
difference between the two is how new code handles symlink targets,
like \??\Volume{ABCD}\.

New implementation uses Windows CreateFile API with
FILE_FLAG_OPEN_REPARSE_POINT flag to get \??\Volume{ABCD}\ file handle.
And then it uses Windows GetFinalPathNameByHandle with VOLUME_NAME_DOS
flag to convert that handle into standard Windows path.
FILE_FLAG_OPEN_REPARSE_POINT flag ensures that symlink is not followed
when CreateFile opens the file.

Fixes #30463

Change-Id: I33b18227ce36144caed694169ef2e429fd995fb4
Reviewed-on: https://go-review.googlesource.com/c/164201
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-01 07:44:37 +00:00
Ian Lance Taylor
4b05dc91b0 os: clarify that mode argument is only used if file is created
Fixes #30400

Change-Id: Icbd1dda29562afa80c8e37657133a6fe48070ac0
Reviewed-on: https://go-review.googlesource.com/c/163744
Reviewed-by: Rob Pike <r@golang.org>
2019-02-26 23:28:32 +00:00
Leon Klingele
d090429ea9 all: fix typos as reported by 'misspell'
Change-Id: I904b8655f21743189814bccf24073b6fbb9fc56d
GitHub-Last-Rev: b032c14394
GitHub-Pull-Request: golang/go#29997
Reviewed-on: https://go-review.googlesource.com/c/160421
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-26 23:02:05 +00:00
Ian Lance Taylor
cf4dc25503 os: don't return ENOENT if directory removed before Fstatat
Fixes #30197

Change-Id: I08b592fbd477d6879eb5d3b7fcbbc8322ea90103
Reviewed-on: https://go-review.googlesource.com/c/162078
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-02-12 21:17:38 +00:00
Ian Lance Taylor
56c9f8e8cf os: treat EACCES as a permission error in RemoveAll
Fixes #29983

Change-Id: I24077bde991e621c23d00973b2a77bb3a18e4ae7
Reviewed-on: https://go-review.googlesource.com/c/160180
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-01-30 01:56:14 +00:00
Ian Lance Taylor
ea27cd35fa os: restore RemoveAll docs by making a single copy
Updates #29983

Change-Id: Ifdf8aa9c92e053374e301a4268d85e277c15f0b5
Reviewed-on: https://go-review.googlesource.com/c/160182
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-30 01:39:37 +00:00
Ian Lance Taylor
eb72a30f87 os: make openFdAt act like openFileNolog
- add EINTR loop on Darwin
- return PathError on error
- call newFile rather than NewFile

This tries to minimize the possibility of any future changes.
It would be nice to put openFdAt in the same file as openFileNolog,
but build tags forbid.

Updates #29983

Change-Id: I866002416d6473fbfd80ff6ef09b2bc4607f2934
Reviewed-on: https://go-review.googlesource.com/c/160181
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2019-01-30 01:07:50 +00:00
Ian Lance Taylor
a5318bf5d6 os: always treat files as unpollable on FreeBSD
Fixes #29633
Updates #27619

Change-Id: I1e38569ea2a02423b028331f2ed987d3ae47fd2e
Reviewed-on: https://go-review.googlesource.com/c/157099
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-09 21:50:11 +00:00
Yuval Pavel Zholkover
79c50c4d57 os: disable the use of netpoll on regular files on *BSDs.
The kqueue based netpoller always registers file descriptors with EVFILT_READ and EVFILT_WRITE.
However only EVFILT_READ notification is supported for regular files.
On FreeBSD a regular file is always reported as ready for writing, resulting in a busy wait.
On Darwin, Dragonfly, NetBSD and OpenBSD, a regular file is reported as ready for both reading and writing only once.

Updates #19093

Change-Id: If284341f60c6c2332fb5499637d4cfa7a4e26b7b
Reviewed-on: https://go-review.googlesource.com/c/156379
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-01-09 05:04:26 +00:00
Yuval Pavel Zholkover
480373c756 syscall: revert to pre-FreeBSD 10 / POSIX-2008 timespec field names in Stat_t on FreeBSD
CL 138595 introduced the new names when the hardcoded stat8 definitions was replaced
with a cgo generated one.

Fixes #29393
Updates #22448

Change-Id: I6309958306329ff301c17344b2e0ead0cc874224
Reviewed-on: https://go-review.googlesource.com/c/155958
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-12-30 19:36:52 +00:00
Ian Lance Taylor
c0914d5df3 os: add SyscallConn method for os.File
Fixes #24331

Change-Id: I119c09a4259d852cdf8ea31b3e03e6f09a5f7bda
Reviewed-on: https://go-review.googlesource.com/c/155517
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-27 16:36:34 +00:00
Kevin Burke
8ff04a9966 os: clearer doc for Interrupt
I was confused by the juxtaposition of os.Interrupt docs, which are
"guaranteed to exist on all platforms" in one sentence and then
"not implemented" in the next sentence. Reading the code reveals
"not implemented" refers specifically to the implementation of
os.Process.Signal on Windows, not to the os.Interrupt variable itself.
Reword the doc to make this distinction clearer.

Fixes #27854.

Change-Id: I5fe7cddea61fa1954cef2006dc51b8fa8ece4d6e
Reviewed-on: https://go-review.googlesource.com/c/137336
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-12-20 18:56:28 +00:00
Ian Lance Taylor
745273f739 os: clarify O_TRUNC comment
Fixes #28699

Change-Id: Ic340c3171bb7d91d8cb9553967c2b51e7d9daba8
Reviewed-on: https://go-review.googlesource.com/c/155177
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-12-20 18:12:51 +00:00
Alex Brainman
49abcf1a97 os: adjust TempDir for Z:\
If TMP environment variable is set to Z:\, TempDir returns Z:.
But Z: refers to current directory on Z:, while Z:\ refers to root
directory on Z:. Adjust TempDir to return Z:\.

Fixes #29291

Change-Id: If04d0c7977a8ac2d9d558307502e81beb68776ef
Reviewed-on: https://go-review.googlesource.com/c/154384
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-20 09:04:35 +00:00
Kevin Burke
c343b6b2b8 os: show how to print permission bits in octal
Permission bits are most commonly viewed in string form (rwx-- etc) or
in octal form (0755), but the latter is relatively rare in Go.
Demonstrate how to print a FileMode in readable octal format.

Change-Id: I41feb801bcecb5077d4eabafdea27c149fc179a1
Reviewed-on: https://go-review.googlesource.com/c/154423
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-18 21:17:16 +00:00
Alex Brainman
e4535772ca os: make Stat work on FAT file system
It appears calling GetFileInformationByHandleEx with
FILE_ATTRIBUTE_TAG_INFO fails on FAT file system. FAT does not
support symlinks, so assume there are no symlnks when
GetFileInformationByHandleEx returns ERROR_INVALID_PARAMETER.

Fixes #29214

Change-Id: If2d9f3288bd99637681ab5fd4e4581c77b578a69
Reviewed-on: https://go-review.googlesource.com/c/154377
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-12-17 09:34:04 +00:00
Elias Naur
9eb383e8f0 runtime,os,syscall,internal/poll: replace getdirentries on iOS
The getdirentries syscall is considered private API on iOS and is
rejected by the App Store submission checks. Replace it with the
fdopendir/readdir_r/closedir syscalls.

Fixes #28984

Change-Id: I73341b124310e9cb34834a95f946769f337ec5b7
Reviewed-on: https://go-review.googlesource.com/c/153338
Reviewed-by: Keith Randall <khr@golang.org>
2018-12-13 17:10:32 +00:00
Lynn Boger
5dc144c607 os/signal: increase wait time for signal delivery time in testcase
This increases the time to wait from 1 to 2 seconds in the
TestAtomicStop testcase. When running with gccgo on ppc64
& ppc64le on a loaded systems these testcases can
intermittently fail with the current value.

Updates #29046

Change-Id: If420274dd65926d933a3024903b5c757c300bd60
Reviewed-on: https://go-review.googlesource.com/c/153826
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-12-13 12:14:18 +00:00
Ian Lance Taylor
ba1de79a3a os: in RemoveAll, try Remove first
Otherwise we can fail to remove a unreadable empty directory.

Fixes #29178

Change-Id: I43d5c89fce57a86626abe2a1c2bbf145716e087b
Reviewed-on: https://go-review.googlesource.com/c/153720
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-12 01:47:47 +00:00
Ian Lance Taylor
f91fd4f9da os: increase default write size for TestClosedPipeRaceWrite
The original value of 65537 consistently caused the test to fail on
Solaris. The new value of 131073 consistently lets the test pass.

Change-Id: If1a76ab89aa8f661ea049113addd04b23a116534
Reviewed-on: https://go-review.googlesource.com/c/152164
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-04 03:32:16 +00:00
Tobias Klauser
9e277f7d55 all: use "reports whether" consistently instead of "returns whether"
Follow-up for CL 147037 and after Brad noticed the "returns whether"
pattern during the review of CL 150621.

Go documentation style for boolean funcs is to say:

    // Foo reports whether ...
    func Foo() bool

(rather than "returns whether")

Created with:

    $ perl -i -npe 's/returns whether/reports whether/' $(git grep -l "returns whether" | grep -v vendor)

Change-Id: I15fe9ff99180ad97750cd05a10eceafdb12dc0b4
Reviewed-on: https://go-review.googlesource.com/c/150918
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-02 15:12:26 +00:00
David Heuschmann
649b89377e os: return an error from UserHomeDir to match UserCacheDir
UserHomeDir used to return an empty string if the corresponding
environment variable was not set. Changed it to return an error if the
variable is not set, to have the same signature and behaviour as UserCacheDir.

Fixes #28562

Change-Id: I42c497e8011ecfbbadebe7de1751575273be221c
Reviewed-on: https://go-review.googlesource.com/c/150418
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-22 20:49:16 +00:00
David du Colombier
47df645473 os: prevent RemoveAll to remove "." on Plan 9
CL 150497 enabled TestRemoveAllDot on "noat" systems.

However, this test is failing on Plan 9 because the rmdir
system call allows to remove "." on Plan 9.

This change prevents the "noat" implementation of RemoveAll to
remove ".", so it remains consistent with the "at" implementation.

Fixes #28903.

Change-Id: Ifc8fe36bdd8053a4e416f0590663c844c97ce72a
Reviewed-on: https://go-review.googlesource.com/c/150621
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-21 23:29:43 +00:00
Tobias Klauser
7780709369 os: return PathError on RemoveAll with trailing dots
Return a PathError instead of an unwrapped syscall.EINVAL if the path
ends with dots.

As suggested by Roger Peppe in CL 150158.

Change-Id: I4d82a6ff64a979b67a843a1cc4fea58ed9326aed
Reviewed-on: https://go-review.googlesource.com/c/150160
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-20 20:03:29 +00:00
Ian Lance Taylor
50c3465fad os: permit RemoveAll with paths that end in ".."
Prohibiting RemoveAll with paths that end in ".." was added with
CL 137442 in this release cycle, but it worked before and it should
continue to work.

Also run TestRemoveAllDot on all systems; the test is not specific to
the use of unlinkat and friends.

Change-Id: I277784c8915cd748fec318d2936062440d5d1fde
Reviewed-on: https://go-review.googlesource.com/c/150497
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-11-20 19:33:17 +00:00
Tobias Klauser
760ac1dd33 os: make RemoveAll("") fail silently on unix
CL 146020 changed the behavior of RemoveAll("") on unix systems using
the *at functions to return syscall.EINVAL instead of nil. Adjust the
*at implementation to retain this behavior as is the case on the *noat
systems.

Additionally, also make sure RemoveAll("") on systems not using the "at
functions (e.g. nacl and js/wasm) follow the same behavior (which wasn't
the case previously).

Fixes #28830

Change-Id: I8383c1423fefe871d18ff49134a1d23077ec6867
Reviewed-on: https://go-review.googlesource.com/c/150158
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: roger peppe <rogpeppe@gmail.com>
2018-11-18 16:13:13 +00:00
Alex Brainman
ff7b245a31 Revert "os: remove sleep in windows Process.Wait"
This reverts CL 145221 (commit 5c359736f8)

Reason for revert: breaks the build occasionally.

Updates #23171
Updates #25965

Change-Id: Ie1e3c76ab9bcd8d28b6118440b5f80c76f9b1852
Reviewed-on: https://go-review.googlesource.com/c/148957
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-09 23:24:35 +00:00
Brad Fitzpatrick
3813edf26e all: use "reports whether" consistently in the few places that didn't
Go documentation style for boolean funcs is to say:

    // Foo reports whether ...
    func Foo() bool

(rather than "returns true if")

This CL also replaces 4 uses of "iff" with the same "reports whether"
wording, which doesn't lose any meaning, and will prevent people from
sending typo fixes when they don't realize it's "if and only if". In
the past I think we've had the typo CLs updated to just say "reports
whether". So do them all at once.

(Inspired by the addition of another "returns true if" in CL 146938
in fd_plan9.go)

Created with:

$ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true iff" | grep -v vendor)
$ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true if" | grep -v vendor)

Change-Id: Ided502237f5ab0d25cb625dbab12529c361a8b9f
Reviewed-on: https://go-review.googlesource.com/c/147037
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-02 22:47:58 +00:00
Clément Chigot
5ee06f5471 internal/poll, os/exec, runtime: replace PollDescriptor by IsPollDescriptor
This commit changes poll.PollDescriptor by poll.IsPollDescriptor. This
is needed for OS like AIX which have more than one FD using inside their
netpoll implementation.

Change-Id: I49e12a8d74045c501e19fdd8527cf166a3c64850
Reviewed-on: https://go-review.googlesource.com/c/146938
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-02 13:43:23 +00:00
Tobias Klauser
cdad408069 os: add support for long path names on aix RemoveAll
Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on
aix.

Updates #27029

Change-Id: I78b34ed671166ee6fa651d5f2025b88548ee6c68
Reviewed-on: https://go-review.googlesource.com/c/146937
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Clément Chigot <clement.chigot@atos.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-02 13:21:12 +00:00
Alex Brainman
f10815898c os: use CreateFile for Stat of symlinks
Stat uses Windows FindFirstFile + CreateFile to gather symlink
information - FindFirstFile determines if file is a symlink,
and then CreateFile follows symlink to capture target details.

Lstat only uses FindFirstFile.

This CL replaces current approach with just a call to CreateFile.
Lstat uses FILE_FLAG_OPEN_REPARSE_POINT flag, that instructs
CreateFile not to follow symlink. Other than that both Stat and
Lstat look the same now. New code is simpler.

CreateFile + GetFileInformationByHandle (unlike FindFirstFile)
does not report reparse tag of a file. I tried to ignore reparse
tag altogether. And it works for symlinks and mount points.
Unfortunately (see https://github.com/moby/moby/issues/37026),
files on deduped disk volumes are reported with
FILE_ATTRIBUTE_REPARSE_POINT attribute set and reparse tag set
to IO_REPARSE_TAG_DEDUP. So, if we ignore reparse tag, Lstat
interprets deduped volume files as symlinks. That is incorrect.
So I had to add GetFileInformationByHandleEx call to gather
reparse tag after calling CreateFile and GetFileInformationByHandle.

Fixes #27225
Fixes #27515

Change-Id: If60233bcf18836c147597cc17450d82f3f88c623
Reviewed-on: https://go-review.googlesource.com/c/143578
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com>
2018-11-02 07:30:03 +00:00
Tobias Klauser
fa466a4f5a os: add support for long path names on freebsd RemoveAll
Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on
freebsd.

Since the layout of syscall.Stat_t changes in FreeBSD 12, Fstatat needs
a compatibility wrapper akin to Fstatat in x/sys/unix. See CL 138595 and
CL 136816 for details.

Updates #27029

Change-Id: I8851a5b7fa658eaa6e69a1693150b16d9a68f36a
Reviewed-on: https://go-review.googlesource.com/c/146597
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Yuval Pavel Zholkover <paulzhol@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-01 17:08:32 +00:00
Ian Lance Taylor
6c9b655ac1 os: don't create files in local directory
Also, use a random temporary directory rather than os.TempDir.  Defer
removal of existing random temporary directories.

Change-Id: Id7549031cdf78a2bab28c07b6eeff621bdf6e49c
Reviewed-on: https://go-review.googlesource.com/c/146457
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-11-01 08:36:12 +00:00
Tobias Klauser
4d1e95bb63 os: add support for long path names on solaris RemoveAll
Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on
solaris.

Updates #27029

Change-Id: I0b0e92f4422fa960a13dcd3e9adb57cd23f09ed4
Reviewed-on: https://go-review.googlesource.com/c/145839
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-31 16:52:45 +00:00
Oliver Stenbom
e8ffb8a74c os: add support for long path names on unix RemoveAll
On unix systems, long enough path names will fail when performing syscalls
like `Lstat`. The current RemoveAll uses several of these syscalls, and so
will fail for long paths. This can be risky, as it can let users "hide"
files from the system or otherwise make long enough paths for programs
to fail. By using `Unlinkat` and `Openat` syscalls instead, RemoveAll is
safer on unix systems. Initially implemented for linux, darwin, dragonfly,
netbsd and openbsd. Not yet implemented on freebsd due to fstatat 64-bit
inode compatibility issues.

Fixes #27029

Co-authored-by: Giuseppe Capizzi <gcapizzi@pivotal.io>
Co-authored-by: Julia Nedialkova <yulia.nedyalkova@sap.com>

Change-Id: I978a6a4986878fe076d3c7af86e7927675624a96
GitHub-Last-Rev: 9235489c81
GitHub-Pull-Request: golang/go#28494
Reviewed-on: https://go-review.googlesource.com/c/146020
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-31 13:55:01 +00:00
Alex Brainman
5cc8089948 os: use Stat instead of Lstat in Symlink
Windows implementation of Symlink uses CreateSymbolicLink Windows
API. The API requires to identify the target type: file or
directory. Current Symlink implementation  uses Lstat to determine
symlink type, but Lstat will not be able to determine correct
result if destination is symlink. Replace Lstat call with Stat.

Fixes #28432

Change-Id: Ibee6d8ac21e2246bf8d0a019c4c66d38b09887d4
Reviewed-on: https://go-review.googlesource.com/c/145217
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-31 08:40:43 +00:00
Katie Hockman
0e0f798624 Revert "os: add support for long path names on unix RemoveAll"
This reverts commit 85143d3554.

Reason for revert: Breaking all Darwin and FreeBSD builds. Trybots did not pass for this.

Change-Id: I5494e14ad5ab9cf6e1e225a25b2e8b38f3359d13
Reviewed-on: https://go-review.googlesource.com/c/145897
Reviewed-by: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-30 16:54:49 +00:00
Oliver Stenbom
85143d3554 os: add support for long path names on unix RemoveAll
On unix systems, long enough path names will fail when performing syscalls
like `Lstat`. The current RemoveAll uses several of these syscalls, and so
will fail for long paths. This can be risky, as it can let users "hide"
files from the system or otherwise make long enough paths for programs
to fail. By using `Unlinkat` and `Openat` syscalls instead, RemoveAll is
safer on unix systems. Initially implemented for linux, darwin, and several bsds.

Fixes #27029

Co-authored-by: Giuseppe Capizzi <gcapizzi@pivotal.io>
Co-authored-by: Julia Nedialkova <yulia.nedyalkova@sap.com>

Change-Id: Id9fcdf4775962b021b7ff438dc51ee6d16bb5f56
GitHub-Last-Rev: b30a621fe3
GitHub-Pull-Request: golang/go#27871
Reviewed-on: https://go-review.googlesource.com/c/137442
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-30 15:18:02 +00:00
Alex Brainman
5c359736f8 os: remove sleep in windows Process.Wait
The wait was there, because we discovered that we could not remove
finished process executable without the wait on Windows XP. But
Windows XP is not supported by Go. Maybe we do not need the wait
with modern Windows versions. Remove the sleep.

Fixes #25965

Change-Id: I02094abee3592ce4fea98eaff9d15137dc54dc81
Reviewed-on: https://go-review.googlesource.com/c/145221
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-29 09:04:07 +00:00
Diogo Pinela
81475ca256 os: ensure tests pass even if GOROOT is read-only
We achieve this by always running all tests that create files in a
fresh temporary directory, rather than just on darwin/{arm,arm64}.
As a bonus, this lets us simplify the cleanup code for these tests
and assume their working directory starts out empty.

Updates #28387

Change-Id: I952007ae390a2451c9a368da26c7f9f5af64b2ba
Reviewed-on: https://go-review.googlesource.com/c/145283
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-28 20:13:26 +00:00
Clément Chigot
db9e15e68f os: fix tests for AIX
This commits fixes tests for AIX inside os package.

"hostname" command on AIX returns "name.domain" and not only "name".
So, "hostname -s" must be called.

Change-Id: I75e193bcb6ad607ce54ad99aabbed9839012f707
Reviewed-on: https://go-review.googlesource.com/c/144537
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-26 14:46:35 +00:00
Ian Lance Taylor
361cf4a880 os: ignore SIGTTIN during TestTTYClose
Otherwise, if the test is run in the background, it will stop waiting
for access to the terminal.

Change-Id: Ib5224c6cb9060281e05c3b00cd2964445421e774
Reviewed-on: https://go-review.googlesource.com/c/136415
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-18 00:08:57 +00:00
Ian Lance Taylor
dc75744f9c os/signal: wait for goroutine in TestTerminalSignal
Fixes #28169

Change-Id: I187d9effea56357bbb04d4971d284a52ffae61f8
Reviewed-on: https://go-review.googlesource.com/c/142889
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-17 19:56:31 +00:00
Jordan Rhee
5ddec24888 os: change UserHomeDir to use USERPROFILE on windows
Fixes #28182

Change-Id: I49c2117fba6325c234512f937ff2edfa9477f52f
Reviewed-on: https://go-review.googlesource.com/c/142886
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-17 19:39:40 +00:00
Elias Naur
93cf82f08a os: make UserHomeDir return "/" on iOS
The UserHomeDir test succeeds on the builder, but not when run
manually where HOME is set to the host $HOME.

Change-Id: I1db0f608b04b311b53cc0c8160a3778caaf542f6
Reviewed-on: https://go-review.googlesource.com/c/141798
Run-TryBot: Elias Naur <elias.naur@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-12 14:25:13 +00:00
Clément Chigot
835f983da6 os: add AIX operating system
This commit adds AIX operating system to os package for ppc64
architecture.

Updates: #25893

Change-Id: Ieb9a2b3ac5b9abd3b5ab68eb732c17b6256d624d
Reviewed-on: https://go-review.googlesource.com/c/138725
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-11 15:41:04 +00:00
Yasuhiro Matsumoto
46cf91a75f all: fix typos
Change-Id: I775eb4b33422a95f4255799d551c9962d7e181d3
Reviewed-on: https://go-review.googlesource.com/c/140318
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-10-06 17:09:47 +00:00
Igor Zhilianin
f90e89e675 all: fix a bunch of misspellings
Change-Id: If2954bdfc551515403706b2cd0dde94e45936e08
GitHub-Last-Rev: d4cfc41a55
GitHub-Pull-Request: golang/go#28049
Reviewed-on: https://go-review.googlesource.com/c/140299
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-06 15:40:03 +00:00
Yuval Pavel Zholkover
dc6eb200dd syscall: FreeBSD 12 ino64 support
This is similar to CL 136816 for x/sys/unix, changing the FreeBSD ABI to use 64-bit inodes in
Stat_t, Statfs_t, and Dirent types.

The changes are forward compatible, that is FreeBSD 10.x, 11.x continue to use their current sysnum numbers.
The affected types are converted to the new layout (with some overhead).
Thus the same statically linked binary should work using the native sysnums (without any conversion) on FreeBSD 12.

Breaking API changes in package syscall are:
Mknod takes a uint64 (C dev_t) instead of int.
Stat_t: Dev, Ino, Nlink, Rdev, Gen became uint64.
  Atimespec, Mtimespec, Ctimespec, Birthtimespec renamed to Atim, Mtim, Ctim, Birthtim respectively.

Statfs_t: Mntonname and Mntfromname changed from [88]int8 to [1024]int8 arrays.

Dirent: Fileno became uint64, Namlen uint16 and an additional field Off int64 (currently unused) was added.

The following commands were run to generate ztypes_* and zsyscall_* on FreeBSD-12.0-ALPHA6 systems (GOARCH=386 were run on the same amd64 host):
GOOS=freebsd GOARCH=amd64 ./mksyscall.pl -tags freebsd,amd64 syscall_bsd.go syscall_freebsd.go syscall_freebsd_amd64.go |gofmt >zsyscall_freebsd_amd64.go
GOOS=freebsd GOARCH=amd64 go tool cgo -godefs types_freebsd.go | GOOS=freebsd GOARCH=amd64 go run mkpost.go >ztypes_freebsd_amd64.go

GOOS=freebsd GOARCH=386 ./mksyscall.pl -l32 -tags freebsd,386 syscall_bsd.go syscall_freebsd.go syscall_freebsd_386.go |gofmt >zsyscall_freebsd_386.go
GOOS=freebsd GOARCH=386 go tool cgo -godefs types_freebsd.go | GOOS=freebsd GOARCH=386 go run mkpost.go >ztypes_freebsd_386.go

GOOS=freebsd GOARCH=arm ./mksyscall.pl -l32 -arm -tags freebsd,arm syscall_bsd.go syscall_freebsd.go syscall_freebsd_arm.go |gofmt >zsyscall_freebsd_arm.go
GOOS=freebsd GOARCH=arm go tool cgo -godefs -- -fsigned-char types_freebsd.go | GOOS=freebsd GOARCH=arm go run mkpost.go >ztypes_freebsd_arm.go

The Kevent struct was changed to use the FREEBSD_COMPAT11 version always (requiring the COMPAT_FREEBSD11 kernel option FreeBSD-12, this is the default).

The definitions of ifData were not updated, their functionality in has have been replaced by vendored golang.org/x/net/route.

freebsdVersion initialization was dropped from init() in favor of a sync.Once based wrapper - supportsABI().

Updates #22448.

Change-Id: I359b756e2849c036d7ed7f75dbd6ec836e0b90b4
Reviewed-on: https://go-review.googlesource.com/c/138595
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-05 21:38:13 +00:00
Brad Fitzpatrick
f22c357a34 os: make UserHomeDir specialize behavior for GOOS=android
Change-Id: I69582662aeee7344226856c24907516ddfc92f60
Reviewed-on: https://go-review.googlesource.com/c/139717
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2018-10-04 16:32:56 +00:00
Brad Fitzpatrick
fa1a49aa55 os: add UserHomeDir
Fixes #26463

Change-Id: Iaef1c7456ffaeadeead6027a37d09c44a3d05bd5
Reviewed-on: https://go-review.googlesource.com/c/139418
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-03 21:47:09 +00:00
Alex Brainman
1c95d9728a os: use FILE_FLAG_OPEN_REPARSE_POINT in SameFile
SameFile opens file to discover identifier and volume serial
number that uniquely identify the file. SameFile uses Windows
CreateFile API to open the file, and that works well for files
and directories. But CreateFile always follows symlinks, so
SameFile always opens symlink target instead of symlink itself.

This CL uses FILE_FLAG_OPEN_REPARSE_POINT flag to adjust
CreateFile behavior when handling symlinks.

As per https://docs.microsoft.com/en-us/windows/desktop/FileIO/symbolic-link-effects-on-file-systems-functions#createfile-and-createfiletransacted

"... If FILE_FLAG_OPEN_REPARSE_POINT is specified and:

If an existing file is opened and it is a symbolic link, the handle
returned is a handle to the symbolic link. ...".

I also added new tests for both issue #21854 and #27225.
Issue #27225 is still to be fixed, so skipping the test on
windows for the moment.

Fixes #21854
Updates #27225

Change-Id: I8aaa13ad66ce3b4074991bb50994d2aeeeaa7c95
Reviewed-on: https://go-review.googlesource.com/134195
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-29 04:02:38 +00:00
Ian Davis
d3dcd89130 all: remove repeated "the" from comments
A simple grep over the codebase for "the the" which is often
missed by humans.

Change-Id: Ie4b4f07abfc24c73dcd51c8ef1edf4f73514a21c
Reviewed-on: https://go-review.googlesource.com/138335
Reviewed-by: Dave Cheney <dave@cheney.net>
2018-09-28 08:46:55 +00:00
Brad Fitzpatrick
da0d1a44ba all: use strings.ReplaceAll and bytes.ReplaceAll where applicable
I omitted vendor directories and anything necessary for bootstrapping.
(Tested by bootstrapping with Go 1.4)

Updates #27864

Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a
Reviewed-on: https://go-review.googlesource.com/137856
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-26 22:14:25 +00:00
David Heuschmann
eff3de0e63 os/user: note in doc that user.Current is being cached
user.Current caches the current user after its first call, so changes to
the uid after the first call will not affect its result. As this might
be unexpected, it should be mentioned in the docs.

Fixes #27659

Change-Id: I8b3323d55441d9a79bc9534c6490884d8561889b
Reviewed-on: https://go-review.googlesource.com/136315
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-25 17:10:46 +00:00
Tobias Klauser
a2a3dd00c9 os: add ModeCharDevice to ModeType
When masking FileInfo.Mode() from a character device with the ModeType
mask, ModeCharDevice cannot be recovered.

ModeCharDevice was added https://golang.org/cl/5531052, but nothing
indicates why it was omitted from ModeType. Add it now.

Fixes #27640

Change-Id: I52f56108b88b1b0a5bc6085c66c3c67e10600619
Reviewed-on: https://go-review.googlesource.com/135075
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-13 09:52:57 +00:00
Kevin Burke
3a18f0ecb5 os/user: retrieve Current username from /etc/passwd, not $USER
Per golang/go#27524 there are situations where the username for the
uid does not match the value in the $USER environment variable and it
seems sensible to choose the value in /etc/passwd when they disagree.

This may make the Current() call slightly more expensive, since we
read /etc/passwd with cgo disabled instead of just checking the
environment. However, we cache the result of Current() calls, so we
only invoke this cost once in the lifetime of the process.

Fixes #14626.
Fixes #27524.
Updates #24884.

Change-Id: I0dcd224cf7f61dd5292f3fcc363aa2e9656a2cb1
Reviewed-on: https://go-review.googlesource.com/134218
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-09 19:24:00 +00:00
Giovanni Bajo
1d15354fb9 os/exec: document how to do special args quoting on Windows
Updates #27199

Change-Id: I5cb6540266901697d3558ce75b8de63b1bfc2ce0
Reviewed-on: https://go-review.googlesource.com/132695
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-09-01 04:45:46 +00:00
Fazlul Shahriar
2e234754d7 os/exec: pass ExitCode tests on Plan 9
Fixes #27294

Change-Id: I8db5ca0f0c690bf532d3d33b8ed7d2633ad1702b
Reviewed-on: https://go-review.googlesource.com/131855
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-28 14:10:31 +00:00
Guoliang Wang
be94dac4e9 os: add ExitCode method to ProcessState
Fixes #26539

Change-Id: I6d403c1bbb552e1f1bdcc09a7ccd60b50617e0fc
GitHub-Last-Rev: 0b5262df5d
GitHub-Pull-Request: golang/go#26544
Reviewed-on: https://go-review.googlesource.com/125443
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-28 01:46:11 +00:00
Tobias Klauser
a700ae9863 Revert "syscall, os: use pipe2 syscall on DragonflyBSD instead of pipe"
This reverts commit e6c15945de.

Reason for revert: breaks the Dragonfly builders.

Fixes #27245

Change-Id: I2c147a5726aec28647f6ef5eb8f9db5efa3a9fd0
Reviewed-on: https://go-review.googlesource.com/131497
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-26 21:30:35 +00:00
Tobias Klauser
e6c15945de syscall, os: use pipe2 syscall on DragonflyBSD instead of pipe
Follow the implementation used by the other BSDs ith os.Pipe and
syscall.forkExecPipe consisting of a single syscall instead of three.

Change-Id: I602187672f244cbd8faaa3397904d71d15452d9f
Reviewed-on: https://go-review.googlesource.com/130996
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-08-24 14:41:04 +00:00
Seebs
9cfa41c826 os: use Println instead of Printf in example
This message has no format specifiers and no trailing newline.
It should use Println for consistency with other examples.

Change-Id: I49bd1652f9449fcbdd79c6b689c123090972aab3
Reviewed-on: https://go-review.googlesource.com/127836
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-24 07:11:38 +00:00
Kazuhiro Sera
ad644d2e86 all: fix typos detected by github.com/client9/misspell
Change-Id: Iadb3c5de8ae9ea45855013997ed70f7929a88661
GitHub-Last-Rev: ae85bcf82b
GitHub-Pull-Request: golang/go#26920
Reviewed-on: https://go-review.googlesource.com/128955
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-23 15:54:07 +00:00
David du Colombier
0a842d5560 os: handle TMPDIR in TempDir on Plan 9
CL 129063 added a test in TestScript/mod_enabled,
which was failing on Plan 9.

The test was failing because the Init function
of the cmd/go/internal/modload package was
expecting ModRoot to be part of os.TempDir.

However, ModRoot was set to TMPDIR, while
os.TempDir is returning /tmp on Plan 9.

This change fixes the implementation of
os.TempDir on Plan 9 to handle the TMPDIR
environment variable, similarly to Unix.

Fixes #27065.

Change-Id: Id6ff926c5c379f63cab2dfc378fa6c15293fd453
Reviewed-on: https://go-review.googlesource.com/129775
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-17 23:12:06 +00:00
Ian Lance Taylor
0bad63437e os: document that Remove removes only empty directories
Fixes #26507

Change-Id: I967e4f897ca891c70ca8bb0e66b984530c240815
Reviewed-on: https://go-review.googlesource.com/127835
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-08-03 23:09:31 +00:00
Roberto Clapis
faadda040d os: add check for empty executable path on darwin
os used to panic (access out of bounds) if executablePath was left empty

Fixes #22529

Change-Id: Iead5e60a3b000dbde421a8e8612c3690340879ce
Reviewed-on: https://go-review.googlesource.com/127546
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-02 20:31:25 +00:00
Adam Shannon
6f96cf2793 os/exec: document ExtraFiles is not supported on windows
Fixes #26182

Change-Id: I1181e191f4742f166c9b67a6f41332a237cf0ede
Reviewed-on: https://go-review.googlesource.com/123855
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-13 22:29:48 +00:00
Ian Lance Taylor
8d6fc84986 internal/poll: don't take read lock in SetBlocking
Taking a read lock in SetBlocking could cause SetBlocking to block
waiting for a Read in another goroutine to complete. Since SetBlocking
is called by os.(*File).Fd, that could lead to deadlock if the
goroutine calling Fd is going to use it to unblock the Read.
Use an atomic store instead.

Updates #24481

Change-Id: I79413328e06ddf28b6d5b8af7a0e29d5b4e1e6ff
Reviewed-on: https://go-review.googlesource.com/123176
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-07-11 00:34:18 +00:00
Ian Lance Taylor
e86bbc2e27 os: clarify that Close cancels pending I/O
Change-Id: I6be6818d951a999f916c2266a6753a5ce5144ee7
Reviewed-on: https://go-review.googlesource.com/122955
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-07-11 00:06:19 +00:00
Ian Lance Taylor
616da5da94 os: increase directory reading block size on Unix systems
Reportedly CIFS on RHEL 7 can fail to report files if directories are
read in 4K increments. While this seems to be a CIFS or RHEL bug,
reportedly CIFS does not return more than 5760 bytes in a block, so
reading in 8K increments should hide the problem from users with
minimal cost.

Fixes #24015

Change-Id: Iaf9f00ffe338d379c819ed9edcd4cc9834e3b0f7
Reviewed-on: https://go-review.googlesource.com/121756
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-06 22:39:14 +00:00
Daniel Martí
a94a390e5c os: treat "${}" in Expand like in Go 1.10
CL 103055 made it so that invalid parameter expansions, like "$|", did
not make the dollar sign silently disappear.

A few edge cases were not taken into account, such as "${}" and "${",
which were now printing just "$". For consistency and to not break
existing programs, go back to eating up the characters when invalid
syntax is encountered.

For completeness, add a "$" test case too, even though its behavior is
unchanged by this CL.

Fixes #26135.

Change-Id: I5d25db9a8356dc6047a8502e318355113a99b247
Reviewed-on: https://go-review.googlesource.com/121636
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-29 21:07:28 +00:00
Ian Lance Taylor
a6a69227f6 os: when looping in RemoveAll, close and re-open directory
On some systems removing files can cause a directory to be re-shuffled,
so simply continuing to read files can cause us to miss some.
Close and re-open the directory when looping, to avoid that.

Read more files each time through the loop, to reduce the chance of
having to re-open.

Fixes #20841

Change-Id: I98a14774ca63786ad05ba5000cbdb01ad2884332
Reviewed-on: https://go-review.googlesource.com/121255
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-27 22:05:25 +00:00
Andrew Bonventre
50bd1c4d4e os: have UserCacheDir return an error on failure
Previously, it would return an empty string if it
could not determine the user's cache directory.
Return an error instead.

Change-Id: I74f00b1ad3858efa3fe2700c599271ebfe5764b6
Reviewed-on: https://go-review.googlesource.com/120757
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-25 18:59:39 +00:00
Ian Lance Taylor
00eac8921e os, net: avoid races between dup, set-blocking-mode, and closing
Fixes #24481
Fixes #24483

Change-Id: Id7da498425a440c91582aa5480c253ae7a9c932c
Reviewed-on: https://go-review.googlesource.com/119955
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-22 14:27:22 +00:00
Tobias Klauser
d8e86caa3f os: skip TestFifoEOF on android
TestFifoEOF fails on android because the mkfifo syscall is not allowed:

--- FAIL: TestFifoEOF (0.00s)
    fifo_test.go:39: permission denied

Change-Id: I007ff359831525add39cec34de4b3d3cd3adb047
Reviewed-on: https://go-review.googlesource.com/118815
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-14 13:41:57 +00:00
Ian Lance Taylor
4a778cdf33 os: don't poll fifos on Darwin
The Darwin kqueue implementation doesn't report any event when the
last writer for a fifo is closed.

Fixes #24164

Change-Id: Ic2c47018ef1284bf2e26379f8dd7646edaad4d05
Reviewed-on: https://go-review.googlesource.com/118566
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-13 20:27:55 +00:00
Eugene Kalinin
0e934dd90e os: check setStickyBit error in mkdir
If an error occurs, delete the newly created directory.

Change-Id: I97e960d24af32f027fb23d5ce3f61959e73f6fb0
Reviewed-on: https://go-review.googlesource.com/115715
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-05 14:53:18 +00:00
Tim Cooper
161874da2a all: update comment URLs from HTTP to HTTPS, where possible
Each URL was manually verified to ensure it did not serve up incorrect
content.

Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df
Reviewed-on: https://go-review.googlesource.com/115798
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-06-01 21:52:00 +00:00
Richard Musiol
063f97a611 os: add js/wasm architecture
This commit adds the js/wasm architecture to the os package.

Access to the actual file system is supported through Node.js.

Updates #18892

Change-Id: I6fa642fb294ca020b2c545649d4324d981aa0408
Reviewed-on: https://go-review.googlesource.com/109977
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-01 05:18:38 +00:00
Tobias Klauser
7ea2c8cf1b os/exec: gofmt
CL 109361 introduced some changes which were not properly gofmt'ed.
Because the CL was sent via Github no gofmt checks were performed
on it (cf. #24946, #18548).

Change-Id: I207065f01161044c420e272f4fd112e0a59be259
Reviewed-on: https://go-review.googlesource.com/115356
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-30 19:57:39 +00:00
Tim Cooper
79fbe92b7e os/signal: remove unnecessary else condition
Change-Id: I00f0195d54bf9bc30073741974ab941ec4d51a5c
Reviewed-on: https://go-review.googlesource.com/108635
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-29 21:06:31 +00:00
azat
ef99381676 os: Add example for Expand function.
Change-Id: I581492c29158e57ca2f98b75f47870791965a7ff
Reviewed-on: https://go-review.googlesource.com/81155
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-23 15:37:22 +00:00
Tobias Klauser
fc9c69a693 os: remove superfluous comments
It's apparent from the file names or build tags to which OS the code in
question applies.

Change-Id: I628ee2bf1d29a6bc30ca5fa6f9eecf809e78a182
Reviewed-on: https://go-review.googlesource.com/110815
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-02 14:41:57 +00:00
Brad Fitzpatrick
6a8cff5730 os: fix missing break bug in earlier CL 110295's use of Uname
The Uname name was never being used because it always generated a
too-long string.

The new test looking for zero bytes wouldn't have caught it (I thought
it would've), but is still nice to have.

Updates #24701

Change-Id: I2648074452609e4ad1b9736973e1b3a95eac658d
Reviewed-on: https://go-review.googlesource.com/110436
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-05-01 15:55:49 +00:00
Brad Fitzpatrick
3c7456c1b0 os: find Hostname using Uname to fix Android
It's also fewer system calls. Fall back to longer read
only if it seems like the Uname result is truncated.

Fixes #24701

Change-Id: Ib6550acede8dddaf184e8fa9de36377e17bbddab
Reviewed-on: https://go-review.googlesource.com/110295
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-30 18:10:46 +00:00
Yasuhiro Matsumoto
e656aebb5b os: os: make Stat("*.txt") fail on windows
Fixes #24999

Change-Id: Ie0bb6a6e0fa3992cdd272d42347af65ae7c95463
Reviewed-on: https://go-review.googlesource.com/108755
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-04-27 10:04:48 +00:00