]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.23] os: use O_EXCL instead of O_TRUNC in CopyFS to disallow rewri...
authorAndy Pan <i@andypan.me>
Fri, 16 Aug 2024 00:04:57 +0000 (08:04 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 21 Aug 2024 17:05:16 +0000 (17:05 +0000)
commit3c9340557cf1e13c2fe61c6b894ba284711dfb85
tree0c43bc10cc8f324f7b36fa34b35899bc579028e6
parentdbecb416d1d4609a1c8185921cb9cf132ac4a11c
[release-branch.go1.23] os: use O_EXCL instead of O_TRUNC in CopyFS to disallow rewriting existing files does not exist

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 #68907

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>
(cherry picked from commit aa5d672a00f5bf64865d0e821623ed29bc416405)
Reviewed-on: https://go-review.googlesource.com/c/go/+/606415
src/os/dir.go
src/os/os_test.go