cavaliergopher / grab

A download manager package for Go
BSD 3-Clause "New" or "Revised" License
1.38k stars 151 forks source link

Call chtimes to set last modified #14

Closed james-antill closed 6 years ago

james-antill commented 7 years ago

This does most of the sane things by default, except set the last modified time to be the file's modified time (aka. --remote-time in curl).

cavaliercoder commented 7 years ago

I've added the ability to set the timestamp according to the Last-Modified header in the remote response. Just set Request.RemoteTime = true.

I haven't however made this the default behavior. I wasn't able to find any scenarios in curl where this is the default behavior unless --remote-time|-R is explicitly given.

james-antill commented 7 years ago

It isn't the default in curl, but then curl cli also requires you to specify --progress-bar, --compressed, --location, and --remote-name.

As a personal thing I almost always want to know "when was this created" and not "which random time did I download it to my computer", although if you still need download time you can usually look at the ctime. But, obviously, it's upto you.

cavaliercoder commented 7 years ago

This is a real pickle! It's not the default in curl or cp, but is the default in wget... I think having it by default might be convenient when checking for remote updates. I'll enable this by default and see how the community reacts.

cavaliercoder commented 7 years ago

Though it raises a question around error handling when Last-Modified is not available from the remote server. Should this be silently ignored? Or should it return early with an error by default? This might break many default cases.

james-antill commented 7 years ago

It is the default in urlgrabber too. Both wget and urlgrabber don't fail if there is no remote last-modified, although wget does print a warning (if it's not in quiet mode).

cavaliercoder commented 6 years ago

Timestamp is now set by default, unless Request.IngoreRemoteTime is true. Great idea, thank you.