summaryrefslogtreecommitdiff
path: root/src/os/file_unix.go
Commit message (Collapse)AuthorAgeFilesLines
* os: if descriptor is non-blocking, retain that in Fd methodIan Lance Taylor2023-05-171-5/+12
| | | | | | | | | | | | | | For #58408 Fixes #60211 Change-Id: I30f5678b46e15121865b19d1c0f82698493fad4e Reviewed-on: https://go-review.googlesource.com/c/go/+/495079 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
* os, runtime: remove unused implementations of os.sigpipeIan Lance Taylor2023-05-121-0/+2
| | | | | | | | | | | | | | | Clean up instances that are unused since CL 6450058. Change-Id: I0e9ae28cfa83fcc8abda8f5eca9c7dfc2c1c4ad1 Reviewed-on: https://go-review.googlesource.com/c/go/+/477396 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
* os: make Chtimes accept empty time values to skip file time modificationConstantin Konstantinidis2023-05-111-0/+2
| | | | | | | | | | | | | | | | Empty time value time.Time{} leaves the corresponding time of the file unchanged. Fixes #32558 Change-Id: I1aff42f30668ff505ecec2e9509d8f2b8e4b1b6a Reviewed-on: https://go-review.googlesource.com/c/go/+/219638 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
* all: add String for fs.{FileInfo,DirEntry} implementationsIan Lance Taylor2023-05-041-0/+5
| | | | | | | | | | | | | | | | | The new String methods use the new FormatFileInfo and FormatDirEntry functions. Fixes #54451 Change-Id: I414cdfc212ec3c316fb2734756d2117842a23631 Reviewed-on: https://go-review.googlesource.com/c/go/+/491175 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
* os: add wasip1 supportJohan Brandhorst-Satzkorn2023-04-071-4/+7
| | | | | | | | | | | | | | | | | For #58141 Co-authored-by: Richard Musiol <neelance@gmail.com> Co-authored-by: Achille Roussel <achille.roussel@gmail.com> Co-authored-by: Julien Fabre <ju.pryz@gmail.com> Co-authored-by: Evan Phoenix <evan@phx.io> Change-Id: I52e3e161f81dcbe8605570e47d732992979c4d34 Reviewed-on: https://go-review.googlesource.com/c/go/+/479623 Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
* os: don't try to put directory into non-blocking modeIan Lance Taylor2023-02-271-0/+10
| | | | | | | | | | | | | | | Fixes #56843 Change-Id: I3cb3e8397499cd8c57a3edddd45f38c510519b36 Reviewed-on: https://go-review.googlesource.com/c/go/+/451997 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Nicolas Hillegeer <aktau@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Rob Pike <r@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* os: only add file descriptors which are set to non-blocking mode to the ↵Yuval Pavel Zholkover2022-08-181-11/+21
| | | | | | | | | | | | | | | | | | | netpoller Either ones where kind == kindNonBlock or those we've successfully called syscall.SetNonblock() on. Restore blocking behavior if we detect an error registering with the netpoller and our flow was successful in setting the inital syscall.SetNonblock(). Update #54100 Change-Id: I08934e4107c7fb36c15a7ca23ac880490b4df235 Reviewed-on: https://go-review.googlesource.com/c/go/+/420334 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Yuval Pavel Zholkover <paulzhol@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
* all: replace `` and '' with “ (U+201C) and ” (U+201D) in doc commentsRuss Cox2022-04-051-1/+1
| | | | | | | | | | | | | | | | go/doc in all its forms applies this replacement when rendering the comments. We are considering formatting doc comments, including doing this replacement as part of the formatting. Apply it to our source files ahead of time. For #51082. Change-Id: Ifcc1f5861abb57c5d14e7d8c2102dfb31b7a3a19 Reviewed-on: https://go-review.googlesource.com/c/go/+/384262 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: use new "unix" build tag where appropriateIan Lance Taylor2022-03-291-1/+1
| | | | | | | | | | For #20322 For #51572 Change-Id: Id0b4799d097d01128e98ba4cc0092298357bca45 Reviewed-on: https://go-review.googlesource.com/c/go/+/389935 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor)Russ Cox2021-10-281-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | When these packages are released as part of Go 1.18, Go 1.16 will no longer be supported, so we can remove the +build tags in these files. Ran go fix -fix=buildtag std cmd and then reverted the bootstrapDirs as defined in src/cmd/dist/buildtool.go, which need to continue to build with Go 1.4 for now. Also reverted src/vendor and src/cmd/vendor, which will need to be updated in their own repos first. Manual changes in runtime/pprof/mprof_test.go to adjust line numbers. For #41184. Change-Id: Ic0f93f7091295b6abc76ed5cd6e6746e1280861e Reviewed-on: https://go-review.googlesource.com/c/go/+/344955 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* os: document that Windows Symlink to missing target creates file symlinkIan Lance Taylor2021-05-021-0/+2
| | | | | | | | | | | Fixes #39183 Change-Id: Iec4a5a561182ade57dc7dc24247710005d6b9f21 Reviewed-on: https://go-review.googlesource.com/c/go/+/314275 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
* all: simplify the spelling of LinuxBrad Fitzpatrick2021-04-131-1/+1
| | | | | | | | | | The prefix didn't help clarify anything. Change-Id: I897fd4022ce9df42a548b15714e4b592618ca547 Reviewed-on: https://go-review.googlesource.com/c/go/+/309573 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
* os: reuse readdir buffers on unix with a sync.PoolTom Thorogood2021-04-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (*File).readdir allocates a fixed-size 8KiB buffer on unix systems that cannot be reused. While it accounts for just a single allocation, it's more than large enough to show up in profiles and make things quite a bit slower. Instead of allocating so often, use a sync.Pool to allow these buffers to be reused. This has a large impact on readdir heavy workloads. Package os benchmarks: name old time/op new time/op delta Readdirname-12 35.6µs ± 5% 18.1µs ± 4% -49.00% (p=0.000 n=10+10) Readdir-12 142µs ± 1% 121µs ± 0% -14.87% (p=0.000 n=10+9) ReadDir-12 44.0µs ± 6% 28.4µs ± 8% -35.58% (p=0.000 n=9+10) name old alloc/op new alloc/op delta Readdirname-12 14.4kB ± 0% 6.2kB ± 0% -57.08% (p=0.000 n=10+10) Readdir-12 41.6kB ± 0% 33.4kB ± 0% -19.77% (p=0.000 n=10+9) ReadDir-12 21.9kB ± 0% 13.7kB ± 0% -37.39% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Readdirname-12 131 ± 0% 130 ± 0% -0.76% (p=0.000 n=10+10) Readdir-12 367 ± 0% 366 ± 0% -0.27% (p=0.000 n=10+10) ReadDir-12 249 ± 0% 248 ± 0% -0.40% (p=0.000 n=10+10) A clunky benchmark I threw together that calls filepath.WalkDir on $GOMODCACHE: name old time/op new time/op delta WalkDir-12 91.2ms ±19% 48.7ms ± 0% -46.54% (p=0.000 n=10+10) name old alloc/op new alloc/op delta WalkDir-12 54.0MB ± 0% 7.6MB ± 0% -85.92% (p=0.000 n=8+9) name old allocs/op new allocs/op delta WalkDir-12 136k ± 0% 130k ± 0% -4.15% (p=0.000 n=8+8) Change-Id: I00e4d48726da0e46c528ab205409afd03127b844 Reviewed-on: https://go-review.googlesource.com/c/go/+/302169 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
* all: go fmt std cmd (but revert vendor)Russ Cox2021-02-201-0/+1
| | | | | | | | | | | | | | | | Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: further document limitations around naked file descriptorsVictor Michel2021-01-261-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | NewFile requires the file descriptor to be either closed through the returned File instance, or to stay valid at least until the finalizer runs during garbage collection. These requirements are easily violated when file descriptors are closed via unix.Close, or when the *File returned by NewFile is garbage collected while the underlying file descriptor is still in use. This commit adds further documentation for NewFile and Fd, making it explicit that using naked file descriptors is subject to constraints due to garbage collection of File objects. Fixes #43863 Change-Id: I49ea1f0054eb2d2a72b616450c8e83476f4d07fb GitHub-Last-Rev: 180d0130ae9009456914fb265b4bafa0e599de0e GitHub-Pull-Request: golang/go#43867 Reviewed-on: https://go-review.googlesource.com/c/go/+/286032 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* os: use keyed literals for PathErrorRuss Cox2020-10-201-5/+5
| | | | | | | | | | | | | Necessary to move PathError to io/fs. For #41190. Change-Id: I05e87675f38a22f0570d4366b751b6169f7a1b13 Reviewed-on: https://go-review.googlesource.com/c/go/+/243900 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: add File.ReadDir method and DirEntry typeRuss Cox2020-10-201-28/+38
| | | | | | | | | | | | | | | | ReadDir provides a portable, efficient way to read a directory and discover the type of directory entries. This enables a more efficient file system walk, yet to be added. See #41467 for the proposal review for the API. Fixes #41467. Change-Id: I461a526793ae46df48821aa448b04f1705546739 Reviewed-on: https://go-review.googlesource.com/c/go/+/261540 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* os: fix SyscallConn typos in the File.Fd commentsChangkun Ou2020-09-281-1/+1
| | | | | | | | | | | | This CL fixes two typos introduced in CL 256899. Change-Id: I47f0a3097deeeec8d6e9bbe7073fcf7a28c5dff9 Reviewed-on: https://go-review.googlesource.com/c/go/+/257997 Trust: Tobias Klauser <tobias.klauser@gmail.com> Trust: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
* os: document and emphasize a potential misuse of File.FdChangkun Ou2020-09-271-2/+7
| | | | | | | | | | | | | | | | This CL revises the document of File.Fd that explicitly points its user to runtime.SetFinalizer where contains the information that a file descriptor could be closed in a finalizer and therefore causes a failure in syscall.Write if runtime.KeepAlive is not invoked. The CL also suggests an alternative of File.Fd towards File.SyscallConn. Fixes #41505 Change-Id: I6816f0157add48b649bf1fb793cf19dcea6894b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/256899 Reviewed-by: Rob Pike <r@golang.org> Trust: Ian Lance Taylor <iant@golang.org>
* all: add GOOS=iosCherry Zhang2020-09-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Introduce GOOS=ios for iOS systems. GOOS=ios matches "darwin" build tag, like GOOS=android matches "linux" and GOOS=illumos matches "solaris". Only ios/arm64 is supported (ios/amd64 is not). GOOS=ios and GOOS=darwin remain essentially the same at this point. They will diverge at later time, to differentiate macOS and iOS. Uses of GOOS=="darwin" are changed to (GOOS=="darwin" || GOOS=="ios"), except if it clearly means macOS (e.g. GOOS=="darwin" && GOARCH=="amd64"), it remains GOOS=="darwin". Updates #38485. Change-Id: I4faacdc1008f42434599efb3c3ad90763a83b67c Reviewed-on: https://go-review.googlesource.com/c/go/+/254740 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
* os, internal/poll: loop on EINTR for all file syscallsIan Lance Taylor2020-08-191-8/+32
| | | | | | | | | | | | | When using a FUSE file system, any system call that touches the file system can return EINTR. Fixes #40846 Change-Id: I25d32da22cec08dea81ab297291a85ad72db2df7 Reviewed-on: https://go-review.googlesource.com/c/go/+/249178 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* os: always check for EINTR in calls to openIan Lance Taylor2020-06-081-4/+2
| | | | | | | | | | For #11180 For #20400 For #39237 Change-Id: I8de97517c8f92c08f0c8a51f651a17e31617979b Reviewed-on: https://go-review.googlesource.com/c/go/+/236997 Reviewed-by: Bryan C. Mills <bcmills@google.com>
* os: merge common Unix/Windows methodsIan Lance Taylor2020-03-201-44/+0
| | | | | | | | | | Several method implementations were identical in file_unix.go and file_windows.go. Merge them into file_posix.go. Change-Id: I8bcfad468829530f81f52fe426b3a8c042e7bbd6 Reviewed-on: https://go-review.googlesource.com/c/go/+/224138 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
* os: seek should invalidate any cached directory readsKeith Randall2020-03-011-1/+6
| | | | | | | | | | | | | | | | | When we seek on the underlying FD, discard any directory entries we've already read and cached. This makes sure we won't return the same entry twice. We already fixed this for Darwin in CL 209961. Fixes #37161 Change-Id: I20e1ac8d751443135e67fb4c43c18d69befb643b Reviewed-on: https://go-review.googlesource.com/c/go/+/219143 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* os: reset dirinfo when seeking on DarwinKeith Randall2019-12-051-0/+1
| | | | | | | | | | | | | | | | | | | | | The first Readdirnames calls opendir and caches the result. The behavior of that cached opendir result isn't specified on a seek of the underlying fd. Free the opendir result on a seek so that we'll allocate a new one the next time around. Also fix wasm behavior in this regard, so that a seek to the file start resets the Readdirnames position, regardless of platform. p.s. I hate the Readdirnames API. Fixes #35767. Change-Id: Ieffb61b3c5cdd42591f69ab13f932003966f2297 Reviewed-on: https://go-review.googlesource.com/c/go/+/209961 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* os: allow case only renames on case-insensitive filesystemsAudrius Butkevicius2019-11-011-2/+6
| | | | | | | | | | | | Fixes #35222 Change-Id: I8be45092ac4079d21ff54661637a3aa8ec4eb9bc GitHub-Last-Rev: 954a016c9bb749268e97489911ea577a6df9fb4c GitHub-Pull-Request: golang/go#35298 Reviewed-on: https://go-review.googlesource.com/c/go/+/204601 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* all: remove the nacl port (part 1)Brad Fitzpatrick2019-10-091-1/+1
| | | | | | | | | | | | | | | | | | You were a useful port and you've served your purpose. Thanks for all the play. A subsequent CL will remove amd64p32 (including assembly files and toolchain bits) and remaining bits. The amd64p32 removal will be separated into its own CL in case we want to support the Linux x32 ABI in the future and want our old amd64p32 support as a starting point. Updates #30439 Change-Id: Ia3a0c7d49804adc87bf52a4dea7e3d3007f2b1cd Reviewed-on: https://go-review.googlesource.com/c/go/+/199499 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* doc: clarify safety of multiple and concurent os.(*File).Close() callsAlex Myasoedov2019-06-051-0/+1
| | | | | | | | | Fixes #32427 Change-Id: I4b863bd3836067dcc2eb3a9c3a7169656763d003 Reviewed-on: https://go-review.googlesource.com/c/go/+/180438 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* os: disable the use of netpoll on directories as well on *BSDsYuval Pavel Zholkover2019-04-191-5/+7
| | | | | | | | | | | | Follow up CL 156379. Updates #19093 Change-Id: I5ea3177fc5911d3af71cbb32584249e419e9d4a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/172937 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: reject WriteAt if file opened in append modeLE Manh Cuong2019-03-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | WriteAt use pwrite syscall on *nix or WriteFile on Windows. On Linux/Windows, these system calls always write to end of file in append mode, regardless of offset parameter. It is hard (maybe impossible) to make WriteAt work portably. Making WriteAt returns an error if file is opened in append mode, we guarantee to get consistent behavior between platforms, also prevent user from accidently corrupting their data. Fixes #30716 Change-Id: If83d935a22a29eed2ff8fe53d13d0b4798aa2b81 Reviewed-on: https://go-review.googlesource.com/c/go/+/166578 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* os: drop special case for FreeBSD 10.4 in newFileTobias Klauser2019-03-121-9/+1
| | | | | | | | | | | | | | 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>
* os: make Readlink work with symlinks with target like \??\Volume{ABCD}\Alex Brainman2019-03-011-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* os: make openFdAt act like openFileNologIan Lance Taylor2019-01-301-0/+1
| | | | | | | | | | | | | | | | | | - 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>
* os: always treat files as unpollable on FreeBSDIan Lance Taylor2019-01-091-6/+16
| | | | | | | | | Fixes #29633 Updates #27619 Change-Id: I1e38569ea2a02423b028331f2ed987d3ae47fd2e Reviewed-on: https://go-review.googlesource.com/c/157099 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* os: disable the use of netpoll on regular files on *BSDs.Yuval Pavel Zholkover2019-01-091-13/+19
| | | | | | | | | | | | | | | 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>
* runtime,os,syscall,internal/poll: replace getdirentries on iOSElias Naur2018-12-131-7/+31
| | | | | | | | | | | | 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>
* os: add AIX operating systemClément Chigot2018-10-111-1/+1
| | | | | | | | | | | | | 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>
* os: document that Remove removes only empty directoriesIan Lance Taylor2018-08-031-1/+1
| | | | | | | | | 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>
* os: clarify that Close cancels pending I/OIan Lance Taylor2018-07-111-1/+2
| | | | | | | 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>
* os: don't poll fifos on DarwinIan Lance Taylor2018-06-131-2/+13
| | | | | | | | | | | 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>
* all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper2018-06-011-1/+1
| | | | | | | | | | 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>
* os: add js/wasm architectureRichard Musiol2018-06-011-1/+1
| | | | | | | | | | | | | | 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>
* os: use poller when NewFile is called with a blocking descriptor.Nick Patavalis2018-04-111-3/+14
| | | | | | | | | | | | | | | | | If NewFile is called with a file descriptor that is already set to non-blocking mode, it tries to return a pollable file (one for which SetDeadline methods work) by adding the filedes to the poll/netpoll mechanism. If called with a filedes in blocking mode, it returns a non-pollable file, as it always did. Fixes #22939 Updates #24331 Change-Id: Id54c8be1b83e6d35e14e76d7df0e57a9fd64e176 Reviewed-on: https://go-review.googlesource.com/100077 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: respect umask in Mkdir and OpenFile on BSD systems when perm has ↵Yuval Pavel Zholkover2018-02-231-4/+4
| | | | | | | | | | | | | | | ModeSticky set Instead of calling Chmod directly on perm, stat the created file/dir to extract the actual permission bits which can be different from perm due to umask. Fixes #23120. Change-Id: I3e70032451fc254bf48ce9627e98988f84af8d91 Reviewed-on: https://go-review.googlesource.com/84477 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* net, os: don't wait for Close in blocking modeIan Lance Taylor2017-12-141-1/+1
| | | | | | | | | | Updates #7970 Updates #21856 Updates #23111 Change-Id: I0cd0151fcca740c40c3c976f941b04e98e67b0bf Reviewed-on: https://go-review.googlesource.com/83715 Reviewed-by: Russ Cox <rsc@golang.org>
* os: don't use test logger for GetwdIan Lance Taylor2017-12-121-9/+2
| | | | | | | | | | | | | | | | Otherwise, on systems for which syscall does not implement Getwd, a lot of unnecessary files and directories get added to the testlog, right up the root directory. This was causing tests on such systems to fail to cache in practice. Updates #22593 Change-Id: Ic8cb3450ea62aa0ca8eeb15754349f151cd76f85 Reviewed-on: https://go-review.googlesource.com/83455 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/go: invalidate cached test results if env vars or files changeRuss Cox2017-12-111-0/+3
| | | | | | | | | | | | | | | | | | When we write a cached test result, we now also write a log of the environment variables and files inspected by the test run, along with a hash of their content. Before reusing a cached test result, we recompute the hash of the content specified by the log, and only use the result if that content has not changed. This makes test caching behave correctly for tests that consult environment variables or stat or read files or directories. Fixes #22593. Change-Id: I8608798e73c90e0c1911a38bf7e03e1232d784dc Reviewed-on: https://go-review.googlesource.com/81895 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: calling Fd disables the SetDeadline methodsIan Lance Taylor2017-12-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The full truth seems too complicated to write in this method's doc, so I'm going with a simple half truth. The full truth is that Fd returns the descriptor in blocking mode, because that is historically how it worked, and existing programs would be surprised if the descriptor is suddenly non-blocking. On Unix systems whether a file is non-blocking or not is a property of the underlying file description, not of a particular file descriptor, so changing the returned descriptor to blocking mode also changes the existing File to blocking mode. Blocking mode works fine, althoug I/O operations now take up a thread. SetDeadline and friends rely on the runtime poller, and the runtime poller only works if the descriptor is non-blocking. So it's correct that calling Fd disables SetDeadline. The other half of the truth is that if the program is willing to work with a non-blocking descriptor, it could call syscall.SetNonblock(descriptor, true) to change the descriptor, and the original File, to non-blocking mode. At that point SetDeadline would start working again. I tried to write that in a way that is short and comprehensible but failed. Since deadlines mostly work on pipes, and there isn't much reason to call Fd on a pipe, and few people use SetDeadline, I decided to punt. Fixes #22934 Change-Id: I2e49e036f0bcf71f5365193831696f9e4120527c Reviewed-on: https://go-review.googlesource.com/81636 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* os: add deadline methods for File typeIan Lance Taylor2017-10-251-7/+18
| | | | | | | | | | | | | | Add SetDeadline, SetReadDeadline, and SetWriteDeadline methods to os.File, just as they exist today for the net package. Fixes #22114 Change-Id: I4d390d739169b991175baba676010897dc8568fa Reviewed-on: https://go-review.googlesource.com/71770 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
* os: don't refer directly to Sysfd in epipecheckIan Lance Taylor2017-09-241-6/+8
| | | | | | | | | | | | | | Instead record in the File whether it is stdout/stderr. This avoids a race between a call to epipecheck and closing the file. Fixes #21994 Change-Id: Ic3d552ffa83402136276bcb5029ec3e6691042c2 Reviewed-on: https://go-review.googlesource.com/65750 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: David Crawshaw <crawshaw@golang.org>