archiver: minimize imports
This commit is contained in:
parent
6fd5d5f2d5
commit
70fbad6623
4 changed files with 11 additions and 15 deletions
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/restic/restic/internal/repository"
|
"github.com/restic/restic/internal/repository"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
"github.com/restic/restic/internal/textfile"
|
"github.com/restic/restic/internal/textfile"
|
||||||
|
"github.com/restic/restic/internal/ui"
|
||||||
"github.com/restic/restic/internal/ui/backup"
|
"github.com/restic/restic/internal/ui/backup"
|
||||||
"github.com/restic/restic/internal/ui/termstatus"
|
"github.com/restic/restic/internal/ui/termstatus"
|
||||||
)
|
)
|
||||||
|
@ -333,7 +334,12 @@ func collectRejectFuncs(opts BackupOptions, targets []string, fs fs.FS) (funcs [
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.ExcludeLargerThan) != 0 && !opts.Stdin && !opts.StdinCommand {
|
if len(opts.ExcludeLargerThan) != 0 && !opts.Stdin && !opts.StdinCommand {
|
||||||
f, err := archiver.RejectBySize(opts.ExcludeLargerThan)
|
maxSize, err := ui.ParseBytes(opts.ExcludeLargerThan)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := archiver.RejectBySize(maxSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
"github.com/restic/restic/internal/ui"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RejectByNameFunc is a function that takes a filename of a
|
// RejectByNameFunc is a function that takes a filename of a
|
||||||
|
@ -139,7 +138,7 @@ func isExcludedByFile(filename, tagFilename, header string, rc *rejectionCache,
|
||||||
func isDirExcludedByFile(dir, tagFilename, header string, fs fs.FS, warnf func(msg string, args ...interface{})) bool {
|
func isDirExcludedByFile(dir, tagFilename, header string, fs fs.FS, warnf func(msg string, args ...interface{})) bool {
|
||||||
tf := fs.Join(dir, tagFilename)
|
tf := fs.Join(dir, tagFilename)
|
||||||
_, err := fs.Lstat(tf)
|
_, err := fs.Lstat(tf)
|
||||||
if os.IsNotExist(err) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -315,12 +314,7 @@ func RejectByDevice(samples []string, filesystem fs.FS) (RejectFunc, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RejectBySize(maxSizeStr string) (RejectFunc, error) {
|
func RejectBySize(maxSize int64) (RejectFunc, error) {
|
||||||
maxSize, err := ui.ParseBytes(maxSizeStr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return func(item string, fi os.FileInfo, _ fs.FS) bool {
|
return func(item string, fi os.FileInfo, _ fs.FS) bool {
|
||||||
// directory will be ignored
|
// directory will be ignored
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
|
|
|
@ -139,9 +139,6 @@ func TestMultipleIsExcludedByFile(t *testing.T) {
|
||||||
func TestIsExcludedByFileSize(t *testing.T) {
|
func TestIsExcludedByFileSize(t *testing.T) {
|
||||||
tempDir := test.TempDir(t)
|
tempDir := test.TempDir(t)
|
||||||
|
|
||||||
// Max size of file is set to be 1k
|
|
||||||
maxSizeStr := "1k"
|
|
||||||
|
|
||||||
// Create some files in a temporary directory.
|
// Create some files in a temporary directory.
|
||||||
// Files in UPPERCASE will be used as exclusion triggers later on.
|
// Files in UPPERCASE will be used as exclusion triggers later on.
|
||||||
// We will test the inclusion later, so we add the expected value as
|
// We will test the inclusion later, so we add the expected value as
|
||||||
|
@ -185,7 +182,7 @@ func TestIsExcludedByFileSize(t *testing.T) {
|
||||||
test.OKs(t, errs) // see if anything went wrong during the creation
|
test.OKs(t, errs) // see if anything went wrong during the creation
|
||||||
|
|
||||||
// create rejection function
|
// create rejection function
|
||||||
sizeExclude, _ := RejectBySize(maxSizeStr)
|
sizeExclude, _ := RejectBySize(1024)
|
||||||
|
|
||||||
// To mock the archiver scanning walk, we create filepath.WalkFn
|
// To mock the archiver scanning walk, we create filepath.WalkFn
|
||||||
// that tests against the two rejection functions and stores
|
// that tests against the two rejection functions and stores
|
||||||
|
|
|
@ -3,7 +3,6 @@ package archiver
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
|
@ -131,7 +130,7 @@ func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (Sca
|
||||||
sort.Strings(names)
|
sort.Strings(names)
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
stats, err = s.scan(ctx, stats, filepath.Join(target, name))
|
stats, err = s.scan(ctx, stats, s.FS.Join(target, name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stats, err
|
return stats, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue