aboutsummaryrefslogtreecommitdiff
path: root/src/os/path_windows_test.go
AgeCommit message (Collapse)Author
2025-10-21os: support deleting read-only files in RemoveAll on older Windows versionsqmuntal
The Windows implementation of RemoveAll supports deleting read-only files only on file systems that supports POSIX semantics and on newer Windows versions (Windows 10 RS5 and latter). For all the other cases, the read-only bit was not clearer before deleting read-only files, so they fail to delete. Note that this case was supported prior to CL 75922, which landed on Go 1.25. Fixes #75922 Change-Id: Id6e6477f42e1952d08318ca3e4ab7c1648969f66 Reviewed-on: https://go-review.googlesource.com/c/go/+/713480 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.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-09-04all: use t.Chdir in testsKir Kolyshkin
Change-Id: I5bc514bedeb1155e6db52e37736fd6101774aea0 Reviewed-on: https://go-review.googlesource.com/c/go/+/529896 Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@golang.org>
2024-04-23all: fix some typos in commentsracequite
This change fixes some typographic errors that I found in various packages. Change-Id: Ie2d0316f0137d6521496d389a9777659ae22128b GitHub-Last-Rev: 0307b03d50f664a00a4afa5afa08a35efb7f3045 GitHub-Pull-Request: golang/go#66917 Reviewed-on: https://go-review.googlesource.com/c/go/+/580077 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Commit-Queue: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>
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-18os: support UNC paths and .. segments in fixLongPathqmuntal
This CL reimplements fixLongPath using syscall.GetFullPathName instead of a custom implementation that was not handling UNC paths and .. segments correctly. It also fixes a bug here multiple trailing \ were removed instead of replaced by a single one. The new implementation is slower than the previous one, as it does a syscall and needs to convert UTF-8 to UTF-16 (and back), but it is correct and should be fast enough for most use cases. goos: windows goarch: amd64 pkg: os cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ LongPath-12 1.007µ ± 53% 4.093µ ± 109% +306.41% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ LongPath-12 576.0 ± 0% 1376.0 ± 0% +138.89% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ LongPath-12 2.000 ± 0% 3.000 ± 0% +50.00% (p=0.000 n=10) Fixes #41734. Change-Id: Iced5cf47f56f6ab0ca74a6e2374c31a75100902d Reviewed-on: https://go-review.googlesource.com/c/go/+/570995 Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-07runtime,internal/syscall/windows: remove long path support checkqmuntal
The runtime currently enables long path support process-wide by updating the process environment block (PEB). It then tries to create a file using a long path to check if the PEB update made any difference. There hasn't been any report that the PEB update was not effective, and the check itself is quite tricky, so it's time to remove it. While here, linkname `runtime.canUseLongPaths` to a variable in internal/syscall/windows instead of the os package so it is easier to consume from other packages. Change-Id: I549380b7f2c242dc4db20d5be603840282de69b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/536495 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com>
2023-08-09os: make MkdirAll support volume namesqmuntal
MkdirAll fails to create directories under root paths using volume names (e.g. //?/Volume{GUID}/foo). This is because fixRootDirectory only handle extended length paths using drive letters (e.g. //?/C:/foo). This CL fixes that issue by also detecting volume names without path separator. Updates #22230 Fixes #39785 Change-Id: I813fdc0b968ce71a4297f69245b935558e6cd789 Reviewed-on: https://go-review.googlesource.com/c/go/+/517015 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-01-19os: clean up testsBryan C. Mills
- Use testenv.Command instead of exec.Command to try to get more useful timeout behavior. - Parallelize tests that appear not to require global state. (And add explanatory comments for a few that are not parallelizable for subtle reasons.) - Consolidate some “Helper” tests with their parent tests. - Use t.TempDir instead of os.MkdirTemp when appropriate. - Factor out subtests for repeated test helpers. For #36107. Updates #22315. Change-Id: Ic24b6957094dcd40908a59f48e44c8993729222b Reviewed-on: https://go-review.googlesource.com/c/go/+/458015 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2021-04-09os: replace os.MkdirTemp with T.TempDirManlio Perillo
Updates #45402 Change-Id: Ib8e62a13ddff884e4d34b3a0fdc9a10db2b68da6 Reviewed-on: https://go-review.googlesource.com/c/go/+/308109 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2021-03-23runtime: support long paths without fixup on Windows 10 >= 1607Jason A. Donenfeld
Windows 10 >= 1607 allows CreateFile and friends to use long paths if bit 0x80 of the PEB's BitField member is set. In time this means we'll be able to entirely drop our long path hacks, which have never really worked right (see bugs below). Until that point, we'll simply have things working well on recent Windows. Updates #41734. Updates #21782. Updates #36375. Change-Id: I765de6ea4859dd4e4b8ca80af7f337994734118e Reviewed-on: https://go-review.googlesource.com/c/go/+/291291 Trust: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-11-14os: handle backslash and slash both in the path on WindowsYasuhiro Matsumoto
Fixes #35492 Change-Id: I00dce8fd1228f809e0c61013ac4de7a5953cbbf9 Reviewed-on: https://go-review.googlesource.com/c/go/+/206997 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-26all: use strings.ReplaceAll and bytes.ReplaceAll where applicableBrad Fitzpatrick
I omitted vendor directories and anything necessary for bootstrapping. (Tested by bootstrapping with Go 1.4) Updates #27864 Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a Reviewed-on: https://go-review.googlesource.com/137856 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-18os: make MkdirAll support path in extended-length formMansour Rahimi
Calling MkdirAll on paths in extended-length form (\\?\-prefixed) failed. MkdirAll calls itself recursively with parent directory of given path in its parameter. It finds parent directory by looking for delimiter in the path, and taking the left part. When path is in extended-length form, it finds empty path at the end. Here is a sample of path in extended-length form: \\?\c:\foo\bar This change fixes that by passing trailing path separator to MkdirAll (so it works for path like \\?\c:\). Fixes #22230 Change-Id: I363660b262588c5382ea829773d3b6005ab8df3c Reviewed-on: https://go-review.googlesource.com/86295 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-08os: on Windows, don't fix long paths that aren't longBrad Fitzpatrick
Notably, don't allocate. Follow-up to https://golang.org/cl/32451 which added long path cleaning. Updates #3358 Change-Id: I89c59cbd660d0a030f31b6acd070fa9f3250683b Reviewed-on: https://go-review.googlesource.com/32886 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2016-11-07os: use extended-length paths on Windows when possibleQuentin Smith
Windows has a limit of 260 characters on normal paths, but it's possible to use longer paths by using "extended-length paths" that begin with `\\?\`. This commit attempts to transparently convert an absolute path to an extended-length path, following the subtly different rules those paths require. It does not attempt to handle relative paths, which continue to be passed to the operating system unmodified. This adds a new test, TestLongPath, to the os package. This test makes sure that it is possible to write a path at least 400 characters long and runs on every platform. It also tests symlinks and hardlinks, though symlinks are not testable with our builder configuration. HasLink is moved to internal/testenv so it can be used by multiple tests. https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx has Microsoft's documentation on extended-length paths. Fixes #3358. Fixes #10577. Fixes #17500. Change-Id: I4ff6bb2ef9c9a4468d383d98379f65cf9c448218 Reviewed-on: https://go-review.googlesource.com/32451 Run-TryBot: Quentin Smith <quentin@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>