aboutsummaryrefslogtreecommitdiff
path: root/src/io
AgeCommit message (Collapse)Author
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
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-11-11io: add error check to TeeReader Examplejiahua wang
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-10-29io: remove UTF8 specified document for RuneReaderMeng Zhuo
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-09-28io: add examples for (*SectionReader) Read/Sizejiahua wang
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-28io: update ByteScanner and RuneScanner docs to match long-standing ↵Bryan C. Mills
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-27io: avoid integer overflow in NewSectionReaderIan Lance Taylor
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-22io: fix spelling in documentationjiahua wang
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-22io: fix spelling in documentation for writerFuncjiahua wang
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-21io: relax documented Seeker invariants that do not hold in practiceBryan C. Mills
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-08-19io: unexport internal methodsRoger Peppe
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-02io/fs: don't use absolute path in DirEntry.Name docIan Lance Taylor
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-06-02io/fs: minor corrections to Sub docsIan Lance Taylor
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-05-21io/fs: added an example for io/fs.WalkDirAdam Mitha
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-04-21io/fs: document that caller can modify slice returned by ReadFileIan Lance Taylor
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-03io/fs: implement subFS.SubDrew Richardson
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-03-25io/fs: implement FileInfoToDirEntryMichel Levieux
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-23io: fix spelling in documentation for io.DiscardSimão Gomes Viana
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: e3257ca272dff42ed7d07b6e6a5fc49493772653 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-19io/ioutil: use correct Go version in redirection commentsIan Lance Taylor
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-13io/fs: use testing.T.TempDir in TestWalkDirTobias Klauser
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-13io: add error check to WriteString Example testJulianChu
Change-Id: I9ce1c79e5799f205aec3a4dc02645ed26bdc3581 GitHub-Last-Rev: 59b637db0154e55ddfdd55e54b9596dc3a0ad32d 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-11io/fs: clarify additional File interface docsJosh Bleecher Snyder
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-02-24io/ioutil: forward TempFile and TempDir to os packageIan Lance Taylor
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-23ios/fs: mention f.dir in (*subFS).fixErr godocTobias Klauser
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-11io/fs: allow backslash in ValidPath, reject in os.DirFS.OpenRuss Cox
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-09io/fs: backslash is always a glob meta characterIan Lance Taylor
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-05embed, io/fs: clarify that leading and trailing slashes are disallowedJay Conrod
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-01-22io/ioutil: fix example test for WriteFile to allow it to run in the playgroundPantonshire
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: 40f14e0adc4ebc00fb2946fe0cbaf8e0cb99f62c 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-08io/fs: minor corrections to Glob docIan Lance Taylor
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-08io/fs: minor corrections to Glob release dateMeng Zhuo
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-07io/fs: correct WalkDirFunc documentationIan Lance Taylor
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>
2020-12-31io/fs: remove darwin/arm64 special conditionCherry Zhang
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-28io/fs: fix typo in commentxinlingchao
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-14io/fs: fix package reference in FS godocTobias Klauser
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-07io/fs: fix Sub method error textRuss Cox
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-04io/fs: add SubRuss Cox
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-02os: add ReadFile, WriteFile, CreateTemp (was TempFile), MkdirTemp (was ↵Russ Cox
TempDir) from io/ioutil io/ioutil was a poorly defined collection of helpers. Proposal #40025 moved out the generic I/O helpers to io. This CL for proposal #42026 moves the OS-specific helpers to os, making the entire io/ioutil package deprecated. For #42026. Change-Id: I018bcb2115ef2ff1bc7ca36a9247eda429af21ad Reviewed-on: https://go-review.googlesource.com/c/go/+/266364 Trust: Russ Cox <rsc@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2020-11-19io/fs: make WalkDirFunc parameter name consistent with doc commentfzipp
The the DirEntry parameter of WalkDirFunc is referred to as `d` in the doc comment. Change-Id: Ibfcf7908eaa0ef1309898150e8fd71101e7de09b GitHub-Last-Rev: e858c52d81b93d293621d7e744bdcb7d6cbd412c GitHub-Pull-Request: golang/go#42447 Reviewed-on: https://go-review.googlesource.com/c/go/+/268277 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Russ Cox <rsc@golang.org>
2020-11-11io/fs: fix reference to WalkFuncRuss Cox
The comment explains differences between WalkDirFunc and WalkFunc, but when this code moved out of path/filepath, we forgot to change the reference to be filepath.WalkFunc. Fix that. (The text should not be deleted, because path/filepath does not contain this type - WalkDirFunc - nor this text anymore.) Pointed out by Carl Johnson on CL 243916 post-submit. For #41190. Change-Id: I44c64d0b7e60cd6d3694cfd6d0b95468ec4612fe Reviewed-on: https://go-review.googlesource.com/c/go/+/268417 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@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-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 io/ioutil to ioRuss Cox
The old ioutil 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. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-10-20io: adopt Discard, NopCloser, ReadAll from io/ioutilRuss Cox
As proposed and approved in #40025, Discard, NopCloser, and ReadAll do not really fit into io/ioutil, which exists mainly to hold things that would cause an import cycle if implemented in io itself, which is to say things that import "os". These three do not import "os" - they are generic io helpers like many of the things in io itself, so it makes sense for them to be there. Fixes #40025. Change-Id: I77f47e9b2a72839edf7446997936631980047b67 Reviewed-on: https://go-review.googlesource.com/c/go/+/263141 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-20io/fs: add Glob and GlobFSRuss Cox
Add Glob helper function, GlobFS interface, and test. Add Glob method to fstest.MapFS. Add testing of Glob method to fstest.TestFS. For #41190. Change-Id: If89dd7f63e310ba5ca2651340267a9ff39fcc0c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/243915 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20io/fs: add ReadDir and ReadDirFSRuss Cox
Add ReadDir helper function, ReadDirFS interface, and test. Add ReadDir method to fstest.MapFS. Add testing of ReadDir method to fstest.TestFS. For #41190. Change-Id: Ib860770ec7433ba77b29e626682b238f1b3bf54f Reviewed-on: https://go-review.googlesource.com/c/go/+/243914 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20io/fs: add Stat and StatFSRuss Cox
Add Stat helper function, StatFS interface, and test. Add Stat method to fstest.MapFS. Add testing of Stat method to fstest.TestFS. For #41190. Change-Id: Icf8b6eb1c3fa6f93a9be8405ec5a9468fb1da97b Reviewed-on: https://go-review.googlesource.com/c/go/+/243913 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20io/fs: add ReadFile and ReadFileFSRuss Cox
Add ReadFile helper function, ReadFileFS interface, and test. Add ReadFile method to fstest.MapFS. Add testing of ReadFile method to fstest.TestFS. For #41190. Change-Id: I5b6a41e2e582824e570463b698b635abaa436c32 Reviewed-on: https://go-review.googlesource.com/c/go/+/243912 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-20io/fs: add FS, File, ReadDirFile; move DirEntry from osRuss Cox
These are the core interfaces for the io/fs design. See #41190 and https://golang.org/s/draft-iofs-design for details. DirEntry was left behind in the previous move from os but is needed for ReadDirFile, so it moves in this commit. Also apply a couple comment changes suggested in the review of CL 261540. For #41190. Change-Id: I087741545139ed30b9ba5db728a0bad71129500b Reviewed-on: https://go-review.googlesource.com/c/go/+/243908 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Go Bot <gobot@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-20io/fs: move FileInfo, FileMode, PathError, ErrInvalid, ... from os to io/fsRuss Cox
First step of creating the new io/fs package. For #41190. Change-Id: I1339b1abdd533b0f1deab283628088b2f706fb5b Reviewed-on: https://go-review.googlesource.com/c/go/+/243906 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-10-16io: unexport ErrBadWriteCountRuss Cox
It was added in CL 240740 to fix #39978 but without any discussion of the exported API. The error can still be returned to fix the issue, without adding new public API to package io. Also fix the error message to refer to lower-case write like the other errors in the package. Change-Id: I134de5eaf3ac903d73913c5cadcde904c5255d79 Reviewed-on: https://go-review.googlesource.com/c/go/+/262877 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>