Skip to content

Commit 007bdb1

Browse files
committed
fetcher: give tmpfile ability to create
When forcing the linux fallback (no O_TMPFILE) it triggers an error: encountered errors: openat fetcher.xxxxxxxx: no such file or directory, when adding the O_CREATE flag the fallback's error was fixed. This also adds the flags to the unix and windows variants. Signed-off-by: crozzy <joseph.crosland@gmail.com>
1 parent 2130b31 commit 007bdb1

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

libindex/tempfile_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Loop:
4646
flag := os.O_WRONLY
4747
if !tmpOK {
4848
name = fetchFilename()
49+
flag |= os.O_CREATE | os.O_EXCL // Create new file, fail if exists
4950
} else {
5051
flag |= unix.O_TMPFILE
5152
}

libindex/tempfile_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func openTemp(dir *os.Root) (f *os.File, err error) {
13-
const flag = os.O_WRONLY
13+
const flag = os.O_WRONLY | os.O_CREATE | os.O_EXCL
1414
for {
1515
name := fetchFilename()
1616
f, err = dir.OpenFile(name, flag, 0o644)

libindex/tempfile_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func openTemp(dir *os.Root) (f *os.File, err error) {
1313
// Copied out of golang.org/x/sys/windows
1414
const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000
15-
const flag = os.O_WRONLY | FILE_FLAG_DELETE_ON_CLOSE
15+
const flag = os.O_WRONLY | os.O_CREATE | os.O_EXCL | FILE_FLAG_DELETE_ON_CLOSE
1616
for {
1717
name := fetchFilename()
1818
f, err = dir.OpenFile(name, flag, 0o644)

0 commit comments

Comments
 (0)