summaryrefslogtreecommitdiff
path: root/src/os/file_unix.go
Commit message (Collapse)AuthorAgeFilesLines
...
* os: clarify behavior of TempDirBrad Fitzpatrick2017-06-141-2/+1
| | | | | | | | | | Fixes #19695 Change-Id: Ie5103f7905969e25dba6e5fb37344b70e807fc69 Reviewed-on: https://go-review.googlesource.com/45702 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: add some comments and remove an unused variable in rename funcBrad Fitzpatrick2017-05-181-6/+8
| | | | | | | | | | | | This slightly clarifies the just-submitted CL 40577. Updates #19647 Change-Id: I5584ad0e1abbc31796e3e5752351857f2a13d6d7 Reviewed-on: https://go-review.googlesource.com/43625 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: lstat oldname before renamingAlexander Menzhinsky2017-05-181-3/+12
| | | | | | | | | | Fixes #19647 Change-Id: Ife4f98cf2c55ee9490843797213dae2f2647b0a3 Reviewed-on: https://go-review.googlesource.com/40577 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* os: document that NewFile can return nilAlberto Donizetti2017-05-181-1/+3
| | | | | | | | Fixes #20023 Change-Id: I1bec3e69031ffcfd7ad71716be9597ec322528ff Reviewed-on: https://go-review.googlesource.com/41211 Reviewed-by: Russ Cox <rsc@golang.org>
* os: consistently return ErrClosed for closed fileIan Lance Taylor2017-04-261-0/+3
| | | | | | | | | | | | Catch all the cases where a file operation might return ErrFileClosing, and convert to ErrClosed. Use a new method for the conversion, which permits us to remove some KeepAlive calls. Change-Id: I584178f297efe6cb86f3090b2341091b412f1041 Reviewed-on: https://go-review.googlesource.com/41793 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* os, net, internal/poll: return consistent error for closed socketIan Lance Taylor2017-04-261-14/+12
| | | | | | | | | | | | | | | | | | | | | | | | | In the past we returned "use of closed network connection" when using a closed network descriptor in some way. In CL 36799 that was changed to return "use of closed file or network connection". Because programs have no access to a value of this error type (see issue #4373) they resort to doing direct string comparisons (see issue #19252). This CL restores the old error string so that we don't break programs unnecessarily with the 1.9 release. This adds a test to the net package for the expected string. For symmetry check that the os package returns the expected error, which for os already exists as os.ErrClosed. Updates #4373. Fixed #19252. Change-Id: I5b83fd12cfa03501a077cad9336499b819f4a38b Reviewed-on: https://go-review.googlesource.com/39997 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* os: fix race between file I/O and CloseIan Lance Taylor2017-04-251-2/+1
| | | | | | | | | | | | | | | Now that the os package uses internal/poll on Unix and Windows systems, it can rely on internal/poll reference counting to ensure that the file descriptor is not closed until all I/O is complete. That was already working. This CL completes the job by not trying to modify the Sysfd field when it might still be used by the I/O routines. Fixes #7970 Change-Id: I7a3daa1a6b07b7345bdce6f0cd7164bd4eaee952 Reviewed-on: https://go-review.googlesource.com/41674 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* os: use poller for file I/OIan Lance Taylor2017-02-151-55/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes the os package to use the runtime poller for file I/O where possible. When a system call blocks on a pollable descriptor, the goroutine will be blocked on the poller but the thread will be released to run other goroutines. When using a non-pollable descriptor, the os package will continue to use thread-blocking system calls as before. For example, on GNU/Linux, the runtime poller uses epoll. epoll does not support ordinary disk files, so they will continue to use blocking I/O as before. The poller will be used for pipes. Since this means that the poller is used for many more programs, this modifies the runtime to only block waiting for the poller if there is some goroutine that is waiting on the poller. Otherwise, there is no point, as the poller will never make any goroutine ready. This preserves the runtime's current simple deadlock detection. This seems to crash FreeBSD systems, so it is disabled on FreeBSD. This is issue 19093. Using the poller on Windows requires opening the file with FILE_FLAG_OVERLAPPED. We should only do that if we can remove that flag if the program calls the Fd method. This is issue 19098. Update #6817. Update #7903. Update #15021. Update #18507. Update #19093. Update #19098. Change-Id: Ia5197dcefa7c6fbcca97d19a6f8621b2abcbb1fe Reviewed-on: https://go-review.googlesource.com/36800 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* os: use extended-length paths on Windows when possibleQuentin Smith2016-11-071-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Windows has a limit of 260 characters on normal paths, but it's possible to use longer paths by using "extended-length paths" that begin with `\\?\`. This commit attempts to transparently convert an absolute path to an extended-length path, following the subtly different rules those paths require. It does not attempt to handle relative paths, which continue to be passed to the operating system unmodified. This adds a new test, TestLongPath, to the os package. This test makes sure that it is possible to write a path at least 400 characters long and runs on every platform. It also tests symlinks and hardlinks, though symlinks are not testable with our builder configuration. HasLink is moved to internal/testenv so it can be used by multiple tests. https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx has Microsoft's documentation on extended-length paths. Fixes #3358. Fixes #10577. Fixes #17500. Change-Id: I4ff6bb2ef9c9a4468d383d98379f65cf9c448218 Reviewed-on: https://go-review.googlesource.com/32451 Run-TryBot: Quentin Smith <quentin@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* os: add ErrClosed, return for use of closed FileDan Caddigan2016-10-241-1/+1
| | | | | | | | | | | | | This is clearer than syscall.EBADF. Fixes #17320. Change-Id: I14c6a362f9a6044c9b07cd7965499f4a83d2a860 Reviewed-on: https://go-review.googlesource.com/30614 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: reject Rename("old", "new") where new is a directoryRuss Cox2016-10-191-0/+4
| | | | | | | | | | | | | | Unix rejects this when new is a non-empty directory. Other systems reject this when new is a directory, empty or not. Make Unix reject empty directory too. Fixes #14527. Change-Id: Ice24b8065264c91c22cba24aa73e142386c29c87 Reviewed-on: https://go-review.googlesource.com/31358 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: deduplicate File definitionShenghou Ma2016-09-051-5/+0
| | | | | | | | | | | Fixes #16993. Change-Id: Ibe406f97d2a49acae94531d969c56dbac8ce53b2 Reviewed-on: https://go-review.googlesource.com/28511 Run-TryBot: Minux Ma <minux@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* os: consolidate filesHiroshi Ioka2016-08-161-85/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Code movement only. If someone finds function 'foo' in "foo_linux.go", they will expect that the Window version of 'foo' exists in "foo_windows.go". Current code doesn't follow this manner. For example, 'sameFile' exists in "file_unix.go", "stat_plan9.go" and "types_windows.go". The CL address that problem by following rules: * readdir family => dir.go, dir_$GOOS.go * stat family => stat.go, stat_$GOOS.go * path-functions => path_$GOOS.go * sameFile => types.go, types_$GOOS.go * process-functions => exec.go, exec_$GOOS.go * hostname => sys.go, sys_$GOOS.go Change-Id: Ic3c64663ce0b2a364d7a414351cd3c772e70187b Reviewed-on: https://go-review.googlesource.com/27035 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: single space after period.Brad Fitzpatrick2016-03-021-5/+5
| | | | | | | | | | | | | | | | | | | | The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* os, runtime: better EPIPE behavior for command line programsIan Lance Taylor2016-01-051-8/+5
| | | | | | | | | | | | | | | | | | Old behavior: 10 consecutive EPIPE errors on any descriptor cause the program to exit with a SIGPIPE signal. New behavior: an EPIPE error on file descriptors 1 or 2 cause the program to raise a SIGPIPE signal. If os/signal.Notify was not used to catch SIGPIPE signals, this will cause the program to exit with SIGPIPE. An EPIPE error on a file descriptor other than 1 or 2 will simply be returned from Write. Fixes #11845. Update #9896. Change-Id: Ic85d77e386a8bb0255dc4be1e4b3f55875d10f18 Reviewed-on: https://go-review.googlesource.com/18151 Reviewed-by: Russ Cox <rsc@golang.org>
* os: reduce allocations in Readdir on unixTaru Karttunen2015-10-301-9/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Include syscall.Stat_t on unix to the unexported fileStat structure rather than accessing it though an interface. Additionally add a benchmark for Readdir (and Readdirnames). Tested on linux, freebsd, netbsd, openbsd darwin, solaris, does not touch windows stuff. Does not change the API, as discussed on golang-dev. E.g. on linux/amd64 with a directory of 65 files: benchmark old ns/op new ns/op delta BenchmarkReaddir-4 67774 66225 -2.29% benchmark old allocs new allocs delta BenchmarkReaddir-4 334 269 -19.46% benchmark old bytes new bytes delta BenchmarkReaddir-4 25208 24168 -4.13% Change-Id: I44ef72a04ad7055523a980f29aa11122040ae8fe Reviewed-on: https://go-review.googlesource.com/16423 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* os: touch up the EINTR retry loop in OpenFileAaron Jacobs2015-09-171-5/+10
| | | | | | | | | In particular, don't use goto and do restrict the behavior to darwin. This addresses comments from http://golang.org/cl/14484. Change-Id: I5b99e1762d1c5b27fdd12b72a5c6d981f6a92f0f Reviewed-on: https://go-review.googlesource.com/14673 Reviewed-by: Rob Pike <r@golang.org>
* os: handle EINTR from open(2).Aaron Jacobs2015-09-171-0/+8
| | | | | | | | | | | | | | | | | | | | | | The man page for sigaction(2) on OS X doesn't guarantee that SA_RESTART will work for open(2) on regular files: The affected system calls include open(2), read(2), write(2), sendto(2), recvfrom(2), sendmsg(2) and recvmsg(2) on a communications channel or a slow device (such as a terminal, but not a regular file) and during a wait(2) or ioctl(2). I've never observed EINTR from open(2) for a traditional file system such as HFS+, but it's easy to observe with a fuse file system that is slightly slow (cf. https://goo.gl/UxsVgB). After this change, the problem can no longer be reproduced when calling os.OpenFile. Fixes #11180. Change-Id: I967247430e20a7d29a285b3d76bf3498dc4773db Reviewed-on: https://go-review.googlesource.com/14484 Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* os: remove stuttering return value namesBrad Fitzpatrick2015-07-181-7/+7
| | | | | | | | | | | | | | | Old style. Make it compliant with our code review comments document. Also, make WriteString's return parameter named 'n', not 'ret', for consistency. Noticed during another documentation review. Change-Id: Ie88910c5841f8353bc5c0152e2168b497578e15e Reviewed-on: https://go-review.googlesource.com/12324 Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* os: windows Rename should overwrite destination file.Daniel Theophanes2015-04-091-0/+8
| | | | | | | | | | Rename now uses MoveFileEx which was previously not available to use because it is not supported on Windows 2000. Change-Id: I583d029c4467c9be6d1574a790c423559b441e87 Reviewed-on: https://go-review.googlesource.com/6140 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
* os: don't return Chmod's error from Mkdir and OpenFileKato Kazuyoshi2015-03-201-2/+2
| | | | | | | | | | | | | | Mkdir and OpenFile call Chmod internally on *BSD and Solaris, because these OSes don't handle the sticky bit correctly. However Chmod's error should be ignored. It shouldn't hide the fact that a file itself is created. Fixes #8383 Change-Id: Ia2e0b2ba72712d73a0a48ba5a263432e0fff31a5 Reviewed-on: https://go-review.googlesource.com/2057 Reviewed-by: Russ Cox <rsc@golang.org>
* os: handle the sticky bit separately for *BSD and SolarisKato Kazuyoshi2014-12-171-0/+12
| | | | | | | | | | | | open(2) and mkdir(2) won't set the sticky bit on *BSD and Solaris. This behavior is mentioned on sticky(8). see also: https://github.com/dotcloud/docker/pull/6587 Fixes #8383. Change-Id: Ic4733700f9926b9fc2b6fd1f998acec34e518764 Reviewed-on: https://go-review.googlesource.com/1673 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* os: document that users of Fd should keep f aliveRuss Cox2014-11-061-0/+1
| | | | | | | | | Fixes #9046. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/162680043
* os: fix buildRuss Cox2014-10-281-1/+1
| | | | | | TBR=crawshaw CC=golang-codereviews https://golang.org/cl/162390043
* os: do not assume syscall i/o funcs return n=0 on errorRuss Cox2014-10-281-5/+5
| | | | | | | | | Fixes #9007. LGTM=iant, r R=r, iant CC=golang-codereviews https://golang.org/cl/160670043
* build: move package sources from src/pkg to srcRuss Cox2014-09-081-0/+338
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.