aboutsummaryrefslogtreecommitdiff
path: root/src/os/file.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-07-10os: trivial comment fixJakob Borg
"Geese" here looks like an autocorrect-o of "oses", I think writing it out makes more sense. Change-Id: Iba89a6c0b94657e2e93937cc153f07aea1d04e04 GitHub-Last-Rev: 4f3a780f327d6c807e9b154d781ee69a10d391e4 GitHub-Pull-Request: golang/go#74332 Reviewed-on: https://go-review.googlesource.com/c/go/+/682776 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-24os,internal/poll: disassociate handle from IOCP in File.Fdqmuntal
Go 1.25 will gain support for overlapped IO on handles passed to os.NewFile thanks to CL 662236. It was previously not possible to add an overlapped handle to the Go runtime's IO completion port (IOCP), and now happens on the first call the an IO method. This means that there is code that relies on the fact that File.Fd returns a handle that can always be associated with a custom IOCP. That wouldn't be the case anymore, as a handle can only be associated with one IOCP at a time and it must be explicitly disassociated. To fix this breaking change, File.Fd will disassociate the handle from the Go runtime IOCP before returning it. It is then not necessary to defer the association until the first IO method is called, which was recently added in CL 661955 to support this same use case, but in a more complex and unreliable way. Updates #19098. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-race,gotip-windows-amd64-longtest,gotip-windows-arm64 Change-Id: Id8a7e04d35057047c61d1733bad5bf45494b2c28 Reviewed-on: https://go-review.googlesource.com/c/go/+/664455 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.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-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-03-04os: guarantee min buffer size for ReadFile reads on /proc-like filesBrad Fitzpatrick
For instance, this fixes os.ReadFile on plan9's /net/iproute file. But it's not necessarily plan9-specific; Linux /proc and /sys filesystems can exhibit the same problems. Fixes #72080 Change-Id: I60b035913f583a91c6d84df95a6ea7b7ec2b3c92 Reviewed-on: https://go-review.googlesource.com/c/go/+/654315 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.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-03io/fs: add ReadLinkFS interfaceRoxy Light
Added implementations for *io/fs.subFS, os.DirFS, and testing/fstest.MapFS. Amended testing/fstest.TestFS to check behavior. Addressed TODOs in archive/tar and os.CopyFS around symbolic links. I am deliberately not changing archive/zip in this CL, since it currently does not resolve symlinks as part of its filesystem implementation. I am unsure of the compatibility restrictions on doing so, so figured it would be better to address independently. testing/fstest.MapFS now includes resolution of symlinks, with MapFile.Data storing the symlink data. The behavior change there seemed less intrusive, especially given its intended usage in tests, and it is especially helpful in testing the io/fs function implementations. Fixes #49580 Change-Id: I58ec6915e8cc97341cdbfd9c24c67d1b60139447 Reviewed-on: https://go-review.googlesource.com/c/go/+/385534 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Funda Secgin <fundasecgin33@gmail.com>
2024-11-20os: add Root.FSDamien Neil
For #67002 Change-Id: Ib687c92d645b9172677e5781a3e51ef1a0427c30 Reviewed-on: https://go-review.googlesource.com/c/go/+/629518 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-20os: add RootDamien Neil
Add os.Root, a type which represents a directory and permits performing file operations within that directory. For #67002 Change-Id: I863f4f1bc320a89b1125ae4237761f3e9320a901 Reviewed-on: https://go-review.googlesource.com/c/go/+/612136 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-19Revert "os: check for valid Windows path when creating files"George Adams
This reverts commit CL 618496. Reason for revert: https://github.com/golang/go/issues/54040#issuecomment-2485151973 Change-Id: I3bf27f7fdd475a005cb6aa190994153504e96fb5 Reviewed-on: https://go-review.googlesource.com/c/go/+/629595 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-10-29os: check for valid Windows path when creating filesGeorge Adams
Checks for a valid Windows path by ensuring the path doesn't end with trailing spaces or periods. Fixes #54040. Cq-Include-Trybots: luci.golang.try:gotip-windows-arm64 Change-Id: I266f79963c821f8cc474097d3e57c5645ad996fc Reviewed-on: https://go-review.googlesource.com/c/go/+/618496 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2024-10-18os: add precondition doc for Create and OpenFilexieyuschen
Fixes #69836 Change-Id: Ide243c2aa9c6f9d45976f728f97e32c4fbadb720 Reviewed-on: https://go-review.googlesource.com/c/go/+/619316 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-08-22os: improve Windows fixLongPathKir Kolyshkin
CL 574695 added caching the os.Chdir argument for Windows, and used the cached value to assess the length of the current working directory in addExtendedPrefix (used by fixLongPath). It did not take into account that Chdir can accept relative paths, and thus the pathLength calculation in addExtendedPrefix can be wrong. Let's only cache the os.Chdir argument if it's absolute, and clean the cache otherwise, thus improving the correctness of fixLongPath. For #41734 For #21782 For #36375 Change-Id: Ie24a5ed763a7aacc310666d2e4cbb8e298768670 Reviewed-on: https://go-review.googlesource.com/c/go/+/607437 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-02os: clarify Rename docs for renaming to a directoryIan Lance Taylor
Fixes #68690 Change-Id: Iebc27d5f385d787e568550a863f59f16c7a79fd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/602178 Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Rob Pike <r@golang.org>
2024-07-24os: document CopyFS behavior for symlinks in destinationDamien Neil
Also clarify the permissions of created files, and note that CopyFS will not overwrite files. Update a few places in documentation to use 0oXXX for octal consts. For #62484 Change-Id: I208ed2bde250304bc7fac2b93963ba57037e791e Reviewed-on: https://go-review.googlesource.com/c/go/+/600775 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-22os: check relative paths in UserConfigDir and UserCacheDirrhysd
Return errors by UserConfigDir and UserCacheDir when XDG environment variables contain relative paths. Fixes #68470 Change-Id: Ib36b56d73b066e002023be55ecfe74d5c0eedb15 GitHub-Last-Rev: c03f371a042c475a6f3f2259b06b140ade511404 GitHub-Pull-Request: golang/go#68471 Reviewed-on: https://go-review.googlesource.com/c/go/+/598655 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2024-04-26all: rename internal/safefilepath to internal/filepathliteDamien Neil
The safefilepath package was originally added to contain the FromFS function. We subsequently added FromFS to path/filepath as Localize. The safefilepath package now exists only to permit the os package to import Localize. Rename safefilepath to filepathlite to better indicate that it's a low-dependency version of filepath. Change-Id: I4c5f9b28e8581f841947b48c5cac9954cd0c9535 Reviewed-on: https://go-review.googlesource.com/c/go/+/581517 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: 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-04-01os: support relative paths in fixLongPathqmuntal
(This CL takes the tests and some ideas from the abandoned CL 263538). fixLongPath is used on Windows to process all path names before syscalls to switch them to extended-length format (with prefix \\?\) to workaround a historical limit of 260-ish characters. This CL updates fixLongPath to convert relative paths to absolute paths if the working directory plus the relative path exceeds MAX_PATH. This is necessary because the Windows API does not support extended-length paths for relative paths. This CL also adds support for fixing device paths (\\.\-prefixed), which were not previously normalized. Fixes #41734 Fixes #21782 Fixes #36375 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-amd64-race,gotip-windows-arm64 Co-authored-by: Giovanni Bajo <rasky@develer.com> Change-Id: I63cfb79f3ae6b9d42e07deac435b730d97a6f492 Reviewed-on: https://go-review.googlesource.com/c/go/+/574695 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.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>
2024-02-26path/filepath: add LocalizeDamien Neil
Add the Localize function, which takes an io/fs slash-separated path and returns an operating system path. Localize returns an error if the path cannot be represented on the current platform. Replace internal/safefile.FromFS with Localize, which serves the same purpose as this function. The internal/safefile package remains separate from path/filepath to avoid a dependency cycle with the os package. Fixes #57151 Change-Id: I75c88047ddea17808276761da07bf79172c4f6fc Reviewed-on: https://go-review.googlesource.com/c/go/+/531677 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-11-27io/fs, os: unify PathError.Path for dirFS.{ReadFile, ReadDir}Jes Cok
Fixes #64366 Change-Id: Ie78ab2cb9e11c0766665cd37fd7a26d36a1c24fa GitHub-Last-Rev: 3cb3bb84a0ccccc88ba30258f52f699ac1364a7b GitHub-Pull-Request: golang/go#64372 Reviewed-on: https://go-review.googlesource.com/c/go/+/544835 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Jes Cok <xigua67damn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-11-17net,os: arrange zero-copy of os.File and net.TCPConn to net.UnixConnAndy Pan
Fixes #58808 goos: linux goarch: amd64 pkg: net cpu: DO-Premium-Intel │ old │ new │ │ sec/op │ sec/op vs base │ Splice/tcp-to-unix/1024-4 3.783µ ± 10% 3.201µ ± 7% -15.40% (p=0.001 n=10) Splice/tcp-to-unix/2048-4 3.967µ ± 13% 3.818µ ± 16% ~ (p=0.971 n=10) Splice/tcp-to-unix/4096-4 4.988µ ± 16% 4.590µ ± 11% ~ (p=0.089 n=10) Splice/tcp-to-unix/8192-4 6.981µ ± 13% 5.236µ ± 9% -25.00% (p=0.000 n=10) Splice/tcp-to-unix/16384-4 10.192µ ± 9% 7.350µ ± 7% -27.89% (p=0.000 n=10) Splice/tcp-to-unix/32768-4 19.65µ ± 13% 10.28µ ± 16% -47.69% (p=0.000 n=10) Splice/tcp-to-unix/65536-4 41.89µ ± 18% 15.70µ ± 13% -62.52% (p=0.000 n=10) Splice/tcp-to-unix/131072-4 90.05µ ± 11% 29.55µ ± 10% -67.18% (p=0.000 n=10) Splice/tcp-to-unix/262144-4 170.24µ ± 15% 52.66µ ± 4% -69.06% (p=0.000 n=10) Splice/tcp-to-unix/524288-4 326.4µ ± 13% 109.3µ ± 11% -66.52% (p=0.000 n=10) Splice/tcp-to-unix/1048576-4 651.4µ ± 9% 228.3µ ± 14% -64.95% (p=0.000 n=10) geomean 29.42µ 15.62µ -46.90% │ old │ new │ │ B/s │ B/s vs base │ Splice/tcp-to-unix/1024-4 258.2Mi ± 11% 305.2Mi ± 8% +18.21% (p=0.001 n=10) Splice/tcp-to-unix/2048-4 492.5Mi ± 15% 511.7Mi ± 13% ~ (p=0.971 n=10) Splice/tcp-to-unix/4096-4 783.5Mi ± 14% 851.2Mi ± 12% ~ (p=0.089 n=10) Splice/tcp-to-unix/8192-4 1.093Gi ± 11% 1.458Gi ± 8% +33.36% (p=0.000 n=10) Splice/tcp-to-unix/16384-4 1.497Gi ± 9% 2.076Gi ± 7% +38.67% (p=0.000 n=10) Splice/tcp-to-unix/32768-4 1.553Gi ± 11% 2.969Gi ± 14% +91.17% (p=0.000 n=10) Splice/tcp-to-unix/65536-4 1.458Gi ± 23% 3.888Gi ± 11% +166.69% (p=0.000 n=10) Splice/tcp-to-unix/131072-4 1.356Gi ± 10% 4.131Gi ± 9% +204.72% (p=0.000 n=10) Splice/tcp-to-unix/262144-4 1.434Gi ± 13% 4.637Gi ± 4% +223.32% (p=0.000 n=10) Splice/tcp-to-unix/524288-4 1.497Gi ± 15% 4.468Gi ± 10% +198.47% (p=0.000 n=10) Splice/tcp-to-unix/1048576-4 1.501Gi ± 10% 4.277Gi ± 16% +184.88% (p=0.000 n=10) geomean 1.038Gi 1.954Gi +88.28% │ old │ new │ │ B/op │ B/op vs base │ Splice/tcp-to-unix/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/32768-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/65536-4 1.000 ± ? 0.000 ± 0% -100.00% (p=0.001 n=10) Splice/tcp-to-unix/131072-4 2.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Splice/tcp-to-unix/262144-4 4.000 ± 25% 0.000 ± 0% -100.00% (p=0.000 n=10) Splice/tcp-to-unix/524288-4 7.500 ± 33% 0.000 ± 0% -100.00% (p=0.000 n=10) Splice/tcp-to-unix/1048576-4 17.00 ± 12% 0.00 ± 0% -100.00% (p=0.000 n=10) geomean ² ? ² ³ ¹ all samples are equal ² summaries must be >0 to compute geomean ³ ratios must be >0 to compute geomean │ old │ new │ │ allocs/op │ allocs/op vs base │ Splice/tcp-to-unix/1024-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/2048-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/4096-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/8192-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/16384-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/32768-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/65536-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/131072-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/262144-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/524288-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ Splice/tcp-to-unix/1048576-4 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ geomean ² +0.00% ² ¹ all samples are equal ² summaries must be >0 to compute geomean Change-Id: I829061b009a0929a8ef1a15c183793c0b9104dde Reviewed-on: https://go-review.googlesource.com/c/go/+/472475 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-01os: fix PathError.Op for dirFS.OpenJoe Tsai
This appears to be a copy-paste error from CL 455362. The operation name used to be "open" but seems to have been accidentally changed to "stat". This CL reverts back to "open". Change-Id: I3fc5168095e2d9eee3efa3cc091b10bcf4e3ecde Reviewed-on: https://go-review.googlesource.com/c/go/+/539056 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-07-25os: ReadFile: don't check for re-allocation in the first iterationJabar Asadi
At the beginning of the for-loop iteration cap(data) > len(data) always. Therefore, in the first iteration, this check becomes unnecessary. we can move this check to after the read operation. Change-Id: I205e4a842ced74f31124b45a39b70523b56ad840 GitHub-Last-Rev: 2fdf25dff2e9984d3a8f8e5e612ea802c88e88a1 GitHub-Pull-Request: golang/go#60473 Reviewed-on: https://go-review.googlesource.com/c/go/+/498915 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-07-20os: remove unused containsAnyTobias Klauser
It's unused since CL 455716. Change-Id: I78bf7ad0e546c7dda8e78b911feb6399e1e6e088 Reviewed-on: https://go-review.googlesource.com/c/go/+/498235 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2023-05-24os: add dirFs.ReadDir to implement fs.ReadDirFS for DirFSTobias Klauser
Follow CL 416775 which added dirFs.ReadFile. Fixes #53761 Change-Id: Iec19a815ab7c37a3206be141518cc587a588de20 Reviewed-on: https://go-review.googlesource.com/c/go/+/498015 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2023-05-24os: implement fs.ReadFileFS for DirFSSean Liao
Use the os.ReadFile implementation to handle sysfs files not reporting size properly via stat. Fixes #53761 Change-Id: I6f34515e8a211e3659f4f6c3598fae7ec0c86975 Reviewed-on: https://go-review.googlesource.com/c/go/+/416775 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: hopehook <hopehook@golangcn.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-03-15os: don't hide all methods in recursive call to io.CopyIan Lance Taylor
In order to avoid a recursive call to ReadFrom, we were converting a *File to an io.Writer. But all we really need to do is hide the ReadFrom method. In particular, this gives us the option of adding a WriteTo method. For #58808 Change-Id: I20d3a45749d528c93c23267c467e607fc17dc83f Reviewed-on: https://go-review.googlesource.com/c/go/+/475535 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-03-13os: correct func name in WriteFile godoc commentTobias Klauser
Change-Id: Ideb70ce04f49ff676c20c2e1f0b43f1d7a6665dc Reviewed-on: https://go-review.googlesource.com/c/go/+/474355 Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2023-02-27os: ensure File.ReadFrom returns ErrClosed instead of the internal ↵Andy Pan
poll.ErrFileClosing Fixes #58622 Change-Id: Ibb80296c39614478c75cb6bb04b6d0695cb990d3 Reviewed-on: https://go-review.googlesource.com/c/go/+/469795 Run-TryBot: Andy Pan <panjf2000@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-01-31os: allow $HOME to not exist in TestUserHomeDirBryan C. Mills
This seems like a cleaner fix for the situation Debian has patched around with https://sources.debian.org/patches/golang-1.19/1.19.3-1/0001-Disable-test-for-UserHomeDir.patch/ Tested with 'GOCACHE=$(go env GOCACHE) HOME=/home/nobody go test os'. Change-Id: I9fd00da38b86df2edfcd8cb87629e2875573903e Reviewed-on: https://go-review.googlesource.com/c/go/+/456126 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-17os: document that Rename is not atomic on non-Unix platformsAlan Donovan
Windows provides no reliable way to rename files atomically. The Plan 9 implementation of os.Rename performs a deletion if the target exists. Change-Id: Ife5f9c97b21f48c11e300cd76d8c7f715db09fd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/462395 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Alan Donovan <adonovan@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-12-06os, net/http: avoid escapes from os.DirFS and http.Dir on WindowsDamien Neil
Do not permit access to Windows reserved device names (NUL, COM1, etc.) via os.DirFS and http.Dir filesystems. Avoid escapes from os.DirFS(`\`) on Windows. DirFS would join the the root to the relative path with a path separator, making os.DirFS(`\`).Open(`/foo/bar`) open the path `\\foo\bar`, which is a UNC name. Not only does this not open the intended file, but permits reference to any file on the system rather than only files on the current drive. Make os.DirFS("") invalid, with all file access failing. Previously, a root of "" was interpreted as "/", which is surprising and probably unintentional. Fixes CVE-2022-41720 Fixes #56694 Change-Id: I275b5fa391e6ad7404309ea98ccc97405942e0f0 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1663834 Reviewed-by: Tatiana Bradley <tatianabradley@google.com> Reviewed-by: Julie Qiu <julieqiu@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/455362 Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jenny Rakoczy <jenny@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/455716 Reviewed-by: Jenny Rakoczy <jenny@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-11-14os,syscall: File.Stat to use file handle for directories on Windowsqmuntal
Updates syscall.Open to support opening directories via CreateFileW. CreateFileW handles are more versatile than FindFirstFile handles. They can be used in Win32 APIs like GetFileInformationByHandle and SetFilePointerEx, which are needed by some Go APIs. Fixes #52747 Fixes #36019 Change-Id: I26a00cef9844fb4abeeb18d2f9d854162a146651 Reviewed-on: https://go-review.googlesource.com/c/go/+/405275 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Patrik Nyblom <pnyb@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-10os: document that WriteFile is not atomicRichard Tweed
Fixes #56173 Change-Id: I03a3ad769c99c0bdb78b1d757173d630879fd4dd GitHub-Last-Rev: e3e31fa0b95aba363b13c45f562e3a4c8b31f2cc GitHub-Pull-Request: golang/go#56282 Reviewed-on: https://go-review.googlesource.com/c/go/+/443495 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-11-09os: remove special casing of NUL in Windows file operationsDamien Neil
Some file operations, notably Stat and Mkdir, special cased their behavior when operating on a file named "NUL" (case-insensitive). This check failed to account for the many other names of the NUL device, as well as other non-NUL device files: "./nul", "//./nul", "nul.txt" (on some Windows versions), "con", etc. Remove the special case. os.Mkdir("NUL") now returns no error. This is consonant with the operating system's behavior: CreateDirectory("NUL") succeeds, as does "MKDIR NUL" on the command line. os.Stat("NUL") now follows the existing path for FILE_TYPE_CHAR devices, returning a FileInfo which correctly reports the file as being a character device. os.Stat and os.File.Stat have common elements of their logic unified. For #24482. For #24556. For #56217. Change-Id: I7e70f45901127c9961166dd6dbfe0c4a10b4ab64 Reviewed-on: https://go-review.googlesource.com/c/go/+/448897 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
2022-10-28os: don't include DirFS argument in DirFS errorsIan Lance Taylor
Otherwise we wind up mixing GOOS paths with slash separated paths. Change-Id: I63dd733cbdb0668effbc030cfd58945008732d9e Reviewed-on: https://go-review.googlesource.com/c/go/+/446115 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-06os: if dirFS.Open fails, undo use of backslashes in error messageIan Lance Taylor
This fixes a bug introduced by CL 426094 that caused the golang.org/x/website/internal/web tests to fail. Fixes #56034 Change-Id: Ic64967c6d440ad260b7283a18972b20023320ab6 Reviewed-on: https://go-review.googlesource.com/c/go/+/437976 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: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-10-02os: use backslashes for DirFS on WindowsIan Lance Taylor
Otherwise DirFS of a UNC path does not work. Fixes #54694 Change-Id: I82c1c436f7c26b3935c2cc4fd238daf094fc4d86 Reviewed-on: https://go-review.googlesource.com/c/go/+/426094 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: hopehook <hopehook@golangcn.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-09-08os: use unsafe.{Slice,StringData} instead of unsafeheader packageTobias Klauser
Change-Id: I213b078effa4b7049c44498d651de5b938e5404b Reviewed-on: https://go-review.googlesource.com/c/go/+/428779 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: hopehook <hopehook@golangcn.org> Run-TryBot: hopehook <hopehook@golangcn.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2022-06-07os: document that Chdir affects fs.FS returned by DirFS with a relative pathDan Kortschak
Fixes #47214. Change-Id: I6fdc1c4340c0943b825ac22e311179ad1cf30915 Reviewed-on: https://go-review.googlesource.com/c/go/+/410334 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-26os: document DirFS implements fs.StatFShopehook
Fixes #51856 Change-Id: I8328d73bbb7bc166d58281180b64785a634e9bab Reviewed-on: https://go-review.googlesource.com/c/go/+/394555 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-09os: clarify that File.{Read,Write} use the bufferIan Lance Taylor
Fixes #49470 Change-Id: I81fd4b0e2eef1d8d430b5d1d10c4f824e803a75c Reviewed-on: https://go-review.googlesource.com/c/go/+/362335 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-04-06os: implement fs.StatFS for os.DirFSCharlie Moog
Change-Id: I1d7382bf522aeda7148431b348f6ab9a162be097 Reviewed-on: https://go-review.googlesource.com/c/go/+/304531 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Robert Griesemer <gri@golang.org>
2021-02-25os: avoid allocation in File.WriteStringJosh Bleecher Snyder
Instead of alloc+copy to convert the string to a byte slice, do an unsafe conversion. Rely on the kernel not to scribble on the buffer during the write. Fixes #42406 Change-Id: I66f4838b43a11bcc3d67bbfa1706726318d55343 Reviewed-on: https://go-review.googlesource.com/c/go/+/268020 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>