"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
lsf: add --absolute flag to add a leading / onto path names
Nick Craig-Wood3ef938ebdec2
diff --git a/cmd/lsf/lsf.go b/cmd/lsf/lsf.goindex d6dfe2458..3dffe5ce3 100644--- a/cmd/lsf/lsf.go+++ b/cmd/lsf/lsf.go@@ -24,6 +24,7 @@ var (filesOnly booldirsOnly boolcsv bool+ absolute bool)func init() {@@ -36,6 +37,7 @@ func init() {flags.BoolVarP(&filesOnly, "files-only", "", false, "Only list files.")flags.BoolVarP(&dirsOnly, "dirs-only", "", false, "Only list directories.")flags.BoolVarP(&csv, "csv", "", false, "Output in CSV format.")+ flags.BoolVarP(&absolute, "absolute", "", false, "Put a leading / in front of path names.")commandDefintion.Flags().BoolVarP(&recurse, "recursive", "R", false, "Recurse into the listing.")}@@ -125,6 +127,15 @@ Egtest.sh,449"this file contains a comma, in the file name.txt",6+Note that the --absolute parameter is useful for making lists of files+to pass to an rclone copy with the --files-from flag.++For example to find all the files modified within one day and copy+those only (without traversing the whole directory structure):++ rclone lsf --absolute --files-only --max-age 1d /path/to/local > new_files+ rclone copy --files-from new_files /path/to/local remote:path+` + lshelp.Help,Run: func(command *cobra.Command, args []string) {cmd.CheckArgs(1, 1, command, args)@@ -149,6 +160,7 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {list.SetSeparator(separator)list.SetCSV(csv)list.SetDirSlash(dirSlash)+ list.SetAbsolute(absolute)for _, char := range format {switch char {diff --git a/fs/operations/operations.go b/fs/operations/operations.goindex 9ca423b9c..5903b15f9 100644--- a/fs/operations/operations.go+++ b/fs/operations/operations.go@@ -1372,6 +1372,7 @@ func CopyFile(fdst fs.Fs, fsrc fs.Fs, dstFileName string, srcFileName string) (etype ListFormat struct {separator stringdirSlash bool+ absolute booloutput []func() stringentry fs.DirEntrycsv *csv.Writer@@ -1388,6 +1389,11 @@ func (l *ListFormat) SetDirSlash(dirSlash bool) {l.dirSlash = dirSlash}+// SetAbsolute prints a leading slash in front of path names+func (l *ListFormat) SetAbsolute(absolute bool) {+ l.absolute = absolute+}+// SetCSV defines if the output should be csv//// Note that you should call SetSeparator before this if you want a@@ -1423,12 +1429,15 @@ func (l *ListFormat) AddSize() {// AddPath adds path to file to outputfunc (l *ListFormat) AddPath() {l.AppendOutput(func() string {+ remote := l.entry.Remote()+ if l.absolute && !strings.HasPrefix(remote, "/") {+ remote = "/" + remote+ }_, isDir := l.entry.(fs.Directory)-if isDir && l.dirSlash {- return l.entry.Remote() + "/"+ remote += "/"}- return l.entry.Remote()+ return remote})}diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.goindex d295dfcd1..37e28436d 100644--- a/fs/operations/operations_test.go+++ b/fs/operations/operations_test.go@@ -726,6 +726,13 @@ func TestListFormat(t *testing.T) {assert.Contains(t, list.Format(items[0]), "/")assert.Equal(t, "inode/directory", list.Format(items[1]))+ list.SetOutput(nil)+ list.AddPath()+ list.SetAbsolute(true)+ assert.Equal(t, "/a", list.Format(items[0]))+ list.SetAbsolute(false)+ assert.Equal(t, "a", list.Format(items[0]))+list.SetOutput(nil)list.AddSize()assert.Equal(t, "1", list.Format(items[0]))