mirror of
https://github.com/rclone/rclone.git
synced 2025-04-24 13:14:13 +08:00
archive: create was not using filters, fixed
This commit is contained in:
parent
e94b9eba6e
commit
b29bac1cd0
@ -164,22 +164,22 @@ the contents of the archive will be:
|
||||
},
|
||||
Run: func(command *cobra.Command, args []string) {
|
||||
var src, dst fs.Fs
|
||||
var srcFile, dstFile string
|
||||
var dstFile string
|
||||
if len(args) == 1 { // source only, archive to stdout
|
||||
src, srcFile = cmd.NewFsFile(args[0])
|
||||
src = cmd.NewFsSrc(args)
|
||||
} else if len(args) == 2 {
|
||||
src, srcFile = cmd.NewFsFile(args[0])
|
||||
src = cmd.NewFsSrc(args)
|
||||
dst, dstFile = cmd.NewFsFile(args[1])
|
||||
} else {
|
||||
cmd.CheckArgs(1, 2, command, args)
|
||||
}
|
||||
cmd.Run(false, false, command, func() error {
|
||||
if prefix != "" {
|
||||
return create.ArchiveCreate(context.Background(), src, srcFile, dst, dstFile, format, prefix)
|
||||
return create.ArchiveCreate(context.Background(), src, dst, dstFile, format, prefix)
|
||||
} else if fullpath {
|
||||
return create.ArchiveCreate(context.Background(), src, srcFile, dst, dstFile, format, src.Root())
|
||||
return create.ArchiveCreate(context.Background(), src, dst, dstFile, format, src.Root())
|
||||
}
|
||||
return create.ArchiveCreate(context.Background(), src, srcFile, dst, dstFile, format, "")
|
||||
return create.ArchiveCreate(context.Background(), src, dst, dstFile, format, "")
|
||||
})
|
||||
},
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func TestArchiveFunctions(t *testing.T) {
|
||||
f2 := r.WriteFile("dir1/sub1.txt", "sub content 1", t1)
|
||||
f3 := r.WriteFile("dir2/sub2.txt", "sub content 2", t1)
|
||||
// create archive
|
||||
err = create.ArchiveCreate(ctx, r.Flocal, "", r.Flocal, "test.zip", "", "")
|
||||
err = create.ArchiveCreate(ctx, r.Flocal, r.Flocal, "test.zip", "", "")
|
||||
require.NoError(t, err)
|
||||
// list archive
|
||||
err = list.ArchiveList(ctx, r.Flocal, "test.zip", false)
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/rclone/rclone/cmd/archive/files"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/accounting"
|
||||
"github.com/rclone/rclone/fs/filter"
|
||||
"github.com/rclone/rclone/fs/operations"
|
||||
"github.com/rclone/rclone/fs/walk"
|
||||
)
|
||||
@ -206,8 +207,16 @@ func onProgress(snapshot accounting.TransferSnapshot, action int) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadMetadata(ctx context.Context, o fs.DirEntry) fs.Metadata {
|
||||
meta, err := fs.GetMetadata(ctx, o)
|
||||
if err != nil {
|
||||
meta = make(fs.Metadata, 0)
|
||||
}
|
||||
return meta
|
||||
}
|
||||
|
||||
// ArchiveCreate - compresses/archive source to destination
|
||||
func ArchiveCreate(ctx context.Context, src fs.Fs, srcFile string, dst fs.Fs, dstFile string, format string, prefix string) error {
|
||||
func ArchiveCreate(ctx context.Context, src fs.Fs, dst fs.Fs, dstFile string, format string, prefix string) error {
|
||||
var err error
|
||||
var list archivesFileInfoList
|
||||
var compArchive archives.CompressedArchive
|
||||
@ -218,6 +227,8 @@ func ArchiveCreate(ctx context.Context, src fs.Fs, srcFile string, dst fs.Fs, ds
|
||||
return err
|
||||
}
|
||||
}
|
||||
//
|
||||
fi := filter.GetConfig(ctx)
|
||||
// get archive format
|
||||
compArchive, err = getCompressor(format, dstFile)
|
||||
if err != nil {
|
||||
@ -227,13 +238,17 @@ func ArchiveCreate(ctx context.Context, src fs.Fs, srcFile string, dst fs.Fs, ds
|
||||
err = walk.Walk(ctx, src, "", false, -1, func(path string, entries fs.DirEntries, err error) error {
|
||||
// get directories
|
||||
entries.ForDir(func(o fs.Directory) {
|
||||
fi := files.NewArchiveFileInfo(ctx, o, prefix, onProgress)
|
||||
list = append(list, fi)
|
||||
if fi.Include(o.Remote(), o.Size(), o.ModTime(ctx), loadMetadata(ctx, o)) {
|
||||
info := files.NewArchiveFileInfo(ctx, o, prefix, onProgress)
|
||||
list = append(list, info)
|
||||
}
|
||||
})
|
||||
// get files
|
||||
entries.ForObject(func(o fs.Object) {
|
||||
fi := files.NewArchiveFileInfo(ctx, o, prefix, onProgress)
|
||||
list = append(list, fi)
|
||||
if fi.Include(o.Remote(), o.Size(), o.ModTime(ctx), loadMetadata(ctx, o)) {
|
||||
info := files.NewArchiveFileInfo(ctx, o, prefix, onProgress)
|
||||
list = append(list, info)
|
||||
}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user