"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 support for unix and unixnano time formats
Motte89a8ea7a91b8
diff --git a/cmd/lsf/lsf.go b/cmd/lsf/lsf.goindex 3c704d27e..38e79d62a 100644--- a/cmd/lsf/lsf.go+++ b/cmd/lsf/lsf.go@@ -33,7 +33,7 @@ func init() {cmd.Root.AddCommand(commandDefinition)cmdFlags := commandDefinition.Flags()flags.StringVarP(cmdFlags, &format, "format", "F", "p", "Output format - see help for details", "")- flags.StringVarP(cmdFlags, &timeFormat, "time-format", "t", "", "Specify a custom time format, or 'max' for max precision supported by remote (default: 2006-01-02 15:04:05)", "")+ flags.StringVarP(cmdFlags, &timeFormat, "time-format", "t", "", "Specify a custom time format - see docs for details (default: 2006-01-02 15:04:05)", "")flags.StringVarP(cmdFlags, &separator, "separator", "s", ";", "Separator for the items in the format", "")flags.BoolVarP(cmdFlags, &dirSlash, "dir-slash", "d", true, "Append a slash to directory names", "")flags.FVarP(cmdFlags, &hashType, "hash", "", "Use this hash when `h` is used in the format MD5|SHA-1|DropboxHash", "")@@ -169,6 +169,8 @@ rclone lsf remote:path --format pt --time-format '2006-01-02T15:04:05.999999999Zrclone lsf remote:path --format pt --time-format RFC3339rclone lsf remote:path --format pt --time-format DateOnlyrclone lsf remote:path --format pt --time-format max+rclone lsf remote:path --format pt --time-format unix+rclone lsf remote:path --format pt --time-format unixnano` + "```" + `` + "`--time-format max`" + ` will automatically truncate ` + "`2006-01-02 15:04:05.000000000`" + `diff --git a/fs/operations/operations.go b/fs/operations/operations.goindex e07b79be3..a10ad41b2 100644--- a/fs/operations/operations.go+++ b/fs/operations/operations.go@@ -2219,14 +2219,25 @@ func (l *ListFormat) SetOutput(output []func(entry *ListJSONItem) string) {// AddModTime adds file's Mod Time to outputfunc (l *ListFormat) AddModTime(timeFormat string) {- if timeFormat == "" {- timeFormat = "2006-01-02 15:04:05"- } else {+ switch timeFormat {+ case "":+ l.AppendOutput(func(entry *ListJSONItem) string {+ return entry.ModTime.When.Local().Format("2006-01-02 15:04:05")+ })+ case "unix":+ l.AppendOutput(func(entry *ListJSONItem) string {+ return fmt.Sprint(entry.ModTime.When.Unix())+ })+ case "unixnano":+ l.AppendOutput(func(entry *ListJSONItem) string {+ return fmt.Sprint(entry.ModTime.When.UnixNano())+ })+ default:timeFormat = transform.TimeFormat(timeFormat)+ l.AppendOutput(func(entry *ListJSONItem) string {+ return entry.ModTime.When.Local().Format(timeFormat)+ })}- l.AppendOutput(func(entry *ListJSONItem) string {- return entry.ModTime.When.Local().Format(timeFormat)- })}// AddSize adds file's size to outputdiff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.goindex 8e6331156..cb68b05ca 100644--- a/fs/operations/operations_test.go+++ b/fs/operations/operations_test.go@@ -1278,6 +1278,14 @@ func TestListFormat(t *testing.T) {list.AddModTime("")assert.Equal(t, t1.Local().Format("2006-01-02 15:04:05"), list.Format(item0))+ list.SetOutput(nil)+ list.AddModTime("unix")+ assert.Equal(t, fmt.Sprint(t1.Local().Unix()), list.Format(item0))++ list.SetOutput(nil)+ list.AddModTime("unixnano")+ assert.Equal(t, fmt.Sprint(t1.Local().UnixNano()), list.Format(item0))+list.SetOutput(nil)list.SetSeparator("|")list.AddID()diff --git a/fs/operations/operationsflags/operationsflags.go b/fs/operations/operationsflags/operationsflags.goindex 8b54fd442..054ed96bc 100644--- a/fs/operations/operationsflags/operationsflags.go+++ b/fs/operations/operationsflags/operationsflags.go@@ -62,7 +62,7 @@ func AddLoggerFlags(cmdFlags *pflag.FlagSet, opt *operations.LoggerOpt, flagsOpt// lsf flags for destAfterflags.StringVarP(cmdFlags, &opt.Format, "format", "F", "p", "Output format - see lsf help for details", "Sync")- flags.StringVarP(cmdFlags, &opt.TimeFormat, "timeformat", "t", "", "Specify a custom time format, or 'max' for max precision supported by remote (default: 2006-01-02 15:04:05)", "")+ flags.StringVarP(cmdFlags, &opt.TimeFormat, "timeformat", "t", "", "Specify a custom time format - see docs for details (default: 2006-01-02 15:04:05)", "")flags.StringVarP(cmdFlags, &opt.Separator, "separator", "s", ";", "Separator for the items in the format", "Sync")flags.BoolVarP(cmdFlags, &opt.DirSlash, "dir-slash", "d", true, "Append a slash to directory names", "Sync")opt.HashType = hash.MD5