From 623ba92b986c856981f30d0f7351668e9532c8f0 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 2 Nov 2024 17:47:54 +0100 Subject: [PATCH] fs: drop unused permission parameter from OpenFile --- internal/archiver/archiver.go | 2 +- internal/archiver/archiver_test.go | 16 ++++++++-------- internal/archiver/exclude.go | 2 +- internal/archiver/file_saver_test.go | 2 +- internal/fs/file.go | 2 +- internal/fs/fs_local.go | 4 ++-- internal/fs/fs_local_vss.go | 4 ++-- internal/fs/fs_local_vss_test.go | 2 +- internal/fs/fs_reader.go | 2 +- internal/fs/fs_reader_test.go | 8 ++++---- internal/fs/fs_track.go | 4 ++-- internal/fs/interface.go | 2 +- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index efa0d2945..fb03c88fc 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -497,7 +497,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous // reopen file and do an fstat() on the open file to check it is still // a file (and has not been exchanged for e.g. a symlink) - file, err := arch.FS.OpenFile(target, fs.O_RDONLY|fs.O_NOFOLLOW, 0) + file, err := arch.FS.OpenFile(target, fs.O_RDONLY|fs.O_NOFOLLOW) if err != nil { debug.Log("Openfile() for %v returned error: %v", target, err) return filterError(err) diff --git a/internal/archiver/archiver_test.go b/internal/archiver/archiver_test.go index 97d27dc64..ff072fa36 100644 --- a/internal/archiver/archiver_test.go +++ b/internal/archiver/archiver_test.go @@ -76,7 +76,7 @@ func saveFile(t testing.TB, repo archiverRepo, filename string, filesystem fs.FS startCallback = true } - file, err := arch.FS.OpenFile(filename, fs.O_RDONLY|fs.O_NOFOLLOW, 0) + file, err := arch.FS.OpenFile(filename, fs.O_RDONLY|fs.O_NOFOLLOW) if err != nil { t.Fatal(err) } @@ -1665,8 +1665,8 @@ type MockFS struct { bytesRead map[string]int // tracks bytes read from all opened files } -func (m *MockFS) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error) { - f, err := m.FS.OpenFile(name, flag, perm) +func (m *MockFS) OpenFile(name string, flag int) (fs.File, error) { + f, err := m.FS.OpenFile(name, flag) if err != nil { return f, err } @@ -2056,12 +2056,12 @@ type TrackFS struct { m sync.Mutex } -func (m *TrackFS) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error) { +func (m *TrackFS) OpenFile(name string, flag int) (fs.File, error) { m.m.Lock() m.opened[name]++ m.m.Unlock() - return m.FS.OpenFile(name, flag, perm) + return m.FS.OpenFile(name, flag) } type failSaveRepo struct { @@ -2228,9 +2228,9 @@ func (fs *StatFS) Lstat(name string) (os.FileInfo, error) { return fs.FS.Lstat(name) } -func (fs *StatFS) OpenFile(name string, flags int, perm os.FileMode) (fs.File, error) { +func (fs *StatFS) OpenFile(name string, flags int) (fs.File, error) { if fi, ok := fs.OverrideLstat[fixpath(name)]; ok { - f, err := fs.FS.OpenFile(name, flags, perm) + f, err := fs.FS.OpenFile(name, flags) if err != nil { return nil, err } @@ -2242,7 +2242,7 @@ func (fs *StatFS) OpenFile(name string, flags int, perm os.FileMode) (fs.File, e return wrappedFile, nil } - return fs.FS.OpenFile(name, flags, perm) + return fs.FS.OpenFile(name, flags) } type fileStat struct { diff --git a/internal/archiver/exclude.go b/internal/archiver/exclude.go index 1e855fc3a..54ced788a 100644 --- a/internal/archiver/exclude.go +++ b/internal/archiver/exclude.go @@ -153,7 +153,7 @@ func isDirExcludedByFile(dir, tagFilename, header string, fs fs.FS, warnf func(m // From this stage, errors mean tagFilename exists but it is malformed. // Warnings will be generated so that the user is informed that the // indented ignore-action is not performed. - f, err := fs.OpenFile(tf, os.O_RDONLY, 0) + f, err := fs.OpenFile(tf, os.O_RDONLY) if err != nil { warnf("could not open exclusion tagfile: %v", err) return false diff --git a/internal/archiver/file_saver_test.go b/internal/archiver/file_saver_test.go index 5b17eca37..069cdc171 100644 --- a/internal/archiver/file_saver_test.go +++ b/internal/archiver/file_saver_test.go @@ -72,7 +72,7 @@ func TestFileSaver(t *testing.T) { var results []futureNode for _, filename := range files { - f, err := testFs.OpenFile(filename, os.O_RDONLY, 0) + f, err := testFs.OpenFile(filename, os.O_RDONLY) if err != nil { t.Fatal(err) } diff --git a/internal/fs/file.go b/internal/fs/file.go index c60625a07..fa395b628 100644 --- a/internal/fs/file.go +++ b/internal/fs/file.go @@ -67,7 +67,7 @@ func ResetPermissions(path string) error { // Readdirnames returns a list of file in a directory. Flags are passed to fs.OpenFile. // O_RDONLY and O_DIRECTORY are implied. func Readdirnames(filesystem FS, dir string, flags int) ([]string, error) { - f, err := filesystem.OpenFile(dir, O_RDONLY|O_DIRECTORY|flags, 0) + f, err := filesystem.OpenFile(dir, O_RDONLY|O_DIRECTORY|flags) if err != nil { return nil, fmt.Errorf("openfile for readdirnames failed: %w", err) } diff --git a/internal/fs/fs_local.go b/internal/fs/fs_local.go index 5fac88dbb..045edf02f 100644 --- a/internal/fs/fs_local.go +++ b/internal/fs/fs_local.go @@ -25,8 +25,8 @@ func (fs Local) VolumeName(path string) string { // (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, // methods on the returned File can be used for I/O. // If there is an error, it will be of type *PathError. -func (fs Local) OpenFile(name string, flag int, perm os.FileMode) (File, error) { - f, err := os.OpenFile(fixpath(name), flag, perm) +func (fs Local) OpenFile(name string, flag int) (File, error) { + f, err := os.OpenFile(fixpath(name), flag, 0) if err != nil { return nil, err } diff --git a/internal/fs/fs_local_vss.go b/internal/fs/fs_local_vss.go index dcbda2a84..aa9f2b89d 100644 --- a/internal/fs/fs_local_vss.go +++ b/internal/fs/fs_local_vss.go @@ -127,8 +127,8 @@ func (fs *LocalVss) DeleteSnapshots() { } // OpenFile wraps the Open method of the underlying file system. -func (fs *LocalVss) OpenFile(name string, flag int, perm os.FileMode) (File, error) { - return fs.FS.OpenFile(fs.snapshotPath(name), flag, perm) +func (fs *LocalVss) OpenFile(name string, flag int) (File, error) { + return fs.FS.OpenFile(fs.snapshotPath(name), flag) } // Stat wraps the Stat method of the underlying file system. diff --git a/internal/fs/fs_local_vss_test.go b/internal/fs/fs_local_vss_test.go index f1a043118..7856767ba 100644 --- a/internal/fs/fs_local_vss_test.go +++ b/internal/fs/fs_local_vss_test.go @@ -331,7 +331,7 @@ func TestVSSFS(t *testing.T) { rtest.OK(t, err) rtest.Equals(t, origFi.Mode(), lstatFi.Mode()) - f, err := localVss.OpenFile(tempfile, os.O_RDONLY, 0) + f, err := localVss.OpenFile(tempfile, os.O_RDONLY) rtest.OK(t, err) data, err := io.ReadAll(f) rtest.OK(t, err) diff --git a/internal/fs/fs_reader.go b/internal/fs/fs_reader.go index 97d4e1660..ed8b9a347 100644 --- a/internal/fs/fs_reader.go +++ b/internal/fs/fs_reader.go @@ -54,7 +54,7 @@ func (fs *Reader) fi() os.FileInfo { // (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, // methods on the returned File can be used for I/O. // If there is an error, it will be of type *os.PathError. -func (fs *Reader) OpenFile(name string, flag int, _ os.FileMode) (f File, err error) { +func (fs *Reader) OpenFile(name string, flag int) (f File, err error) { if flag & ^(O_RDONLY|O_NOFOLLOW) != 0 { return nil, pathError("open", name, fmt.Errorf("invalid combination of flags 0x%x", flag)) diff --git a/internal/fs/fs_reader_test.go b/internal/fs/fs_reader_test.go index 442912fe3..e7020bc9d 100644 --- a/internal/fs/fs_reader_test.go +++ b/internal/fs/fs_reader_test.go @@ -16,7 +16,7 @@ import ( ) func verifyFileContentOpenFile(t testing.TB, fs FS, filename string, want []byte) { - f, err := fs.OpenFile(filename, O_RDONLY, 0) + f, err := fs.OpenFile(filename, O_RDONLY) if err != nil { t.Fatal(err) } @@ -37,7 +37,7 @@ func verifyFileContentOpenFile(t testing.TB, fs FS, filename string, want []byte } func verifyDirectoryContents(t testing.TB, fs FS, dir string, want []string) { - f, err := fs.OpenFile(dir, os.O_RDONLY, 0) + f, err := fs.OpenFile(dir, os.O_RDONLY) if err != nil { t.Fatal(err) } @@ -123,7 +123,7 @@ func TestFSReader(t *testing.T) { { name: "file/Stat", f: func(t *testing.T, fs FS) { - f, err := fs.OpenFile(filename, os.O_RDONLY, 0) + f, err := fs.OpenFile(filename, os.O_RDONLY) if err != nil { t.Fatal(err) } @@ -295,7 +295,7 @@ func TestFSReaderMinFileSize(t *testing.T) { AllowEmptyFile: test.allowEmpty, } - f, err := fs.OpenFile("testfile", os.O_RDONLY, 0) + f, err := fs.OpenFile("testfile", os.O_RDONLY) if err != nil { t.Fatal(err) } diff --git a/internal/fs/fs_track.go b/internal/fs/fs_track.go index 366bbee76..9912ac45b 100644 --- a/internal/fs/fs_track.go +++ b/internal/fs/fs_track.go @@ -16,8 +16,8 @@ type Track struct { } // OpenFile wraps the OpenFile method of the underlying file system. -func (fs Track) OpenFile(name string, flag int, perm os.FileMode) (File, error) { - f, err := fs.FS.OpenFile(fixpath(name), flag, perm) +func (fs Track) OpenFile(name string, flag int) (File, error) { + f, err := fs.FS.OpenFile(fixpath(name), flag) if err != nil { return nil, err } diff --git a/internal/fs/interface.go b/internal/fs/interface.go index 2967429c0..58744bd1d 100644 --- a/internal/fs/interface.go +++ b/internal/fs/interface.go @@ -9,7 +9,7 @@ import ( // FS bundles all methods needed for a file system. type FS interface { - OpenFile(name string, flag int, perm os.FileMode) (File, error) + OpenFile(name string, flag int) (File, error) Stat(name string) (os.FileInfo, error) Lstat(name string) (os.FileInfo, error) DeviceID(fi os.FileInfo) (deviceID uint64, err error)