fs: fix compilation on non-Linux/macOS/Windows
This commit is contained in:
parent
4a9603d253
commit
cee05947b5
3 changed files with 60 additions and 48 deletions
|
@ -199,54 +199,6 @@ func (f *pathLocalFile) MakeReadable() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type fdLocalFile struct {
|
||||
localFile
|
||||
flag int
|
||||
metadataOnly bool
|
||||
}
|
||||
|
||||
var _ File = &fdLocalFile{}
|
||||
|
||||
func newFdLocalFile(name string, flag int, metadataOnly bool) (*fdLocalFile, error) {
|
||||
var f *os.File
|
||||
var err error
|
||||
if metadataOnly {
|
||||
f, err = openMetadataHandle(name, flag)
|
||||
} else {
|
||||
f, err = openReadHandle(name, flag)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
meta := newFdMetadataHandle(name, f)
|
||||
return &fdLocalFile{
|
||||
localFile: localFile{
|
||||
name: name,
|
||||
f: f,
|
||||
meta: meta,
|
||||
},
|
||||
flag: flag,
|
||||
metadataOnly: metadataOnly,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *fdLocalFile) MakeReadable() error {
|
||||
if !f.metadataOnly {
|
||||
panic("file is already readable")
|
||||
}
|
||||
|
||||
newF, err := reopenMetadataHandle(f.f)
|
||||
// old handle is no longer usable
|
||||
f.f = nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.f = newF
|
||||
f.meta = newFdMetadataHandle(f.name, newF)
|
||||
f.metadataOnly = false
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildLocalFile(name string, flag int, metadataOnly bool) (File, error) {
|
||||
useFd := runtime.GOOS == "linux" || runtime.GOOS == "windows" || runtime.GOOS == "darwin"
|
||||
useFd = useFd && feature.Flag.Enabled(feature.FilehandleBasedBackup)
|
||||
|
|
53
internal/fs/fs_local_fd.go
Normal file
53
internal/fs/fs_local_fd.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
//go:build linux || darwin || windows
|
||||
|
||||
package fs
|
||||
|
||||
import "os"
|
||||
|
||||
type fdLocalFile struct {
|
||||
localFile
|
||||
flag int
|
||||
metadataOnly bool
|
||||
}
|
||||
|
||||
var _ File = &fdLocalFile{}
|
||||
|
||||
func newFdLocalFile(name string, flag int, metadataOnly bool) (*fdLocalFile, error) {
|
||||
var f *os.File
|
||||
var err error
|
||||
if metadataOnly {
|
||||
f, err = openMetadataHandle(name, flag)
|
||||
} else {
|
||||
f, err = openReadHandle(name, flag)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
meta := newFdMetadataHandle(name, f)
|
||||
return &fdLocalFile{
|
||||
localFile: localFile{
|
||||
name: name,
|
||||
f: f,
|
||||
meta: meta,
|
||||
},
|
||||
flag: flag,
|
||||
metadataOnly: metadataOnly,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *fdLocalFile) MakeReadable() error {
|
||||
if !f.metadataOnly {
|
||||
panic("file is already readable")
|
||||
}
|
||||
|
||||
newF, err := reopenMetadataHandle(f.f)
|
||||
// old handle is no longer usable
|
||||
f.f = nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.f = newF
|
||||
f.meta = newFdMetadataHandle(f.name, newF)
|
||||
f.metadataOnly = false
|
||||
return nil
|
||||
}
|
7
internal/fs/fs_local_nofd.go
Normal file
7
internal/fs/fs_local_nofd.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
//go:build !linux && !darwin && !windows
|
||||
|
||||
package fs
|
||||
|
||||
func newFdLocalFile(name string, flag int, metadataOnly bool) (File, error) {
|
||||
panic("not supported")
|
||||
}
|
Loading…
Reference in a new issue