1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:28:32 -06:00
Commit Graph

141 Commits

Author SHA1 Message Date
Paschalis Tsilias
95a786da12 path/filepath, io/fs: add SkipAll
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-08-25 18:50:37 +00:00
hopehook
dc8e2a6a8e io: add OffsetWriter, NewOffsetWriter
Offsetwriter refers to the design of SectionReader and removes
the section parameter n.

Since the size of the written data is determined by the user,
we cannot know where the end offset of the original data is.
The offset of SeekEnd is not valid in Seek method.

Fixes #45899.

Change-Id: I9d9445aecfa0dd4fc5168f2f65e1e3055c201b45
Reviewed-on: https://go-review.googlesource.com/c/go/+/406776
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-08-19 17:03:55 +00:00
Julie Qiu
fa2d41d0ca io/fs: fix stack exhaustion in Glob
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 a similar issue in
path/filepath.

Fixes CVE-2022-30630
Fixes golang/go#53415

Change-Id: I5a9d02591fed90cd3d52627f5945f1301e53465d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1497588
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/417065
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-07-12 15:05:55 +00:00
HowJMay
3b594b9255 io: clarify SeekEnd offset value
fixes #53474

Change-Id: I14c3dc800dc27233630a54592328bb0df1bbaa5d
GitHub-Last-Rev: 46f93cfbd4
GitHub-Pull-Request: golang/go#53505
Reviewed-on: https://go-review.googlesource.com/c/go/+/413614
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-06-25 19:08:51 +00:00
Russ Cox
f8a53df314 io: revert: add an Err field to LimitedReader
We are having a hard time deciding the exact semantics
of the Err field, and we need to ship the beta.
So revert the Err field change; it can wait for Go 1.20.

For #51115.

This reverts CL 396215.

Change-Id: I7719386567d3da10a614058a11f19dbccf304b4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/410133
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
2022-06-04 14:00:38 +00:00
Russ Cox
946b4baaf6 all: gofmt main repo
Excluding vendor and testdata.
CL 384268 already reformatted most, but these slipped past.

The struct in the doc comment in debug/dwarf/type.go
was fixed up by hand to indent the first and last lines as well.

For #51082.

Change-Id: Iad020f83aafd671ff58238fe491907e85923d0c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/407137
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-19 15:49:05 +00:00
John Bampton
20db15ce12 all: fix spelling
Change-Id: I63eb42f3ce5ca452279120a5b33518f4ce16be45
GitHub-Last-Rev: a88f2f72be
GitHub-Pull-Request: golang/go#52951
Reviewed-on: https://go-review.googlesource.com/c/go/+/406843
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-18 00:47:29 +00:00
Damien Neil
aedf298daf io/fs: document requirement that ReadDir return an unwrapped io.EOF
This requirement ensures that ReadDir implementations are as compatible
as possible with "*os.File".ReadDir.

The testing/fstest package already tests for equality to io.EOF.

Updates #47062.
Fixes #47086.

Change-Id: I54f911a34e507a3db0abc4da55a19b7a50b35041
Reviewed-on: https://go-review.googlesource.com/c/go/+/333149
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-05-17 01:50:34 +00:00
Carl Johnson
fd6ef06296 io: add an Err field to LimitedReader
Fixes #51115

Change-Id: I3c5296e4adc71c1c1b1808a45abd4801ae43465a
GitHub-Last-Rev: 4c197acd51
GitHub-Pull-Request: golang/go#51990
Reviewed-on: https://go-review.googlesource.com/c/go/+/396215
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-04 20:06:32 +00:00
Jorropo
0537a74b76 io: NopCloser forward WriterTo implementations if the reader supports it
This patch also include related fixes to net/http.

io_test.go don't test reading or WritingTo of the because the logic is simple.
NopCloser didn't even had direct tests before.

Fixes #51566

