Rewording the comments for Join to do a better job of calling out
when Clean is called. Also clarifing other portions of the comment.
Fixes#29875
Change-Id: Ied43983bb10a97922898d28af133de0930224496
Reviewed-on: https://go-review.googlesource.com/c/go/+/194339
Reviewed-by: Rob Pike <r@golang.org>
At the moment the last output line of ExampleSplit- two empty strings- are being
trimmed from the output. I have formatted the output of the function to avoid
whitespace trimming and show empty strings more clearly.
Fixes#23542
Change-Id: Ic2a4d98cfa06db1466c6c6d98099542df9e7c88b
Reviewed-on: https://go-review.googlesource.com/c/go/+/191397
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
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>
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>
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 #27791Fixes#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>
TestIssue29372 is broken on windows when temporary directory has
symlink in its path.
Adjust the test to use filepath.EvalSymlinks of temporary directory,
instead of temporary directory on windows. This change is not a
proper fix, but at least it makes TestIssue29372 pass on windows-arm.
See issue for details.
Updates #29746
Change-Id: I2af8ebb89da7cb9daf027a5e49e32ee22dbd0e3d
Reviewed-on: https://go-review.googlesource.com/c/159578
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Recent CL 156398 extended TestNTNamespaceSymlink. But new code
fails, if user running the test does not have sufficient privilege
to create file symlink. Skip part of TestNTNamespaceSymlink, if
user cannot create symlink.
Fixes#29745
Change-Id: Ie4176429ba9dd98553ce9e91fd19851cc7353f42
Reviewed-on: https://go-review.googlesource.com/c/157917
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
CL 155597 attempted to fix#29372. But it failed to make all new
test cases pass. Also CL 155597 broke some existing code
(see #29449 for details).
Make small adjustment to CL 155597 that fixes both #29372 and #29449.
Suggested by Ian.
Updates #29372Fixes#29449
Change-Id: I9777a615514d3f152af5acb65fb1239e696607b6
Reviewed-on: https://go-review.googlesource.com/c/156398
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Rather than return os.ErrNotExist for /path/to/existing_file/,
walkSymLinks now returns syscall.ENOTDIR.
This is consistent with behavior of os.Lstat.
Fixes#29372
Change-Id: Id5c471d901db04b2f35d60f60a81b2a0be93cae9
Reviewed-on: https://go-review.googlesource.com/c/155597
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Go documentation style for boolean funcs is to say:
// Foo reports whether ...
func Foo() bool
(rather than "returns true if")
This CL also replaces 4 uses of "iff" with the same "reports whether"
wording, which doesn't lose any meaning, and will prevent people from
sending typo fixes when they don't realize it's "if and only if". In
the past I think we've had the typo CLs updated to just say "reports
whether". So do them all at once.
(Inspired by the addition of another "returns true if" in CL 146938
in fd_plan9.go)
Created with:
$ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true iff" | grep -v vendor)
$ perl -i -npe 's/returns true if/reports whether/' $(git grep -l "returns true if" | grep -v vendor)
Change-Id: Ided502237f5ab0d25cb625dbab12529c361a8b9f
Reviewed-on: https://go-review.googlesource.com/c/147037
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This CL changes IsAbs to return true for "NUL" and other Windows
reserved filenames (search
https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
for NUL for details). os.Open("NUL") and os.Stat("NUL") work
regardless of what current directory is, and it is mistake to join
"NUL" with current directory when building full path. Changing
IsAbs("NUL") to return true fixes that mistake.
Fixes#28035
Change-Id: Ife8f8aee48400702613ede8fc6834fd43e6e0f03
Reviewed-on: https://go-review.googlesource.com/c/145220
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
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>
For a relative symlink in the root directory, such as /tmp ->
private/tmp, we were dropping the leading slash.
No test because we can't create a symlink in the root directory.
The test TestGZIPFilesHaveZeroMTimes was failing on the Darwin builders.
Updates #19922
Updates #20506
Change-Id: Ic83cb6d97ad0cb628fc551ac772a44fb3e20f038
Reviewed-on: https://go-review.googlesource.com/135295
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Rather than try to work around Clean and Join on intermediate steps,
which can remove ".." components unexpectedly, just do everything in
walkSymlinks. Use a single loop over path components.
Fixes#23444
Change-Id: I4f15e50d0df32349cc4fd55e3d224ec9ab064379
Reviewed-on: https://go-review.googlesource.com/121676
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
The message was hardcoded to indicate that the test wanted a nil error, even
though in some cases a specific error was wanted. This patch fixes the
message to print the wanted error.
Change-Id: Id86ea89d6f41f25bfa164acc50142ae8ff0ec410
GitHub-Last-Rev: c220374845
GitHub-Pull-Request: golang/go#26674
Reviewed-on: https://go-review.googlesource.com/126619
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
If a filepath.WalkFunc is called with an non-nil err argument, it's possible
that the info argument will be nil. The comment above filepath.WalkFunc now
reflects this.
Fixes#26425
Change-Id: Ib9963b3344587d2993f1698c5a801f2d1286856b
GitHub-Last-Rev: 553fc266b5
GitHub-Pull-Request: golang/go#26435
Reviewed-on: https://go-review.googlesource.com/124635
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Relates to #9679
Change-Id: I68951f664d2a03812dae309c580c181869d8af21
Reviewed-on: https://go-review.googlesource.com/122237
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit adds the js/wasm architecture to the os package.
Access to the actual file system is supported through Node.js.
Updates #18892
Change-Id: I6fa642fb294ca020b2c545649d4324d981aa0408
Reviewed-on: https://go-review.googlesource.com/109977
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The current Abs docs say:
// If the path is not absolute it will be joined with the current
// working directory to turn it into an absolute path.
The empty string is not an absolute path, so the docs suggest that the
empty string should be joined with the current working directory to
turn it into an absolute path. This was already the case on all
platforms other than Windows. Per the decision in issue #24441,
this change makes it work on Windows too.
Since the empty string is not a valid path for the purposes of calling
os.Stat on it, we can't simply add the empty string test case to
absTests, which TestAbs uses. It would error when trying to do:
info, err := os.Stat(path)
I didn't find a good way to modify TestAbs to handle this situation
without significantly complicating its code and compromising the test.
So, a separate test is created for testing Abs on empty string input.
Fixes#24441.
Change-Id: I11d8ae2f6e6e358f3e996372ee2a0449093898d2
Reviewed-on: https://go-review.googlesource.com/112935
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
'%SystemRoot%/System32/chcp.com' is a tool on Windows that
is used to change the active code page in the console.
'go test path/filepath' can fail with:
"'chcp' is not recognized as an internal or external command"
The test uses a custom PATH variable but does not include
'%SystemRoot%/System32'. Always append that to PATH.
Updates #24709
Change-Id: Ib4c83ffdcc5dd6eb7bb34c07386cf2ab61dcae57
GitHub-Last-Rev: fac92613cc
GitHub-Pull-Request: golang/go#25089
Reviewed-on: https://go-review.googlesource.com/109362
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This change makes errors in the example code a bit better, as it's no use to show the root dir when an error occurs walking a subdirectory or file.
Change-Id: I546276e9b151fabba5357258f03bfbd47a508201
GitHub-Last-Rev: 398c1eeb61
GitHub-Pull-Request: golang/go#24536
Reviewed-on: https://go-review.googlesource.com/102535
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
We should avoid writing temp files to GOROOT, since it might be readonly.
Fixes#23881
Change-Id: Iaa38ec404b303f0cf27fdfb7daf1ddd60fd5d1c9
GitHub-Last-Rev: de0211df84
GitHub-Pull-Request: golang/go#24238
Reviewed-on: https://go-review.googlesource.com/98517
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Backslashes are ignored in Match and Glob on Windows, since those
collide with the separator character. However, they should still work in
both functions on other operating systems.
hasMeta did not reflect this logic - it always treated a backslash as a
non-special character. Do that only on Windows.
Assuming this is what the TODO was referring to, remove it. There are no
other characters that scanChunk treats especially.
Fixes#23418.
Change-Id: Ie0bd795812e0ed9d8c8c1bbc3137f29d960cba84
Reviewed-on: https://go-review.googlesource.com/87455
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
path.Match works purely with strings, not file paths. That's what sets
it apart from filepath.Match. For example, only filepath.Match will
change its behavior towards backslashes on Windows, to accomodate for
the file path separator on that system.
As such, path.Match should make no mention of file names. Nor should
path.ErrBadPattern mention globbing at all - the package has no notion
of globbing, and the error concerns only patterns.
For a similar reason, remove the mention of globbing from
filepath.ErrBadPattern. The error isn't reserved to just globbing, as it
can be returned from filepath.Match. And, as before, it only concerns
the patterns themselves.
Change-Id: I58a83ffa3e2549625d8e546ef916652525504bd1
Reviewed-on: https://go-review.googlesource.com/87857
Reviewed-by: Rob Pike <r@golang.org>
Fixes: #22052
Change-Id: Ia056871b35ecc1a8c5ac891402fc1c5702731623
Reviewed-on: https://go-review.googlesource.com/66330
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
strings.LastIndexByte was introduced in go1.5 and it can be used
effectively wherever the second argument to strings.LastIndex is
exactly one byte long.
This avoids generating unnecessary string symbols and saves
a few calls to strings.LastIndex.
Change-Id: I7b5679d616197b055cffe6882a8675d24a98b574
Reviewed-on: https://go-review.googlesource.com/66372
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Before this change, if Walk encounters an unreadable directory,
it will call walkFn with this directory twice. Argument err in
the first call is nil, and the second is the permission error.
This change removes the former call and makes Walk call walkFn
with permission error.
Fixes#21758
Change-Id: I21e57c67f3c5a8370fc80a43db3c8009fbce6439
Reviewed-on: https://go-review.googlesource.com/63994
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
It doesn't change the outcome. It might have been useful at some point
to avoid Replace from doing work or allocating. However, nowadays the
func returns early without doing any work if Count returns 0.
Change-Id: Id69dc74042a6e39672b405016484db8b50f43d58
Reviewed-on: https://go-review.googlesource.com/62991
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
Change-Id: I143203a9dcf9a4da0e53a3aab6e370244b849296
Reviewed-on: https://go-review.googlesource.com/62270
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Make it dead simple to see visually what the function outputs in
various scenarios.
Change-Id: I8f6fcd72fa1515361481f0510412cde221e1d4e3
Reviewed-on: https://go-review.googlesource.com/51630
Run-TryBot: Kevin Burke <kev@inburke.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Hiroshi Ioka <hirochachacha@gmail.com>
The path package has a reference to the path/filepath package, so add
a reverse reference.
And clarify the path package doesn't do Windows paths.
Fixes#20117
Change-Id: I65c5ce24e600b32ea20c5821b744bd89f6aff98c
Reviewed-on: https://go-review.googlesource.com/45653
Reviewed-by: Jaana Burcu Dogan <jbd@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This change adds several examples, with emphasis on special or edge
cases such as a directory parameter consisting of an empty string.
Change-Id: Ib4ac3d0f6d503493eeed0c4fda7c12acf782e9e2
Reviewed-on: https://go-review.googlesource.com/43010
Reviewed-by: Steve Francia <spf@golang.org>
Run-TryBot: Jaana Burcu Dogan <jbd@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
When using Lstat against symlinks that point to a directory,
the function returns FileInfo with both ModeDir and ModeSymlink set.
Change that to never set ModeDir if ModeSymlink is set.
Fixes#10424Fixes#17540Fixes#17541
Change-Id: Iba280888aad108360b8c1f18180a24493fe7ad2b
Reviewed-on: https://go-review.googlesource.com/41830
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Mostly unnecessary *testing.T arguments.
Found with github.com/mvdan/unparam.
Change-Id: Ifb955cb88f2ce8784ee4172f4f94d860fa36ae9a
Reviewed-on: https://go-review.googlesource.com/41691
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
For #17540.
Change-Id: Ie01f39797526934fa553f4279cbde6c7cbf14154
Reviewed-on: https://go-review.googlesource.com/36854
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The environment variables used in those tests override the default
OS ones. However, one of them (SystemRoot) seems to be required on
some Windows systems for invoking cmd.exe properly.
This fixes#4930 and #6568.
Change-Id: I23dfb67c1de86020711a3b59513f6adcbba12561
Reviewed-on: https://go-review.googlesource.com/36873
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>