aboutsummaryrefslogtreecommitdiff
path: root/src/io
AgeCommit message (Collapse)Author
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>
2020-10-14io: add a new ReadSeekCloser interfaceMohamed Attahri
Research showed that this interface is defined frequently enough in real-world usage to justify its addition to the standard library. Fixes #40962 Change-Id: I522fe8f9b8753c3fa42ccc1def49611cf88cd340 GitHub-Last-Rev: 6a45be66b42e482a06d9809d9da20c195380988b GitHub-Pull-Request: golang/go#41939 Reviewed-on: https://go-review.googlesource.com/c/go/+/261577 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Trust: Dmitri Shuralyov <dmitshur@golang.org>
2020-10-13io: add ErrBadWriteCountTao Qingyun
Fixes #39978 Change-Id: Ib41459861ba9f7cf0bf1fc95b1479c358c4bdbd8 GitHub-Last-Rev: 19cbb1461ca04a8eb64f0c4f354d8fb81a70d4f3 GitHub-Pull-Request: golang/go#39989 Reviewed-on: https://go-review.googlesource.com/c/go/+/240740 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-01io: make clear that EOF should not be wrappedRuss Cox
For #40827. Change-Id: Ifd108421abd8d0988dd7b985e4f9e2bd5356964a Reviewed-on: https://go-review.googlesource.com/c/go/+/258524 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-06-04io/ioutil: update WriteFile to clarify it does not change permissions if the ↵joshuabezaleel
file exists. The existing documentation of WriteFile does not make it clear for non-native English speakers that it will not change the permissions if the file already exists before. Fixes #35711 Change-Id: If861c3e3700957fc9ac3d5313351c57d399d3f58 Reviewed-on: https://go-review.googlesource.com/c/go/+/218417 Reviewed-by: Rob Pike <r@golang.org>
2020-04-13io: simplify ExamplesEric
- CopyN: 5 creates ambiguity with respect to whitespace and upperbound - TeeReader less boilerplate and displays a common usage of it - SectionReader_* all sections unified to 5:17 for clarity - SectionReader_Seek uses io.Copy to stdout like other examples - Seeker_Seek remove useless prints - Pipe print reader like other examples Updates #36417 Change-Id: Ibd01761d5a5786cdb1ea934f7a98f8302430c8a5 GitHub-Last-Rev: 4c17f9a8e32d89743b7eaec7c52032256972cc0a GitHub-Pull-Request: golang/go#38379 Reviewed-on: https://go-review.googlesource.com/c/go/+/227868 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-02testing: add TB.TempDirBrad Fitzpatrick
Fixes #35998 Change-Id: I87c6bf4e34e832be68862ca16ecfa6ea12048d31 Reviewed-on: https://go-review.googlesource.com/c/go/+/226877 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-03-12io: add a comment about how to turn a Reader into ByteReaderRob Pike
Offered as an alternative to CL 221380, which was more tutorial than necessary. Update #37344 Change-Id: Ide673b0b97983c2c2319a9311dc3d0a10567e6c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/223097 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-02-26io/ioutil: reject path separators in TempDir, TempFile patternConstantin Konstantinidis
Fixes #33920 Change-Id: I2351a1caa80c086ff5a8e02aad70d996be7aac35 Reviewed-on: https://go-review.googlesource.com/c/go/+/212597 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-21io: check n in testReadAtLeastDavor Kapsa
Change-Id: I53859d4d3c729cce9f73b14dc2dd8571f7e7ffb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/216457 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2019-12-27io: show ErrUnexpectedEOF in ExampleReadAtLeastIan Lance Taylor
Fixes #36245 Change-Id: I10ce50b0cc28b15f4e7be85b8f12cf9d0e4fac96 Reviewed-on: https://go-review.googlesource.com/c/go/+/212404 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-12-10all: fix a number of misuses of the word "an"Daniel Martí
After golang.org/cl/210124, I wondered if the same error had gone unnoticed elsewhere. I quickly spotted another dozen mistakes after reading through the output of: git grep '\<[Aa]n [bcdfgjklmnpqrtvwyz][a-z]' Many results are false positives for acronyms like "an mtime", since it's pronounced "an em-time". However, the total amount of output isn't that large given how simple the grep pattern is. Change-Id: Iaa2ca69e42f4587a9e3137d6c5ed758887906ca6 Reviewed-on: https://go-review.googlesource.com/c/go/+/210678 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Zach Jones <zachj1@gmail.com> Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-11-27doc: clarify interaction of ioutil.WriteFile with umaskMostyn Bramley-Moore
Note that ioutil.WriteFile's perm argument is the value before the umask is applied. Fixes #35835 Change-Id: I61cd9c88bced3be52b616d86e060cd3fd912ab1f Change-Id: I61cd9c88bced3be52b616d86e060cd3fd912ab1f GitHub-Last-Rev: 0069abb7c5d904fb11448148f44db023dbcf74aa GitHub-Pull-Request: golang/go#35836 Reviewed-on: https://go-review.googlesource.com/c/go/+/208838 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-11-05io/ioutil: Fix dropped test errorLars Lehtonen
Change-Id: I9cfaba4f1af23ab67627bf496739311e4d1984c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/205245 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-22syscall: respect permission bits on file opening on WindowsJason A. Donenfeld
On Windows, os.Chmod and syscall.Chmod toggle the FILE_ATTRIBUTES_ READONLY flag depending on the permission bits. That's a bit odd but I guess some compromises were made at some point and this is what was chosen to map to a Unix concept that Windows doesn't really have in the same way. That's fine. However, the logic used in Chmod was forgotten from os.Open and syscall.Open, which then manifested itself in various places, most recently, go modules' read-only behavior. This makes syscall.Open consistent with syscall.Chmod and adds a test for the permission _behavior_ using ioutil. By testing the behavior instead of explicitly testing for the attribute bits we care about, we make sure this doesn't regress in unforeseen ways in the future, as well as ensuring the test works on platforms other than Windows. In the process, we fix some tests that never worked and relied on broken behavior, as well as tests that were disabled on Windows due to the broken behavior and had TODO notes. Fixes #35033 Change-Id: I6f7cf54517cbe5f6b1678d1c24f2ab337edcc7f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/202439 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-21io: make CopyBuffer docs state when buf is not usedsandyskies
Document that if either src implements the WriteTo interface or if dst implements the ReaderFrom interface, then buf will not be used. Fixes #32276 Change-Id: Id0a69c90e255e694e7ec9f79ffe4d8391441e59e GitHub-Last-Rev: 750e7e86d5d9b985fae7f2329fd219cacf72a62b GitHub-Pull-Request: golang/go#32279 Reviewed-on: https://go-review.googlesource.com/c/go/+/179137 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-10-16io/ioutil: support predictable prefix,suffix for TempDir with *Emmanuel T Odeke
Allow TempDir to create directories with predictable prefixes and suffixes, separated by the last "*", for example: "prefix*suffix" will now expand to "prefix" + <RANDOM_VALUE> + "suffix" RELNOTE=yes Fixes #33805. Change-Id: I85fa73ae6a684ce820d1810c82a60765eb9c4a42 Reviewed-on: https://go-review.googlesource.com/c/go/+/198488 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-01io/ioutil: don't check for short write in WriteFilejsign
*os.File already does it. Fixes #33064 Change-Id: I3edf0a31bf6d6e5023f47f01ebc92ed057357278 GitHub-Last-Rev: e6a5ba45d7e74def668adf145f46387ef27f5d28 GitHub-Pull-Request: golang/go#33065 Reviewed-on: https://go-review.googlesource.com/c/go/+/185857 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-28io: add error check on pipe close functions to avoid error overwritingJordi Martin
The current implementation allows multiple calls `Close` and `CloseWithError` in every side of the pipe, as a result, the original error can be overwritten. This CL fixes this behavior adding an error existence check on `atomicError` type and keeping the first error still available. Fixes #24283 Change-Id: Iefe8f758aeb775309424365f8177511062514150 GitHub-Last-Rev: b559540d7af3a0dad423816b695525ac2d6bd864 GitHub-Pull-Request: golang/go#33239 Reviewed-on: https://go-review.googlesource.com/c/go/+/187197 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-26io: align style of test comments in multi_test.goDerek Phan
Change-Id: Ic93a084311de46461ed3b30f4ac2fe11311e74d7 GitHub-Last-Rev: 32fbd63b10d0fa489406333ff6f8b6708974a73c GitHub-Pull-Request: golang/go#29705 Reviewed-on: https://go-review.googlesource.com/c/157642 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matt Layher <mdlayher@gmail.com>
2018-10-03io: export StringWriterDaniel Martí
And start using it elsewhere in the standard library, removing the copies in the process. While at it, rewrite the io.WriteString godoc to be more clear, since it can now make reference to the defined interface. Fixes #27946. Change-Id: Id5ba223c09c19e5fb49815bd3b1bd3254fc786f3 Reviewed-on: https://go-review.googlesource.com/c/139457 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-08-30ghchinoy: add example for ioutil.WriteFileG. Hussain Chinoy
Change-Id: I65c3bda498562fdf39994ec1cadce7947e2d84b5 Reviewed-on: https://go-review.googlesource.com/132277 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-05-06io: calculate buffer size only when neededAuthor Name
Change-Id: I930be9027fb972198b3d44816a5e4f53ff7eb5ea Reviewed-on: https://go-review.googlesource.com/111642 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-12io/ioutil: change TempFile prefix to a patternTom Limoncelli
Users of TempFile need to be able to supply the suffix, especially when using operating systems that give semantic meaning to the filename extension such as Windows. Renaming the file to include an extension after the fact is insufficient as it could lead to race conditions. If the string given to TempFile includes a "*", the random string replaces the "*". For example "myname.*.bat" will result in a random filename such as "myname.123456.bat". If no "*' is included the old behavior is retained, and the random digits are appended to the end. If multiple "*" are included, the final one is replaced, thus permitting a pathological programmer to create filenames such as "foo*.123456.bat" but not "foo.123456.*.bat" Fixes #4896 Change-Id: Iae7f0980b4de6d7d31b87c8c3c3d40767b283c1f Reviewed-on: https://go-review.googlesource.com/105675 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>