Change-Id: I1943ee2c20d0fe749f4d04177342ce6eca443efe
GitHub-Last-Rev: a6b9af4e94
GitHub-Pull-Request: golang/go#52340
Reviewed-on: https://go-review.googlesource.com/c/go/+/400236
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-03 14:37:48 +00:00
Daniel Martí
e04280838f io/ioutil: provide an equivalent for the deprecated ReadDir
All APIs in the now-deprecated io/ioutil package have a direct
replacement in either the io or os package with the same signature,
with the notable exception of ioutil.ReadDir, as os.ReadDir has a
slightly different signature with fs.DirEntry rather than fs.FileInfo.

New code can easily make use of []fs.DirEntry directly,
but existing code may need to continue using []fs.FileInfo for backwards
compatibility reasons. For instance, I had a bit of code that exposed
the slice as a public API, like:

	return ioutil.ReadDir(name)

It took me a couple of minutes to figure out what the exact equivalent
in terms of os.ReadDir would be, and a code sample would have helped.
Add one for future reference.

For #42026.
For #51927.

Change-Id: I76d46cd7d68fc609c873821755fdcfc299ffd56c
Reviewed-on: https://go-review.googlesource.com/c/go/+/399854
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
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>
2022-04-19 16:19:27 +00:00
Russ Cox
690ac4071f all: remove trailing blank doc comment lines
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-04-01 18:18:07 +00:00
Ian Lance Taylor
460fd63ccc io/fs, path/filepath: honor SkipDir on second WalkDirFunc error call
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-28 22:03:07 +00:00
Jeff Widman
a208aa7f33 io/ioutil: add deprecation markers to ioutil
All the code in ioutil just forwards functionality to code
in either the io or os packages, per issue 42026.

This change adds the "Deprecated" marker to all the
functions in this package.

For #42026

Fixes #51927

Change-Id: Ia807bc5c0edb06cc80ec7e35917dcfe2ad50f0ea
GitHub-Last-Rev: 3c3603f368
GitHub-Pull-Request: golang/go#51961
Reviewed-on: https://go-review.googlesource.com/c/go/+/395918
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-28 16:44:09 +00:00
Jorropo
079a027d27 io: add WriterTo to MultiReader
This patch allows to zerocopy using MultiReader.
This is done by MultiReader implementing WriterTo.

Each sub reader is copied using usual io copy helper and thus use
WriterTo or ReadFrom with reflection.

There is a special case for when a subreader is a MultiReader.
Instead of using copyBuffer which would call multiReader.WriteTo,
multiReader.writeToWithBuffer is used instead, the difference
is that the temporary copy buffer is passed along, saving
allocations for nested MultiReaders.

The workflow looks like this:
- multiReader.WriteTo (allocates 32k buffer)
  - multiReader.writeToWithBuffer
    - for each subReader:
      - is instance of multiReader ?
        - yes, call multiReader.writeToWithBuffer
        - no, call copyBuffer(writer, currentReader, buffer)
          - does currentReader implements WriterTo ?
           - yes, use use currentReader.WriteTo
           - no, does writer implement ReadFrom ?
             - yes, use writer.ReadFrom
             - no, copy using Read / Write with buffer

This can be improved by lazy allocating the 32k buffer.
For example a MultiReader of such types:
  MultiReader(
    bytes.Reader, // WriterTo-able
    bytes.Reader, // WriterTo-able
    bytes.Reader, // WriterTo-able
  )

Doesn't need any allocation, all copy can be done using bytes.Reader's
internal data slice. However currently we still allocate a 32k buffer
for nothing.

This optimisation has been omitted for a future patch because of high
complexity costs for a non obvious performance cost (it needs a benchmark).
This patch at least is on par with the previous MultiReader.Read
workflow allocation wise.

Fixes #50842

Change-Id: Ib070c8f36337d9dd86090df8a703c5df97a773ae
GitHub-Last-Rev: 8ebe60ceac
GitHub-Pull-Request: golang/go#51502
Reviewed-on: https://go-review.googlesource.com/c/go/+/390215
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Trust: Daniel Martí <mvdan@mvdan.cc>
2022-03-07 23:22:26 +00:00
Russ Cox
2580d0e08d all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata.
And adjust tests as needed.

