]> Cypherpunks repositories - gostls13.git/commit
os: use O_EXCL instead of O_TRUNC in CopyFS to disallow rewriting existing files
authorAndy Pan <i@andypan.me>
Fri, 16 Aug 2024 00:04:57 +0000 (08:04 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 16 Aug 2024 23:34:41 +0000 (23:34 +0000)
commitaa5d672a00f5bf64865d0e821623ed29bc416405
treed6a40cbc6aaf3c593ef03e8fe434c5e2aee565ee
parent660e7d60f28ed4b2c14f6e1fcf6d0e5a7f4aa1e0
os: use O_EXCL instead of O_TRUNC in CopyFS to disallow rewriting existing files

On Linux, a call to creat() is equivalent to calling open() with flags
equal to O_CREAT|O_WRONLY|O_TRUNC, which applies to other platforms
as well in a similar manner. Thus, to force CopyFS's behavior to
comply with the function comment, we need to replace O_TRUNC with O_EXCL.

Fixes #68895

Change-Id: I3e2ab153609d3c8cf20ce5969d6f3ef593833cd1
Reviewed-on: https://go-review.googlesource.com/c/go/+/606095
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/dir.go
src/os/os_test.go