aboutsummaryrefslogtreecommitdiff
path: root/src/os/file_unix.go
AgeCommit message (Collapse)Author
2025-07-18os: revert the use of AddCleanup to close files and rootsCarlos Amedee
This reverts commit fdaac84480b02e600660d0ca7c15339138807107. Updates #70907 Updates #74574 Updates #74642 Reason for revert: Issue #74574 Change-Id: I7b55b85736e4210d9b6f3fd7a24050ac7bdefef9 Reviewed-on: https://go-review.googlesource.com/c/go/+/688435 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-04-04os: support overlapped IO with NewFileqmuntal
The runtime/poll package has just gained support for overlapped IO, see CL 660595 and CL 661955. The only remaining piece was making it visible to user code via os.NewFile. Some of the poll.FD.Init responsibility has been moved to os.NewFile to avoid unnecessary syscalls for the common case of using os.Open, os.Create, os.OpenFile, and os.Pipe, where we know that the file is not opened for overlapped IO. Some internal/poll tests have been moved to the os package to exercise public APIs rather than internal ones. The os.NewFile function definition has been moved into an OS-agnostic file to avoid having duplicated documentation and ensure that the caller is aware of its behavior across all platforms. Closes #19098. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-amd64-race,gotip-windows-arm64 Change-Id: If043f8b34d588cd4b481777203107ed92d660fd9 Reviewed-on: https://go-review.googlesource.com/c/go/+/662236 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Damien Neil <dneil@google.com>
2025-03-07os: remove unused testingForceReadDirLstatTobias Klauser
It was introduced in CL 261540 but never set by any test. Change-Id: Id2a59c58ed510b6041cc51ce47ab79199a60b215 Reviewed-on: https://go-review.googlesource.com/c/go/+/655797 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2025-03-06os: more godoc linksOlivier Mengué
Add missing links to *PathError. Also a few links to O_ flags and Mode and syscall constants. Change-Id: Ic6ec5780a44942050a83ed07dbf16d6fa9f83eb9 Reviewed-on: https://go-review.googlesource.com/c/go/+/655375 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2025-02-13os: consolidate and clarify File.Fd docsIan Lance Taylor
Change-Id: Id062b969fe7d6908a0797b36a4a379e4d46ba557 Reviewed-on: https://go-review.googlesource.com/c/go/+/648516 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-02-13os: use AddCleanup to close filesCarlos Amedee
This changes the finalizer mechanism used to close files from runtime.SetFinalizer to runtime.AddCleanup. Updates #70907 Change-Id: I47582b81b0ed69609dd9dac158ec7bb8819c8c77 Reviewed-on: https://go-review.googlesource.com/c/go/+/638555 Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-16os: add and use ignoringEINTR2Tobias Klauser
Copy ignoringEINTR2 from internal/poll and make use of it to remove open-coded implementations. Change-Id: I8802862f2012980f2af445b75eb45bb5a97bcc2a Reviewed-on: https://go-review.googlesource.com/c/go/+/627479 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-22os: openDir: add O_DIRECTORY flag for unixKir Kolyshkin
With this, ReadDir will fail a tad earlier (on open rather than on readdir syscall). This should be the only effect of this change. Change-Id: Icf2870f47ea6c19aad29670e78ba9bfcc13c0ac3 Reviewed-on: https://go-review.googlesource.com/c/go/+/588915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-05-29os: RemoveAll: fix symlink race for unixKir Kolyshkin
Since all the platforms now support O_DIRECTORY flag for open, it can be used to (together with O_NOFOLLOW) to ensure we open a directory, thus eliminating the need to call stat before open. This fixes the symlink race, when a directory is replaced by a symlink in between stat and open calls. While at it, rename openFdAt to openDirAt, because this function is (and was) meant for directories only. NOTE Solaris supports O_DIRECTORY since before Solaris 11 (which is the only version Go supports since supported version now), and Illumos always had it. The only missing piece was O_DIRECTORY flag value, which is taken from golang.org/x/sys/unix. Updates #52745. Change-Id: Ic1111d688eebc8804a87d39d3261c2a6eb33f176 Reviewed-on: https://go-review.googlesource.com/c/go/+/588495 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Aleksa Sarai <cyphar@cyphar.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-04-15os: make File.Readdir et al concurrency-safeAlan Donovan
Before, all methods of File (including Close) were safe for concurrent use (I checked), except the three variants of ReadDir. This change makes the ReadDir operations atomic too, and documents explicitly that all methods of File have this property, which was already implied by the package documentation. Fixes #66498 Change-Id: I05c88b4e60b44c702062e99ed8f4a32e7945927a Reviewed-on: https://go-review.googlesource.com/c/go/+/578322 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-19os: kick FIFOs with O_NONBLOCK out of the kqueue on Darwin/iOSAndy Pan
Fixes #66239 Change-Id: I8210682c0cf4285b950e9fabe687b7ad2369835c Reviewed-on: https://go-review.googlesource.com/c/go/+/570397 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2024-03-19os: use ignoringEINTR in openFileNolog and openDirNologAndy Pan
Change-Id: Ie8fa25d5e326efd7d3c9b72203783110d9e22ce8 Reviewed-on: https://go-review.googlesource.com/c/go/+/572215 Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-16os: don't try to make the directory FD non-blocking in os.ReadDirPeter Collingbourne
This will fail because epoll_ctl() fails on directory FDs, so we end up issuing unnecessary syscalls. My test program that calls filepath.WalkDir on a large directory tree runs 1.23 ± 0.04 times faster than with the original implementation. Change-Id: Ie33d798c48057a7b2d0bacac80fcdde5b5a8bb1b Reviewed-on: https://go-review.googlesource.com/c/go/+/570877 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-02-26os: add available godoc linkcui fliter
Change-Id: I430c9a7c4936d7a8c8c787aa63de9a796d20fdf3 Reviewed-on: https://go-review.googlesource.com/c/go/+/539597 Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-12-07os: document Readlink behavior for relative linksBryan C. Mills
Also provide a runnable example to illustrate that behavior. This should help users to avoid the common mistake of expecting os.Readlink to return an absolute path. Fixes #57766. Change-Id: I8f60aa111ebda0cae985758615019aaf26d5cb41 Reviewed-on: https://go-review.googlesource.com/c/go/+/546995 Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2023-05-24os: explicitly check for invalid FD in NewFileMichael Pratt
CL 497075 refactored NewFile to unconditionally dereference the file returned by newFile. However, newFile can return nil if passed a negative FD, which now causes a crash. Resolve this by moving the invalid check earlier in NewFile, which also lets us avoid a useless fcntl syscall on a negative FD. Since we convert to int to check sign, adjust newFile to take an int rather than uintptr, which cleans up a lot of conversions. Fixes #60406 Change-Id: I382a74e22f1cc01f7a2dcf1ff4efca6a79c4dd57 Reviewed-on: https://go-review.googlesource.com/c/go/+/497877 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-05-23os: avoid second fcntl syscall in NewFile on unixTobias Klauser
CL 494915 introduced an additional fcntl(F_GETFL) syscall to determine whether the file is in append-only mode. The existing unix.IsNonblock call also issues an fcntl(F_GETFL) syscall. The two can be combined and both the append-only mode and the non-blocking flags can be determined from that syscall's result. Change-Id: I915589ed94e079f6abaa2fd0032ef01f78698f7f Reviewed-on: https://go-review.googlesource.com/c/go/+/497075 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2023-05-20net, os: net.Conn.File.Fd should return a blocking descriptorIan Lance Taylor
Historically net.Conn.File.Fd has returned a descriptor in blocking mode. That was broken by CL 495079, which changed the behavior for os.OpenFile and os.NewFile without intending to affect net.Conn.File.Fd. Use a hidden os entry point to preserve the historical behavior, to ensure backward compatibility. Change-Id: I8d14b9296070ddd52bb8940cb88c6a8b2dc28c27 Reviewed-on: https://go-review.googlesource.com/c/go/+/496080 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-05-18os: set File.appendMode in NewFile if file was opened with O_APPENDTobias Klauser
To allow skipping the use of the copy_file_range syscall on Linux which isn't supported for destination files opened with O_APPEND, see comment in (*File).readFrom and https://man7.org/linux/man-pages/man2/copy_file_range.2.html#ERRORS Fixes #60181 Change-Id: Ie0b0050faab16858412928a3d1f96442619581eb Reviewed-on: https://go-review.googlesource.com/c/go/+/494915 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2023-05-17os: if descriptor is non-blocking, retain that in Fd methodIan Lance Taylor
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>
2023-05-12os, runtime: remove unused implementations of os.sigpipeIan Lance Taylor
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>
2023-05-11os: make Chtimes accept empty time values to skip file time modificationConstantin Konstantinidis
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>
2023-05-04all: add String for fs.{FileInfo,DirEntry} implementationsIan Lance Taylor
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>
2023-04-07os: add wasip1 supportJohan Brandhorst-Satzkorn
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>
2023-02-27os: don't try to put directory into non-blocking modeIan Lance Taylor
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>
2022-08-18os: only add file descriptors which are set to non-blocking mode to the ↵Yuval Pavel Zholkover
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>
2022-04-05all: replace `` and '' with “ (U+201C) and ” (U+201D) in doc commentsRuss Cox
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>
2022-03-29all: use new "unix" build tag where appropriateIan Lance Taylor
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>
2021-10-28all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor)Russ Cox
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>
2021-05-02os: document that Windows Symlink to missing target creates file symlinkIan Lance Taylor
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>
2021-04-13all: simplify the spelling of LinuxBrad Fitzpatrick
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>
2021-04-03os: reuse readdir buffers on unix with a sync.PoolTom Thorogood
(*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>
2021-02-20all: go fmt std cmd (but revert vendor)Russ Cox
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>
2021-01-26os: further document limitations around naked file descriptorsVictor Michel
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>
2020-10-20os: use keyed literals for PathErrorRuss Cox
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>
2020-10-20os: add File.ReadDir method and DirEntry typeRuss Cox
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>
2020-09-28os: fix SyscallConn typos in the File.Fd commentsChangkun Ou
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>
2020-09-27os: document and emphasize a potential misuse of File.FdChangkun Ou
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>
2020-09-23all: add GOOS=iosCherry Zhang
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>
2020-08-19os, internal/poll: loop on EINTR for all file syscallsIan Lance Taylor
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>
2020-06-08os: always check for EINTR in calls to openIan Lance Taylor
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>
2020-03-20os: merge common Unix/Windows methodsIan Lance Taylor
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>
2020-03-01os: seek should invalidate any cached directory readsKeith Randall
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>
2019-12-05os: reset dirinfo when seeking on DarwinKeith Randall
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>
2019-11-01os: allow case only renames on case-insensitive filesystemsAudrius Butkevicius
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>
2019-10-09all: remove the nacl port (part 1)Brad Fitzpatrick
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>
2019-06-05doc: clarify safety of multiple and concurent os.(*File).Close() callsAlex Myasoedov
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>
2019-04-19os: disable the use of netpoll on directories as well on *BSDsYuval Pavel Zholkover
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>
2019-03-27os: reject WriteAt if file opened in append modeLE Manh Cuong
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>
2019-03-12os: drop special case for FreeBSD 10.4 in newFileTobias Klauser
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>