mirror of
https://github.com/restic/restic.git
synced 2025-01-21 06:48:35 +00:00
26 lines
442 B
Go
26 lines
442 B
Go
|
package fs
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"golang.org/x/sys/unix"
|
||
|
)
|
||
|
|
||
|
func openMetadataHandle(path string, flag int) (*os.File, error) {
|
||
|
// O_PATH|O_NOFOLLOW is necessary to also be able to get a handle to symlinks
|
||
|
flags := unix.O_PATH
|
||
|
if flag&O_NOFOLLOW != 0 {
|
||
|
flags |= O_NOFOLLOW
|
||
|
}
|
||
|
if flag&O_DIRECTORY != 0 {
|
||
|
flags |= O_DIRECTORY
|
||
|
}
|
||
|
|
||
|
f, err := os.OpenFile(path, flags, 0)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
_ = setFlags(f)
|
||
|
return f, nil
|
||
|
}
|