Not reverting the changes in std that are bootstrapped,
because some of those changes would appear in API docs,
and we want to use any consistently.
Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories
when preparing the bootstrap copy.

A few files changed as a result of running gofmt -w
not because of interface{} -> any but because they
hadn't been updated for the new //go:build lines.

Fixes #49884.

Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09
Reviewed-on: https://go-review.googlesource.com/c/go/+/368254
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-13 18:45:54 +00:00
jiahua wang
8ce1a953fb io: add error check to TeeReader Example
Change-Id: I0b94bdced47483c6412e9979ce2d103fbfc52afb
Reviewed-on: https://go-review.googlesource.com/c/go/+/353729
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Carlos Amedee <carlos@golang.org>
2021-11-11 19:34:23 +00:00
Meng Zhuo
2c7cdec2a7 io: remove UTF8 specified document for RuneReader
RuneReader is fine with UTF16 or any other character encoding

Fixes #49178

Change-Id: I08a5ac205e095349d451d3b60411eaeebc3aa563
Reviewed-on: https://go-review.googlesource.com/c/go/+/359334
Trust: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-29 02:16:47 +00:00
jiahua wang
7eb0dd289a io: add examples for (*SectionReader) Read/Size
Change-Id: Ie804f9a5d1d6beec210d2f8075c030a5c60a78ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/352152
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
2021-09-28 19:51:08 +00:00
Bryan C. Mills
e301b2f11c io: update ByteScanner and RuneScanner docs to match long-standing implementations
Do not require the byte or rune unread by the call to match the last
return from ReadByte or ReadRune, since in practice the
implementations of these methods (especially ReadByte) may also unread
bytes from other Read-style methods without reporting an error.

Explicitly allow the Seek-like behavior implemented by bytes.Reader
and bufio.Reader, which can “unread” bytes that were never actually
read.

Explicitly allow ReadByte or ReadRune to return an error after a call
to a non-ReadByte or non-ReadRune operation respectively.
(In practice, implementations today allow very liberal calls to
ReadByte and tend to be more strict about ReadRune, but it seems
simpler to keep the two definitions completely parallel.)

Like CL 349054, this is techincally a breaking change, but given the
long-standing behavior of the implementations in the Go standard
library (such as strings.Reader, bytes.Buffer, and bufio.Reader),
I believe it falls under the “specification errors” exception to the
Go 1 compatibility policy.

Fixes #48449

Change-Id: I61696a59770fe83c667377ba25a072762d3f6f19
Reviewed-on: https://go-review.googlesource.com/c/go/+/351809
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-09-28 17:13:30 +00:00
Ian Lance Taylor
12e8ffc18e io: avoid integer overflow in NewSectionReader
Fixes #48620

Change-Id: I37a5909ad27dc4a170929cb2e2ed1045cf524d59
Reviewed-on: https://go-review.googlesource.com/c/go/+/352629
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-27 22:57:08 +00:00
jiahua wang
1537f14db5 io: fix spelling in documentation
Change-Id: Ie23a9f1300a803d9c713e82b0d892dd90333ca7b
Reviewed-on: https://go-review.googlesource.com/c/go/+/351371
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-09-22 21:47:18 +00:00
jiahua wang
051df0d722 io: fix spelling in documentation for writerFunc
Change-Id: I9f55188859944e1b2b140d3547bcfcb335c5ff50
Reviewed-on: https://go-review.googlesource.com/c/go/+/351370
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-09-22 03:45:00 +00:00
Bryan C. Mills
39e08c6cd7 io: relax documented Seeker invariants that do not hold in practice
Use “or” instead of “and” to describe error behavior.
On error, nearly all Seeker implementations in the Go repo return
0 instead of “the new offset”. (Arguably on error “the new offset”
is the same as the previous offset, but some Seeker implementations
don't have that offset readily available.)

Don't claim that “any positive offsite is legal”.
In practice, most of the Seeker implementations within the Go standard
library do not allow “[s]eeking to any [arbitrary] positive offset”:
some reject all out-of-bounds offsets, and some reject only a subset
that happen to overflow some underlying representation. Since some
positive offsets may be rejected, we cannot claim that seeking to
those offsets “is legal”. However, to avoid invalidating existing
Seeker implemetations we must not require an implementation to reject
invalid positive offsets either.

This is technically a breaking change, since callers of Seek are no
longer allowed to assume that a Seek resulting in an arbitrary
positive offset will succeed. However, since basically none of the
existing implementations actually conformed to the documented behavior
I believe this falls under the “specification errors” exception to the
Go 1 compatibility policy.

Fixes #48316

Change-Id: Ib1b478599b20ad5361bcc97fe8ceb84f74e6d971
Reviewed-on: https://go-review.googlesource.com/c/go/+/349054
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-09-21 13:18:09 +00:00
Roger Peppe
3bdc1799d6 io: unexport internal methods
The methods on the pipe type don't need to be exported. Doing so sets
a bad precedent that it's OK to export methods to indicate an internal
public API.  That's not a good idea in general, because exported methods
increase cognitive load when reading code: the reader needs to consider
whether the exported method might be used via some external interface
or reflection.

Change-Id: Ib13f1b3f9fe0ff251628f31b776182a0953268ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/341409
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Joe Tsai <joetsai@digital-static.net>
Trust: Daniel Martí <mvdan@mvdan.cc>
2021-08-19 09:11:02 +00:00
Ian Lance Taylor
8a7ee4c51e io/fs: don't use absolute path in DirEntry.Name doc
Fixes #47485

Change-Id: I64ac00905a403b7594c706141679051a93058a31
Reviewed-on: https://go-review.googlesource.com/c/go/+/338889
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-08-02 17:18:57 +00:00
Ian Lance Taylor
4f572d7076 io/fs: minor corrections to Sub docs
Fixes #44376

Change-Id: I9cd21adb9d4d434c3d8b8eb8af3042b70c763ea1
Reviewed-on: https://go-review.googlesource.com/c/go/+/296389
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-06-02 18:52:58 +00:00
Adam Mitha
831573cd21 io/fs: added an example for io/fs.WalkDir
The documentation currently does not show how to get an `FS` instance for the operating system's filesystem. This example demonstrates how to accomplish this using the `os` package.

Fixes #46083

Change-Id: I053111c12ab09ef13f0d04fcdff8a6ea0dccf379
Reviewed-on: https://go-review.googlesource.com/c/go/+/319989
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-05-21 03:21:56 +00:00
Ian Lance Taylor
35806efda2 io/fs: document that caller can modify slice returned by ReadFile
Also add a test to testing/fstest.

Fixes #45186

Change-Id: I00e5f46ccd5269dbc266a8f2ebc9a62ebb1297b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/311649
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-04-21 16:46:52 +00:00
Drew Richardson
971c7154b0 io/fs: implement subFS.Sub
Calling fs.Sub with the result of fs.Sub multiple times creates a deep
call stack for Open and other methods. Enhance the fs.FS returned by
fs.Sub to implement fs.SubFS and reduce the call stack.

Fixes #45349

Change-Id: I10e10501e030176e10e2ae5ad260212e5c784bed
Reviewed-on: https://go-review.googlesource.com/c/go/+/306769
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-04-03 20:14:37 +00:00
Michel Levieux
374b190475 io/fs: implement FileInfoToDirEntry
Implements FileInfoToDirEntry which converts an fs.FileInfo to fs.DirEntry.

Fixes #42387.

Change-Id: Ie723b6ed583c6c5ecf22bbe64e3b6496f5114254
Reviewed-on: https://go-review.googlesource.com/c/go/+/293649
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-03-25 21:35:05 +00:00
Simão Gomes Viana
dc289d3dcb io: fix spelling in documentation for io.Discard
In the process of refactoring ioutil.Discard to io.Discard in
CL 263141 "an" should have been changed to "a" but was likely
missed in the process.

This commit corrects the spelling of the documentation.

Change-Id: I0609c45878291f8f01560efc3f3e6fba191e095b
GitHub-Last-Rev: e3257ca272
GitHub-Pull-Request: golang/go#45190
Reviewed-on: https://go-review.googlesource.com/c/go/+/304209
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-03-23 22:17:52 +00:00
Ian Lance Taylor
dcc96e4b94 io/ioutil: use correct Go version in redirection comments
Change-Id: I282f428137ca3360a58167c94e26f3dfdf59fb63
Reviewed-on: https://go-review.googlesource.com/c/go/+/302756
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-19 01:02:56 +00:00
Tobias Klauser
1767d2cc2f io/fs: use testing.T.TempDir in TestWalkDir
Change-Id: I805ad51332e4efe27d47f6c6e3b0af945e0d4aa0
Reviewed-on: https://go-review.googlesource.com/c/go/+/301489
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-13 18:35:01 +00:00
JulianChu
8336c311f8 io: add error check to WriteString Example test
Change-Id: I9ce1c79e5799f205aec3a4dc02645ed26bdc3581
GitHub-Last-Rev: 59b637db01
GitHub-Pull-Request: golang/go#44533
Reviewed-on: https://go-review.googlesource.com/c/go/+/295389
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-13 18:03:52 +00:00
Josh Bleecher Snyder
bbf79793bd io/fs: clarify additional File interface docs
Emphasize ReadDirFile. It isn't really optional,
and all filesystems have at least one directory (".").

The remaining two additional interfaces are optimizations.
Call them that.

Fully qualify package package io identifiers.

Change-Id: Ibc425a5dfd27e08c2c10c353f780e4a6304cfd87
Reviewed-on: https://go-review.googlesource.com/c/go/+/296390
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-11 18:25:30 +00:00
Ian Lance Taylor
07c658316b io/ioutil: forward TempFile and TempDir to os package
For #42026
Fixes #44311

Change-Id: I3dabcf902d155f95800b4adf1d7578906a194ce6
Reviewed-on: https://go-review.googlesource.com/c/go/+/285378
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-02-24 15:12:08 +00:00
Tobias Klauser
08543f0715 ios/fs: mention f.dir in (*subFS).fixErr godoc
There is no dir parameter to (f *subFS).fixErr.

Change-Id: I49e42bac5e102cfab0d289658d9871429cfec515
Reviewed-on: https://go-review.googlesource.com/c/go/+/292389
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-23 09:16:54 +00:00
Russ Cox
e5b08e6d5c io/fs: allow backslash in ValidPath, reject in os.DirFS.Open
Rejecting backslash introduces problems with presenting
underlying OS file systems that contain names with backslash.
Rejecting backslash also does not Windows-proof the syntax,
because colon can also be a path separator. And we are not
going to reject colon from all names. So don't reject backslash
either.

There is a similar problem on Windows with names containing
slashes, but those are more difficult (though not impossible)
to create.

Also document and enforce that paths must be UTF-8.

Fixes #44166.

Change-Id: Iac7a9a268025c1fd31010dbaf3f51e1660c7ae2a
Reviewed-on: https://go-review.googlesource.com/c/go/+/290709
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
2021-02-11 01:10:28 +00:00
Ian Lance Taylor
cea4e21b52 io/fs: backslash is always a glob meta character
Fixes #44171

Change-Id: I2d3437a2f5b9fa0358e4664e1a8eacebed975eed
Reviewed-on: https://go-review.googlesource.com/c/go/+/290512
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-02-09 01:22:45 +00:00
Jay Conrod
b54cd94d47 embed, io/fs: clarify that leading and trailing slashes are disallowed
Fixes #44012

Change-Id: I5782cea301a65ae12ba870ff1e6b2e0a2651dc09
Reviewed-on: https://go-review.googlesource.com/c/go/+/290071
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
2021-02-05 22:35:11 +00:00
Pantonshire
25c39e4fb5 io/ioutil: fix example test for WriteFile to allow it to run in the playground
The example for WriteFile assumed the existence of a testdata/ directory, which is not present on the playground. The example now writes the file to the current working directory, rather than to testdata/.

Fixes #32916

Change-Id: I577caac7e67ba9d9941b2dd19346ad5ff61e78d9
GitHub-Last-Rev: 40f14e0adc
GitHub-Pull-Request: golang/go#43757
Reviewed-on: https://go-review.googlesource.com/c/go/+/284452
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
2021-01-22 23:03:58 +00:00
Ian Lance Taylor
c6513bca5a io/fs: minor corrections to Glob doc
The documentation for Glob was copied from filepath.Glob, and needs a bit
of tweaking: paths are not rooted at slash; the separator is always '/'.

Fixes #43537

Change-Id: Id64daa137e2762b66a82a5b9e60bbe603f4e2f5c
Reviewed-on: https://go-review.googlesource.com/c/go/+/282173
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-01-08 15:41:36 +00:00
Meng Zhuo
ee4d32249b io/fs: minor corrections to Glob release date
io/fs is introduced in 2020, not 2009 nor 2010

Change-Id: I7d63aae17b1f8c3af1ded2f639e3fb76ff2aea81
Reviewed-on: https://go-review.googlesource.com/c/go/+/282232
Trust: Meng Zhuo <mzh@golangcn.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-01-08 01:48:01 +00:00
Ian Lance Taylor
091414b5b7 io/fs: correct WalkDirFunc documentation
The documentation was copied from filepath.WalkFunc, and the copy was
not fully adjusted to the new circumstances.

Fixes #43536

Change-Id: I09687c7656e6938ebd9fc1e1643d34be88cf141d
Reviewed-on: https://go-review.googlesource.com/c/go/+/282172
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Marco Gazerro <gazerro@open2b.com>
2021-01-07 23:38:51 +00:00
Cherry Zhang
95ce805d14 io/fs: remove darwin/arm64 special condition
It isn't necessary on darwin/arm64 (macOS).

It was probably leftover from the old code when darwin/arm64
meant iOS. The test passes on iOS builder. Apparently this is
not needed either. Remove.

Change-Id: I6fa0c55d6086325d4b722862c4fe6c30bcd6e6e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/280158
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-31 02:24:55 +00:00
xinlingchao
4fd9455882 io/fs: fix typo in comment
Change-Id: Idf8e5d808c0996e0ca00979e7b8d7627f29cd10f
Reviewed-on: https://go-review.googlesource.com/c/go/+/280552
Reviewed-by: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
2020-12-28 17:15:36 +00:00
Tobias Klauser
278b9a8a4a io/fs: fix package reference in FS godoc
Reported by Ben on golang-dev
https://groups.google.com/g/golang-dev/c/gsoj5Vv15j0/m/kZxzYUdnAQAJ

Change-Id: Ic2c9600b831592ad54036b816138760b7fbb737a
Reviewed-on: https://go-review.googlesource.com/c/go/+/277377
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2020-12-14 22:04:37 +00:00
Russ Cox
7ad6596c47 io/fs: fix Sub method error text
Noticed in (and alternative to) CL 275520.

Change-Id: If6c107ee9928dd1910facd4dc66da7234cb91c39
Reviewed-on: https://go-review.googlesource.com/c/go/+/275879
Trust: Russ Cox <rsc@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-07 21:01:46 +00:00
Russ Cox
478bde3a43 io/fs: add Sub
Sub provides a convenient way to refer to a subdirectory
automatically in future operations, like Unix's chdir(2).

The CL also includes updates to fstest to check Sub implementations.

As part of updating fstest, I changed the meaning of TestFS's
expected list to introduce a special case: if you list no expected files,
that means the FS must be empty. In general it's OK not to list all
the expected files, but if you list none, that's almost certainly a
mistake - if your FS were broken and empty, you wouldn't find out.
Making no expected files mean "must be empty" makes the mistake
less likely - if your file system ever worked, then your test will keep
it working.

That change found a testing bug: embedtest was making exactly
that mistake.

Fixes #42322.

Change-Id: I63fd4aa866b30061a0e51ca9a1927e576d6ec41e
Reviewed-on: https://go-review.googlesource.com/c/go/+/274856
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-12-04 16:49:30 +00:00