-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66fe210
commit 758477b
Showing
3 changed files
with
64 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package agent | ||
|
||
import ( | ||
"errors" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
|
||
errw "github.com/pkg/errors" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// platform-specific UID check. | ||
func checkPathOwner(uid int, info fs.FileInfo) error { | ||
stat, ok := info.Sys().(*syscall.Stat_t) | ||
if !ok { | ||
// should be impossible on Linux | ||
return errw.New("cannot convert to syscall.Stat_t") | ||
} | ||
if uid != int(stat.Uid) { | ||
return errw.Errorf("%s is owned by UID %d but the current UID is %d", info.Name(), stat.Uid, uid) | ||
} | ||
return nil | ||
} | ||
|
||
func SyncFS(syncPath string) (errRet error) { | ||
file, errRet := os.Open(filepath.Dir(syncPath)) | ||
if errRet != nil { | ||
return errw.Wrapf(errRet, "syncing fs %s", syncPath) | ||
} | ||
_, _, err := unix.Syscall(unix.SYS_SYNCFS, file.Fd(), 0, 0) | ||
if err != 0 { | ||
errRet = errw.Wrapf(err, "syncing fs %s", syncPath) | ||
} | ||
return errors.Join(errRet, file.Close()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package agent | ||
|
||
import ( | ||
"io/fs" | ||
"syscall" | ||
) | ||
|
||
// platform-specific UID check. | ||
func checkPathOwner(uid int, info fs.FileInfo) error { | ||
// todo: figure this out on windows. | ||
return nil | ||
} | ||
|
||
func SyncFS(syncPath string) error { | ||
handle, err := syscall.Open(syncPath, syscall.O_RDWR, 0) | ||
if err != nil { | ||
return err | ||
} | ||
defer syscall.CloseHandle(handle) | ||
err = syscall.Fsync(handle) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |