From cee05947b52a9a97bfbfb92341278afe1dd3461e Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 30 Nov 2024 17:31:52 +0100 Subject: [PATCH] fs: fix compilation on non-Linux/macOS/Windows --- internal/fs/fs_local.go | 48 -------------------------------- internal/fs/fs_local_fd.go | 53 ++++++++++++++++++++++++++++++++++++ internal/fs/fs_local_nofd.go | 7 +++++ 3 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 internal/fs/fs_local_fd.go create mode 100644 internal/fs/fs_local_nofd.go diff --git a/internal/fs/fs_local.go b/internal/fs/fs_local.go index 573c14316..3b97c1fc4 100644 --- a/internal/fs/fs_local.go +++ b/internal/fs/fs_local.go @@ -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) diff --git a/internal/fs/fs_local_fd.go b/internal/fs/fs_local_fd.go new file mode 100644 index 000000000..c00e5d841 --- /dev/null +++ b/internal/fs/fs_local_fd.go @@ -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 +} diff --git a/internal/fs/fs_local_nofd.go b/internal/fs/fs_local_nofd.go new file mode 100644 index 000000000..cd33c2dd1 --- /dev/null +++ b/internal/fs/fs_local_nofd.go @@ -0,0 +1,7 @@ +//go:build !linux && !darwin && !windows + +package fs + +func newFdLocalFile(name string, flag int, metadataOnly bool) (File, error) { + panic("not supported") +}