aboutsummaryrefslogtreecommitdiff
path: root/src/path
AgeCommit message (Collapse)Author
10 daysall: change from sort functions to slices functions where feasibleIan Lance Taylor
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. This CL does not change packages that are used during bootstrap, as the bootstrap compiler does not have the required slices functions. It does not change the go/scanner package because the ErrorList Len, Swap, and Less methods are part of the Go 1 API. Change-Id: If52899be791c829198e11d2408727720b91ebe8a Reviewed-on: https://go-review.googlesource.com/c/go/+/587655 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> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-04-26path/filepath, internal/filepathlite: move parts of filepath to filepathliteDamien Neil
The path/filepath package needs to depend on the os package to implement Abs, Walk, and other functions. Move the implementation of purely lexical functions from path/filepath into internal/filepathlite, so they can be used by os and other low-level packages. Change-Id: Id211e547d6f1f58c82419695ff2d75cd6cd14a12 Reviewed-on: https://go-review.googlesource.com/c/go/+/566556 Reviewed-by: Behroz Karimpor <behrozkarimpor201@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
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-03-22path/filepath: use slices to simplify the test codeapocelipes
Change-Id: I020ca2ed8a6af60977f2c492cd742f824906d4ec GitHub-Last-Rev: b27fda463058e86eafbe5bd10e5c99e10dd609a8 GitHub-Pull-Request: golang/go#66462 Reviewed-on: https://go-review.googlesource.com/c/go/+/573715 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-04os: don't normalize volumes to drive letters in os.Readlinkqmuntal
This CL updates os.Readlink so it no longer tries to normalize volumes to drive letters, which was not always even possible. This behavior is controlled by the `winreadlinkvolume` setting. For Go 1.23, it defaults to `winreadlinkvolume=1`. Previous versions default to `winreadlinkvolume=0`. Fixes #63703. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-arm64 Change-Id: Icd6fabbc8f0b78e23a82eef8db89940e89e9222d Reviewed-on: https://go-review.googlesource.com/c/go/+/567735 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-04os: don't treat mount points as symbolic linksqmuntal
This CL changes the behavior of os.Lstat to stop setting the os.ModeSymlink type mode bit for mount points on Windows. As a result, filepath.EvalSymlinks no longer evaluates mount points, which was the cause of many inconsistencies and bugs. Additionally, os.Lstat starts setting the os.ModeIrregular type mode bit for all reparse tags on Windows, except for those that are explicitly supported by the os package, which, since this CL, doesn't include mount points. This helps to identify files that need special handling outside of the os package. This behavior is controlled by the `winsymlink` GODEBUG setting. For Go 1.23, it defaults to `winsymlink=1`. Previous versions default to `winsymlink=0`. Fixes #39786 Fixes #40176 Fixes #61893 Updates #63703 Updates #40180 Updates #63429 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-arm64 Change-Id: I2e7372ab8862f5062667d30db6958d972bce5407 Reviewed-on: https://go-review.googlesource.com/c/go/+/565136 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@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>
2024-02-26path/filepath: support multiple TestAbs runs on Windowsqmuntal
TestAbs modifies the absTests global variable on Windows, which makes the test to fail if it is run more than once, i.e. executing "go test -run ^TestAbs$ -count 2 path/filepath". This CL fixes the issue by clipping the absTests slices before appending more elements to it. Change-Id: I8f1144b2f10b8fa1b847e6639c0bda7baafc2dac Reviewed-on: https://go-review.googlesource.com/c/go/+/566396 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-02-23path/filepath: delete the deprecated joinNonEmpty and isUNCAndy Pan
Change-Id: I4ce88b2e8e8d24afb63ca7246ce0c418fcb02c9e Reviewed-on: https://go-review.googlesource.com/c/go/+/564715 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-09io/fs,path/filepath: fix typo in SkipAll/SkipDir docRoger Peppe
Also make the reference into a doc link. Change-Id: Ib112307a65b65c8f963abf60aa92cb1942de940c Reviewed-on: https://go-review.googlesource.com/c/go/+/554295 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-23path: add available godoc linkcui fliter
Change-Id: I6d40a59cde4c3f1d5094f5126fdbc1195285195f Reviewed-on: https://go-review.googlesource.com/c/go/+/539577 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2023-11-09path/filepath: consider \\?\c: as a volume on WindowsDamien Neil
While fixing several bugs in path handling on Windows, beginning with \\?\. Prior to #540277, VolumeName considered the first path component after the \\?\ prefix to be part of the volume name. After, it considered only the \\? prefix to be the volume name. Restore the previous behavior. Fixes #64028 Change-Id: I6523789e61776342800bd607fb3f29d496257e68 Reviewed-on: https://go-review.googlesource.com/c/go/+/541175 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
2023-11-07path/filepath: fix various issues in parsing Windows pathsDamien Neil
On Windows, A root local device path is a path which begins with \\?\ or \??\. A root local device path accesses the DosDevices object directory, and permits access to any file or device on the system. For example \??\C:\foo is equivalent to common C:\foo. The Clean, IsAbs, IsLocal, and VolumeName functions did not recognize root local device paths beginning with \??\. Clean could convert a rooted path such as \a\..\??\b into the root local device path \??\b. It will now convert this path into .\??\b. IsAbs now correctly reports paths beginning with \??\ as absolute. IsLocal now correctly reports paths beginning with \??\ as non-local. VolumeName now reports the \??\ prefix as a volume name. Join(`\`, `??`, `b`) could convert a seemingly innocent sequence of path elements into the root local device path \??\b. It will now convert this to \.\??\b. In addition, the IsLocal function did not correctly detect reserved names in some cases: - reserved names followed by spaces, such as "COM1 ". - "COM" or "LPT" followed by a superscript 1, 2, or 3. IsLocal now correctly reports these names as non-local. Fixes #63713 Fixes CVE-2023-45283 Fixes CVE-2023-45284 Change-Id: I446674a58977adfa54de7267d716ac23ab496c54 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2040691 Reviewed-by: Roland Shoemaker <bracewell@google.com> Reviewed-by: Tatiana Bradley <tatianabradley@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/540277 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Heschi Kreinick <heschi@google.com>
2023-09-29path/filepath: reuse os.ReadDirDaniel Martí
While reading the source code, I noticed that readDir seemed extremely similar to os.ReadDir. They indeed appear to be copies. Note that there's readDirNames as well, but it has no corresponding os.ReadDirNames top-level helper to be replaced by. Change-Id: I6fe1d0aeda35dc69bb4531986fe3a21ebda1d877 Reviewed-on: https://go-review.googlesource.com/c/go/+/530795 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-13path: use bytealg.LastIndexByteStringTobias Klauser
While strings.LastIndex{,Byte} cannot be used in package path, the respective internal/bytealg function can be used. Change-Id: If0ecc36484308221f50875c8609913f6f2887fba Reviewed-on: https://go-review.googlesource.com/c/go/+/527855 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-09-12io/fs, path/filepath, cmd/gofmt: replace statDirEntry with fs.FileInfoToDirEntrymstmdev
Change-Id: Ie914367314ca72fab34c4d4529755dea853cf325 GitHub-Last-Rev: bc61665d33d7f15da371dcfb90c132fab25fc233 GitHub-Pull-Request: golang/go#62342 Reviewed-on: https://go-review.googlesource.com/c/go/+/523876 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2023-08-08path/filepath: don't drop .. elements when cleaning invalid Windows pathsDamien Neil
Fix a bug where Clean could improperly drop .. elements from a path on Windows, when the path contains elements containing a ':'. For example, Clean("a/../b:/../../c") now correctly returns "..\c" rather than "c". Fixes #61866 Change-Id: I97b0238953c183b2ce19ca89c14f26700008ea72 Reviewed-on: https://go-review.googlesource.com/c/go/+/517216 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>
2023-08-07all: add a few more godoc linksDaniel Martí
Over the past few months as I read the standard library's documentation I kept finding spots where godoc links would have helped me. I kept adding to a stash of changes to fix them up bit by bit. The stash has grown big enough by now, and we're nearing a release, so I think it's time to merge to avoid git conflicts or bit rot. Note that a few sentences are slightly reworded, since "implements the Fooer interface" can just be "implements [Fooer]" now that the link provides all the context needed to the user. Change-Id: I01c31d3d3ff066d06aeb44f545f8dd0fb9a8d998 Reviewed-on: https://go-review.googlesource.com/c/go/+/508395 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-06-16path/filepath: avoid assuming that GOROOT/test is presentBryan C. Mills
GOROOT/test is pruned out by cmd/distpack. It isn't really needed for the test anyway; the test can instead use the "src/unicode" subdirectory, which is even within the same module. This test was previously adjusted in CL 13467045 and CL 31859. Unlike in previous iterations of the test, the directories used in this revision are covered by the Go 1 compatibility policy and thus unlikely to disappear. For #24904. Change-Id: I156ae18354bcbc2ddd8d22b210f16ba1e97cd5d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/504116 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@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-14path/filepath,cmd/go: skip tests involving double-symlinks on iosBryan C. Mills
For #59586. Change-Id: I092f7a4abce1074b8eef64a3ecf9fc187914709b Reviewed-on: https://go-review.googlesource.com/c/go/+/484755 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Bypass: Bryan Mills <bcmills@google.com>
2023-04-13path/filepath: add test cases for walking a symlink-to-symlink-to-dirBryan C. Mills
The "double link with slash" test is skipped on darwin due to an apparent kernel / libc bug. If the bug is present on other platforms too, I'd like to know about it. For #59586. Change-Id: I4bdd6a80a3ed7b0960ea6da30f91a655f317d512 Reviewed-on: https://go-review.googlesource.com/c/go/+/484395 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-04-11all: add wasip1 supportJohan Brandhorst-Satzkorn
Fixes #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: I49b66946acc90fdf09ed9223096bfec9a1e5b923 Reviewed-on: https://go-review.googlesource.com/c/go/+/479627 Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
2023-03-25all: add a few links in package godocsDaniel Martí
I noticed the one in path/filepath while reading the docs, and the other ones were found via some quick grepping. Change-Id: I386f2f74ef816a6d18aa2f58ee6b64dbd0147c9e Reviewed-on: https://go-review.googlesource.com/c/go/+/478795 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-02-21path/filepath: document that Clean does not change Windows volume namesDamien Neil
Fixes #58348 Change-Id: I4aac0285f11618a45aca6b13c2da2a10a803a9b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/469955 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2023-02-14path/filepath: do not Clean("a/../c:/b") into c:\b on WindowsDamien Neil
Do not permit Clean to convert a relative path into one starting with a drive reference. This change causes Clean to insert a . path element at the start of a path when the original path does not start with a volume name, and the first path element would contain a colon. This may introduce a spurious but harmless . path element under some circumstances. For example, Clean("a/../b:/../c") becomes `.\c`. This reverts CL 401595, since the change here supersedes the one in that CL. Thanks to RyotaK (https://twitter.com/ryotkak) for reporting this issue. Fixes #57274 Fixes CVE-2022-41722 Change-Id: I837446285a03aa74c79d7642720e01f354c2ca17 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1675249 Reviewed-by: Roland Shoemaker <bracewell@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Julie Qiu <julieqiu@google.com> TryBot-Result: Security TryBots <security-trybots@go-security-trybots.iam.gserviceaccount.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/468123 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
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>