aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath
AgeCommit message (Collapse)Author
2023-01-25os: make Lstat for symlinks on Windows consistent with POSIXBryan C. Mills
This also makes path/filepath.Walk more consistent between Windows and POSIX platforms. According to https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/basedefs/V1_chap04.html#tag_04_12 symlinks in a path that includes a trailing slash must be resolved before a function acts on that path. POSIX defines an lstat function, whereas the Win32 API does not, so Go's os.Lstat should follow the (defined) POSIX semantics instead of doing something arbitrarily different. CL 134195 added a test for the correct POSIX behavior when os.Lstat is called on a symlink. However, the test turned out to be broken on Windows, and when it was fixed (in CL 143578) it was fixed with different Lstat behavior on Windows than on all other platforms that support symlinks. In #50807 we are attempting to provide consistent symlink behavior for cmd/go. This unnecessary platform difference, if left uncorrected, will make that fix much more difficult. CL 460595 reworked the implementation of Stat and Lstat on Windows, and with the new implementation this fix is straightforward. For #50807. Updates #27225. Change-Id: Ia28821aa4aab6cefa021da2d9b803506cdb2621b Reviewed-on: https://go-review.googlesource.com/c/go/+/463177 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-01-24path/filepath: remove extra Clean call in EvalSymlinks on Windowsqmuntal
EvalSymlinks calls Clean twice, one in walkSymlinks and another in toNorm. The later is not necessary, as toNorm is only called by EvalSymlinks and just after walkSymlinks cleans the path without any path manipulation in between. Change-Id: Ibdb782c7eed59468f0ebb913e98d2a7db0df010d Reviewed-on: https://go-review.googlesource.com/c/go/+/454615 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
2023-01-20path/filepath: fix evaluation of symlinks to paths under /tmp on macOSmatsuyoshi30
For symlinks created from symlinks under the root directory created as the relative path (e.g., symbolic links under /tmp), we update vol and volLen. Fixes #57905 Change-Id: I45affd1db3b93109de51bf19b181f3cdba061109 Reviewed-on: https://go-review.googlesource.com/c/go/+/461761 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-12-02path/filepath: make Join("c:", "/a") return "c:/a" againDamien Neil
Historically, on Windows filepath.Join("c:", elt) does not insert a path separator between "c:" and elt, but preserves leading slashes in elt. Restore this behavior, which was inadvertently changed by CL 444280. Fixes #56988 Change-Id: Id728bf311f4093264f8c067d8b801ea9ebef5b5f Reviewed-on: https://go-review.googlesource.com/c/go/+/453497 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-11-17path/filepath: detect Windows CONIN$ and CONOUT$ paths in IsLocalDamien Neil
CreateFile creates a handle to the console input or screen buffer when opening a file named CONIN$ or CONOUT$: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#consoles Detect these paths as non-local. For #56219. Change-Id: Ib09e76a110d6ec09aef8038074b9bcbae09d00d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/451657 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-17path/filepath: remove IsLocal tests dependent on Windows versionDamien Neil
Don't test IsLocal("nul.txt"), since whether this name is reserved or not is version-dependent. Change-Id: Ifff3edc77454e052080e325871c08bbba49e692c Reviewed-on: https://go-review.googlesource.com/c/go/+/451222 Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-16path/filepath: add IsLocalDamien Neil
IsLocal reports whether a path lexically refers to a location contained within the directory in which it is evaluated. It identifies paths that are absolute, escape a directory with ".." elements, and (on Windows) paths that reference reserved device names. For #56219. Change-Id: I35edfa3ce77b40b8e66f1fc8e0ff73cfd06f2313 Reviewed-on: https://go-review.googlesource.com/c/go/+/449239 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Joedian Reid <joedian@golang.org>
2022-11-09Revert "path/filepath: change IsAbs("NUL") to return true"Damien Neil
This reverts commit d154ef60a0c88be98c70bbe1c5735fb7b1f45250. This change made IsAbs return true for certain reserved filenames, but does not consistently detect reserved names. For example, "./COM1", "//./COM1", and (on some Windows versions) "COM1.txt" all refer to the COM1 device, but IsAbs detects none of them. Since NUL is not an absolute path, do not attempt to detect it or other device paths in IsAbs. See #56217 for more discussion of IsAbs and device paths. For #56217. Change-Id: If4bf81c7e1a2e8842206c7c5268555102140dae8 Reviewed-on: https://go-review.googlesource.com/c/go/+/448898 Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2022-11-09path/filepath: detect all forms of \\ volume paths on WindowsDamien Neil
Previously, the volumeNameLen function checked for UNC paths starting with two slashes, a non-'.' character, and another slash. This misses volume names such as "\\.\C:\". The previous check for volume names rejects paths beginning with "\\.". This is incorrect, because while these names are not UNC paths, "\\.\C:\" is a DOS device path prefix indicating the C: device. It also misses UNC path prefixes in the form "\\.\UNC\server\share\". The previous check for UNC paths also rejects any path with an empty or missing host or share component. This leads to a number of possibly-incorrect behaviors, such as Clean(`\\a`) returning `\a`. Converting the semantically-significant `\\` prefix to a single `\` seems wrong. Consistently treat paths beginning with two separators as having a volume prefix. Update VolumeName to detect DOS device paths (`\\.\` or `\\?\`), DOS device paths linking to UNC paths (`\\.\UNC\Server\Share` or `\\?\UNC\Server\Share`), and UNC paths (`\\Server\Share\`). Clean(`\\a`) = `\\a` Join(`\\`, `a`, `b`) = `\\a\b` In addition, normalize path separators in VolumeName for consistency with other functions which Clean their result. Fixes #56336 Change-Id: Id01c33029585bfffc313dcf0ad42ff6ac7ce42fd Reviewed-on: https://go-review.googlesource.com/c/go/+/444280 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-11-09all: add missing copyright headercui fliter
Change-Id: Ia5a090953d324f0f8aa9c1808c88125ad5eb6f98 Reviewed-on: https://go-review.googlesource.com/c/go/+/448955 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2022-09-23path/filepath: optimize isReservedNameJoe Tsai
A linear search through a list of 22 strings takes ~80ns. A quick check for 3-4 byte strings reduces this check to 2ns for a vast majority of inputs. In the event of a name match, the new logic is either just as fast (for "CON") or 10x faster (for "LPT9"). Change-Id: I412fa73beebd7c81dc95f9ed12c35ca1d5d6baf0 Reviewed-on: https://go-review.googlesource.com/c/go/+/433175 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-14path/filepath: document that WalkDir uses OS pathsIan Lance Taylor
Fixes #52812 Change-Id: Idb70d0540bbf9ecdc64293c62a23f07ee3be883c Reviewed-on: https://go-review.googlesource.com/c/go/+/405615 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Caleb Spare <cespare@gmail.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-25path/filepath, io/fs: add SkipAllPaschalis Tsilias
Fixes #47209 Change-Id: If75b0dd38f2c30a23517205d80c7a6683a5c921c Reviewed-on: https://go-review.googlesource.com/c/go/+/363814 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: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-07-12path/filepath: fix stack exhaustion in GlobJulie Qiu
A limit is added to the number of path separators allowed by an input to Glob, to prevent stack exhaustion issues. Thanks to Juho Nurminen of Mattermost who reported the issue. Fixes CVE-2022-30632 Fixes #53416 Change-Id: I1b9fd4faa85411a05dbc91dceae1c0c8eb021f07 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1498176 Reviewed-by: Roland Shoemaker <bracewell@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/417066 Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Knyszek <mknyszek@google.com>
2022-05-24path/filepath: do not remove prefix "." when following path contains ":".Yasuhiro Matsumoto
Fixes #52476 Change-Id: I9eb72ac7dbccd6322d060291f31831dc389eb9bb Reviewed-on: https://go-review.googlesource.com/c/go/+/401595 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-09path/filepath: simplify EvalSymlinks for plan9miller
Plan 9 doesn't have symbolic links, so EvalSymlinks can be simplified just to check validity of the path and call Clean. This saves a lot of redundant file system activity. Updates #50775 Change-Id: I84c24ef1d5e6e38fd19df2d37c72fbf883f0140d Reviewed-on: https://go-review.googlesource.com/c/go/+/404954 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: David du Colombier <0intro@gmail.com> Reviewed-by: David du Colombier <0intro@gmail.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-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-04-01all: remove trailing blank doc comment linesRuss Cox
A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@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>
2022-03-28io/fs, path/filepath: honor SkipDir on second WalkDirFunc error callIan Lance Taylor
Fixes #51617 Change-Id: I03e9e575d9bad1481e7e4f051b50a077ba5f2fe0 Reviewed-on: https://go-review.googlesource.com/c/go/+/392154 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2022-03-18internal/testenv: add GOROOT and use it to fix tests broken with -trimpathBryan C. Mills
This fixes many (but not all) of the tests that currently fail (due to a bogus path reported by runtime.GOROOT) when run with 'go test -trimpath std cmd'. Updates #51461 Change-Id: Ia2cc05705529c4859e7928f32eeceed647f2e986 Reviewed-on: https://go-review.googlesource.com/c/go/+/391806 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
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-08-18path/filepath: change IsAbs to treat \\host\share as an absolute pathYasuhiro Matsumoto
Fixes #47123 Change-Id: I2226b8a9ea24cd88171acfbaffea2566309416de Reviewed-on: https://go-review.googlesource.com/c/go/+/334809 Trust: Alex Brainman <alex.brainman@gmail.com> Trust: Hajime Hoshi <hajimehoshi@gmail.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2021-06-30path/filepath: deflake TestEvalSymlinksAboveRoot on darwinJosh Bleecher Snyder
On darwin, under load, it appears that the system occasionally deletes the temp dir mid-test. Don't fail the test when that happens. It would be nice to fix this in a deeper way. See golang.org/cl/332009 for some discussion. In the meantime, this will at least stop the flakiness. Updates #37910 Change-Id: I6669e466fed9abda4a87ca88345c04cd7986b41e Reviewed-on: https://go-review.googlesource.com/c/go/+/332009 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-05-02path/filepath: fix documentation typo (was "each each")Vitaly Zdanevich
Change-Id: I8dcf6c4489e16e91b8685c31569297cfeb700f9d GitHub-Last-Rev: f6b40e029874230789a7ae2b750a42a355ae42cf GitHub-Pull-Request: golang/go#45905 Reviewed-on: https://go-review.googlesource.com/c/go/+/316009 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Kevin Burke <kev@inburke.com> Trust: Kevin Burke <kev@inburke.com>
2021-04-10path/filepath: replace os.MkdirTemp with T.TempDirManlio Perillo
Add the tempDirCanonical function, for tests that need a temporary directory that does not contain symlinks. Updates #45402 Change-Id: I3d08ef32ef911331544acce3d7d013b4c3382960 Reviewed-on: https://go-review.googlesource.com/c/go/+/308011 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-04-06path/filepath: replace os.MkdirTemp with T.TempDirianwoolf
Change-Id: I6d78e0e742cb0e7f5ea3f430e9cec0f5d1ee03e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/307652 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: Emmanuel Odeke <emmanuel@orijtech.com>
2021-04-04os, path/filepath: use T.Cleanup to restore the original working directoryianwoolf
Updates #45182 Change-Id: Iaf3bdcc345c72fa9669fdc99908ada4e89904edd Reviewed-on: https://go-review.googlesource.com/c/go/+/306290 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-25path/filepath: make Rel handle Windows UNC shareAman Gupta
Fixes #41230 Change-Id: Iea15e4ae6d56328333fd22de5d78dfcad78ef1bc Reviewed-on: https://go-review.googlesource.com/c/go/+/253197 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Trust: Alex Brainman <alex.brainman@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.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>
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>
2020-11-06io/fs: add WalkDirRuss Cox
This commit is a copy of filepath.WalkDir adapted to use fs.FS instead of the native OS file system. It is the last implementation piece of the io/fs proposal. The original io/fs proposal was to adopt filepath.Walk, but we have since introduced the more efficient filepath.WalkDir (#42027), so this CL adopts that more efficient option instead. (The changes in path/filepath bring the two copies more in line with each other. The main change is unembedding the field in statDirEntry, so that the fs.DirEntry passed to the WalkDirFunc for the root of the tree does not have any extra methods.) For #41190. Change-Id: I9359dfcc110338c0ec64535f22cafb38d0b613a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/243916 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-11-06path/filepath: add WalkDirRuss Cox
WalkDir is like Walk but can use ReadDir to read directories, instead of Readdirnames + Lstat on every entry, which is usually a significant performance improvement. (The Lstat can still happen if the walk function calls d.Info.) Fixes #42027. [Replay of CL 266240 after it was reverted due to accidentally enabling on Windows a test that does not work on Windows. The original code only ran the test on os.Getuid() > 0. The rolled-back CL skipped the test on os.Getuid() == 0. But on Windows, os.Getuid(), it turns out, always returns -1. So what looked like a test for root was also excluding Windows. This CL revises the test to skip Windows explicitly.] Change-Id: I9b3661013d6449b7486532445d934ae91e5393ef Reviewed-on: https://go-review.googlesource.com/c/go/+/267887 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2020-11-05path/filepath: revert "add WalkDir"Dmitri Shuralyov
This reverts CL 266240. Reason for revert: tests aren't passing on windows-amd64-longtest. Change-Id: If323c6254a42aff0418e2c0a9531f3d4c829a242 Reviewed-on: https://go-review.googlesource.com/c/go/+/267798 Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-11-04path/filepath: add WalkDirRuss Cox
WalkDir is like Walk but can use ReadDir to read directories, instead of Readdirnames + Lstat on every entry, which is usually a significant performance improvement. (The Lstat can still happen if the walk function calls d.Info.) Fixes #42027. Change-Id: Ie11024b23be2656e320d41fd81ff0d8810aa729e Reviewed-on: https://go-review.googlesource.com/c/go/+/266240 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-25path/filepath: allow EvalSymlinks to work on UNC share roots on WindowsKevin Parsons
Fixes #42079 Previously, EvalSymlinks returned an error when called with the root of a UNC share (e.g. \\server\share). This was due to Windows's FindFirstFile function not supporting a share root path. To resolve this, now return early from toNorm in the case where the path after the volume name is empty. Skipping the later path component resolution shouldn't have any negative impact in this case, as if the path is empty, there aren't any path components to resolve anyways. The test case uses the localhost admin share (c$), as it should be present in most situations. This allows testing without setting up an external file share. However, this fix applies to all UNC share root paths. Change-Id: I05035bd86be93662d7bea34fab4b75fc8e918206 GitHub-Last-Rev: bd3db2cda65aae1cdf8d94b03bc7197dff68dc44 GitHub-Pull-Request: golang/go#42096 Reviewed-on: https://go-review.googlesource.com/c/go/+/263917 Trust: Alex Brainman <alex.brainman@gmail.com> Trust: Giovanni Bajo <rasky@develer.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2020-10-23io/fs, path, path/filepath, testing/fstest: validate patterns in Match, GlobRuss Cox
According to #28614, proposal review agreed in December 2018 that Match should return an error for failed matches where the unmatched part of the pattern has a syntax error. (The failed match has to date caused the scan of the pattern to stop early.) This change implements that behavior: the match loop continues scanning to the end of the pattern, even after a confirmed mismatch, to check whether the pattern is even well-formed. The change applies to both path.Match and filepath.Match. Then filepath.Glob and fs.Glob make a single validity-checking call to Match before beginning their usual processing. Also update fstest.TestFS to check for correct validation in custom Glob implementations. Fixes #28614. Change-Id: Ic1d35a4bb9c3565184ae83dbefc425c5c96318e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/264397 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20all: update references to symbols moved from os to io/fsRuss Cox
The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-06all: enable more tests on macOS/ARM64Cherry Zhang
Updates #38485. Change-Id: Iac96f5ffe88521fcb11eab306d0df6463bdce046 Reviewed-on: https://go-review.googlesource.com/c/go/+/256920 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: 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-19path,path/filepath: add Join examples with ".." componentsAndrew Ekstedt
People sometimes expect Join to trim .. components from its arguments before joining, and are surprised that it doesn't. This is bad if they were relying on that assumed behaviour to prevent directory traversal attacks. While a careful reading of the documentation for Join and Clean might dispel this notion, it is not obvious at first glance. Add a case to the examples to nudge people in the right direction. Updates #40373 Change-Id: Ib5792c12ba1000811a0c0eb77048196d0b26da60 Reviewed-on: https://go-review.googlesource.com/c/go/+/249177 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-07-07path/filepath: add explicit comment marking elided errorsRuss Cox
The errors on these lines are meant to be discarded. Add a comment to make that extra clear. Change-Id: I38f72af6dfbb0e86677087baf47780b3cc6e7d40 Reviewed-on: https://go-review.googlesource.com/c/go/+/241083 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-08all: remove scattered remnants of darwin/armAustin Clements
This removes all conditions and conditional code (that I could find) that depended on darwin/arm. Fixes #35439 (since that only happened on darwin/arm) Fixes #37611. Change-Id: Ia4c32a5a4368ed75231075832b0b5bfb1ad11986 Reviewed-on: https://go-review.googlesource.com/c/go/+/227198 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-11-20path: minor changes to improve documentation for JoinEric Rutherford
Reworking the comments in path to call out how leading empty elements are treated. Also updating filepath.Join since it shared much of the wording from path.Join. Updates #35655 Change-Id: I5b15c5d36e9d19831ed39e6bcc7f2fd6c1330033 Reviewed-on: https://go-review.googlesource.com/c/go/+/207797 Reviewed-by: Rob Pike <r@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-03-25path/filepath: add examples for Base, Dir and IsAbsHasan Ozgan
Change-Id: I7a438409748f0f9d6517a7ea1cdee6512ce3ca8a Reviewed-on: https://go-review.googlesource.com/c/go/+/161678 Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2019-03-05path/filepath: don't discard .. in EvalSymlinksIan Lance Taylor
EvalSymlinks was mishandling cases like "/x/../../y" or "../../../x" where there is an extra ".." that goes past the start of the path. Fixes #30520 Change-Id: I07525575f83009032fa1a99aa270c8d42007d276 Reviewed-on: https://go-review.googlesource.com/c/go/+/164762 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-03-01path/filepath: do not call GetFinalPathNameByHandle from EvalSymlinksAlex Brainman
EvalSymlinks is using GetFinalPathNameByHandle to handle symlinks with unusual targets like \??\Volume{ABCD}\. But since CL 164201, os.Readlink handles path like that too. So remove all that extra code that EvalSymlinks calls when os.Readlink fails - it is not needed any more. Now that windows EvalSymlinks implementation is similar to unix implementation, we can remove all slashAfterFilePathError related code too. So do that. This also makes TestIssue29372 pass even when TMP directory refers to symlinks with target like \??\Volume{ABCD}\. So remove TestIssue29372 code that helped it pass on windows-arm. TestIssue29372 should pass as is now. Fixes #29746 Change-Id: I568d142c89d3297bff8513069bceaa6be51fe7e4 Reviewed-on: https://go-review.googlesource.com/c/164202 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-20path/filepath: revert "fix Windows-specific Clean bug"Ian Lance Taylor
Revert CL 137055, which changed Clean("\\somepath\dir\") to return "\\somepath\dir" on Windows. It's not entirely clear this is correct, as this path is really "\\server\share\", and as such the trailing slash may be the path on that share, much like "C:\". In any case, the change broke existing code, so roll it back for now and rethink for 1.13. Updates #27791 Fixes #30307 Change-Id: I69200b1efe38bdb6d452b744582a2bfbb3acbcec Reviewed-on: https://go-review.googlesource.com/c/163077 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>