fs: fix compilation on non-Linux/macOS/Windows

This commit is contained in:
Michael Eischer 2024-11-30 17:31:52 +01:00
parent 4a9603d253
commit cee05947b5
3 changed files with 60 additions and 48 deletions

View file

@ -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)

View 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
}

View 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")
}