-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fs/operations: add support for unix and unixnano time formats #8726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. First of all you should revert changes in autogenerated files. These would have been flagged by our linter, if we had allowed the workflows to run.
@albertony thank you so much for the review! And sorry for the oversight. I reverted the changes to the autogenerated files in 4a67257. I hope it's OK now. Let me know :) |
Great, lets run the workflows and see. 👍 |
Hey @albertony JFYI it seems like all the workflows passed 🙂 |
Great. Looks good as far as I can tell, good job! However; I'll leave the final review up to Nick. |
There are several ways to fix that, but the first one which comes to mind is this
Yes it does look useful, thank you. I'll review the code now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good :-)
See comments inline
cmd/lsf/lsf_test.go
Outdated
@@ -264,6 +265,84 @@ subdir/file3_+_111_+_`+expectedOutput[6]+` | |||
dirSlash = false | |||
} | |||
|
|||
func TestTimeFormatUnix(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these tests would be more sensibly in fs/operations/operations_test.go
Search for AddModTime in there - we don't test with any time formats so it would be a good idea to add some.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, done in 1647bf7. I hope I got everything right :) let me know
@@ -62,7 +62,7 @@ func AddLoggerFlags(cmdFlags *pflag.FlagSet, opt *operations.LoggerOpt, flagsOpt | |||
|
|||
// lsf flags for destAfter | |||
flags.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, 'unix' / 'unixnano' for timestamp, or 'max' for max precision supported by remote (default: 2006-01-02 15:04:05)", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
@nielash was there a reason this flag is called --timeformat
but the lsf flag is called --time-format
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't specifically remember now, but probably an accidental oversight. I think the logger flags came first and adding the same idea to lsf
was something we did later.
cmd/lsf/lsf.go
Outdated
@@ -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, 'unix' / 'unixnano' for timestamp, or 'max' for max precision supported by remote (default: 2006-01-02 15:04:05)", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the command line help, so try to keep it short. It leaves out an awful lot so maybe just this?
"Specify a custom time format - see docs for details"
Note the docs here also need updating.
Lines 149 to 154 in fc5bd21
rclone lsf remote:path --format pt --time-format 'Jan 2, 2006 at 3:04pm (MST)' | |
rclone lsf remote:path --format pt --time-format '2006-01-02 15:04:05.000000000' | |
rclone lsf remote:path --format pt --time-format '2006-01-02T15:04:05.999999999Z07:00' | |
rclone lsf remote:path --format pt --time-format RFC3339 | |
rclone lsf remote:path --format pt --time-format DateOnly | |
rclone lsf remote:path --format pt --time-format max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ncw already tried that, but for some reason it didn't work. But thanks for pointing it out anyway 🙂 nevermind, unix timestamps will be more than enough for me. Now I'm gonna address all your comments |
Yep @nielash I can confirm. I was trying it from a Windows PC and @ncw I addressed all your comments 👍 I hope I did things correctly now. Sorry but it's my first contribution to this project and I don't have much experience with the codebase yet :) |
Hey guys @albertony @ncw @nielash any news on this? I just resolved some conflicts with |
Mmmh, I can see a CI failure here: https://github.com/rclone/rclone/actions/runs/17295515406/job/49094283747?pr=8726 But the failure is only in the Update: yep, I can see the same failure in a completely different commit from |
Yes, it is a bit flaky. I'll rerun it and hopefully it gets all green.. |
Thank you @albertony, now it's green :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great now - thank you :-)
I'll merge it now.
What is the purpose of this change?
First of all, thank you so much for this amazing project! 🙂 I found Rclone extremely useful and very well done.
In this very simple PR I'm adding support for two new time formats:
unix
andunixnano
. The reason behind this is that sometimes I use therclone lsf
command like this:to generate a sort of CSV-based "tree" of a directory (either local or remote) with file sizes and last modification times. But the output of such command is timezone-dependent (note the
+02:00
s). So, if I run the same command on one of my servers, which has a copy of the same folder but the system time zone set to UTC, I get this:So, even if the content of the directory is exactly the same, I'm unable to programmatically compare the two outputs, e.g. using the
diff
command.Since Unix timestamps are timezone-agnostic, with this PR I'm introducing the possibility to do this:
And:
I hope this is useful :) let me know what you think. Thanks in advance!
Was the change discussed in an issue or in the forum before?
I don't think so. I tried to search but couldn't find anything related :)
Checklist