mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
filch: use F_NOCACHE on macOS
For #1320 Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
parent
dec01ef22b
commit
de94fe0f87
@ -131,11 +131,11 @@ func New(filePrefix string, opts Options) (f *Filch, err error) {
|
|||||||
path1 := filePrefix + ".log1.txt"
|
path1 := filePrefix + ".log1.txt"
|
||||||
path2 := filePrefix + ".log2.txt"
|
path2 := filePrefix + ".log2.txt"
|
||||||
|
|
||||||
f1, err = os.OpenFile(path1, os.O_CREATE|os.O_RDWR, 0600)
|
f1, err = openFileSync(path1, os.O_CREATE|os.O_RDWR, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f2, err = os.OpenFile(path2, os.O_CREATE|os.O_RDWR, 0600)
|
f2, err = openFileSync(path2, os.O_CREATE|os.O_RDWR, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
27
logtail/filch/openfilesync_darwin.go
Normal file
27
logtail/filch/openfilesync_darwin.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//+build darwin
|
||||||
|
|
||||||
|
package filch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func openFileSync(path string, flag int, perm os.FileMode) (*os.File, error) {
|
||||||
|
f, err := os.OpenFile(path, flag, perm)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = unix.FcntlInt(uintptr(f.Fd()), syscall.F_NOCACHE, 1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("openFileSync: %w", err)
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
|
}
|
16
logtail/filch/openfilesync_notdarwin.go
Normal file
16
logtail/filch/openfilesync_notdarwin.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//+build !darwin
|
||||||
|
|
||||||
|
package filch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func openFileSync(path string, flag int, perm os.FileMode) (*os.File, error) {
|
||||||
|
// TODO(crawshaw): on Linux and FreeBSD, use O_SYNC
|
||||||
|
return os.OpenFile(path, flag, perm)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user