Skip to content
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

Archiver modifies the last modified date of the folder to archive #7

Open
oO0XX0Oo opened this issue Dec 21, 2019 · 3 comments
Open

Comments

@oO0XX0Oo
Copy link

Hi,

I'm on MS Windows and when I use your "Archiver example" from the readme.me, the last modified date of the folder to archive is changed to now().

Instead of ~/fastzip-archiving
I'm using R:/tst_zip/zip me" which contains about 2000 files and 300 folders

Is there a way to avoid this behavior? I know that the last modified date is not know on linux but it is on Windows and it shouldn't be reset only because the folder gets zipped...

@saracen
Copy link
Owner

saracen commented Dec 21, 2019

Hey @oO0XX0Oo

Unfortunately I'm not going to have a chance to look at this in detail probably for a week or so.

However, I think I know what the issue is: For concurrent archiving, where multiple files are compressed at the same time, a staging directory is used. This staging directory is by default the directory to be archived.

You can change the staging directory's location by passing the option: WithStageDirectory. Alternatively, using the option WithArchiverConcurrency(1) will stop concurrent archiving, and therefore also not create any files in the staging directory - but will impact performance.

For changing the staging directory, you could do something like this:

tmp, err := ioutil.TempDir("", "fastzip")
if err != nil {
   return err
}
defer os.RemoveAll(tmp) // delete tmp directory after archiving complete

a, err := fastzip.NewArchiver(w, "~/fastzip-archiving", fastzip.WithStageDirectory(tmp))
...

This will then use the operating system's default directory for temporary files. This isn't the default to avoid cross-filesystem problems. However, when this decision was made, I didn't foresee this directory modification date issue. I'll think on this further. At the very least, the documentation should make it clear that by default, the directory to be archived is used to stage files in (and then they're cleaned up).

@oO0XX0Oo
Copy link
Author

oO0XX0Oo commented Dec 22, 2019

Hi @saracen

Thanks for the quick answer! WithStageDirectory is a perfectly fine option (at least for me). As long as the last modified date isn't reset, everything is fine (I don't want to harm concurrency because I like Archiver for its incredible speed. E.g. Archiver vs 7-Zip: Archiver it's a lot faster for the test folder with 2000 files and 300 folders).

Additionally, thanks a lot for the example how to set up the temp folder and providing the necessary option to Archiver!

Take your time if you really want to look deeper into this 'issue', it isn't urgent (any more) :)

Merry Christmas!

@oO0XX0Oo
Copy link
Author

oO0XX0Oo commented Dec 23, 2019

Unfortunately, a somehow related issue...

This is only valid for the Windows operating systems!

When Archiver stores the file dates from the files/folders inside the source path it sets the last modified time (sometimes it's called "birth time") to time.Now() instead of using the existing time.

The same goes for Extractor. When it extracts an archive, the last modified date is set to time.Now() as well...

Can you consider importing the times library: https://github.com/djherbis/times
and store/restore the correct last modified time instead?

Thanks a lot,
oO0XX0Oo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants