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

Preserve mtimes from archives #4392 #4396

Merged
merged 5 commits into from
Apr 1, 2023
Merged

Conversation

arogl
Copy link
Contributor

@arogl arogl commented Jul 2, 2022

Description

Fixes #X.

(...)

To Do

  • Documentation. (If you've add a new command-line flag, for example, find the appropriate page under docs/ to describe it.)
  • Changelog. (Add an entry to docs/changelog.rst near the top of the document.)
  • Tests. (Encouraged but not strictly required.)

@arogl
Copy link
Contributor Author

arogl commented Jul 2, 2022

Initial change

Still to do
[ ] test which archive types do not keep mtimes
[ ] how to check whether preserve_mtimes is set

@stale
Copy link

stale bot commented Nov 1, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 1, 2022
@arogl
Copy link
Contributor Author

arogl commented Nov 1, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Still relevant.

@stale stale bot removed the stale label Nov 1, 2022
@stale
Copy link

stale bot commented Mar 18, 2023

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 18, 2023
@arogl
Copy link
Contributor Author

arogl commented Mar 18, 2023

This should be an easy pull, as it mimics normal unzip behaviour of extracting files with times from the zip file.

Python unzip does not modify the files date when extracting, so it gets the current time.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it works, it works!! Here are a few suggestions, especially about the comments.

# fixing #4392

for f in archive.infolist():
# path to this extracted f-item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't seem important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment removed

# still need to adjust the dt o/w item will have the current dt
date_time = time.mktime(f.date_time + (0, 0, -1))
# update date_time
os.utime(fullpath, (date_time, date_time))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just put the relevant assignment closer to here?

Suggested change
os.utime(fullpath, (date_time, date_time))
fullpath = os.path.join(extract_to, f.filename)
os.utime(fullpath, (date_time, date_time))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code

# path to this extracted f-item
fullpath = os.path.join(extract_to, f.filename)
# still need to adjust the dt o/w item will have the current dt
date_time = time.mktime(f.date_time + (0, 0, -1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't yet understand the need for + (0, 0, -1) here… in fact, I'm not entirely sure what type f.date_time is. Maybe this needs a closer look?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the question and answer from the stackoverflow link

Comment on lines 1094 to 1097
# From here:
# https://stackoverflow.com/questions/9813243/extract-files-from-zip-file-and-retain-mod-date
# fixing #4392

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# From here:
# https://stackoverflow.com/questions/9813243/extract-files-from-zip-file-and-retain-mod-date
# fixing #4392
# Adjust the files' mtimes to match the information from the archive. Inspired by:
# https://stackoverflow.com/q/9813243

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as requested

@stale stale bot removed the stale label Mar 25, 2023
@sampsyo
Copy link
Member

sampsyo commented Mar 25, 2023

Looking good! I think all this needs is to polish the comments so they're self-contained and oriented toward the code-reader of the future rather than summarizing our discussion here, and it will be good to go.

@sampsyo
Copy link
Member

sampsyo commented Apr 1, 2023

Very nice work; thanks for your effort on this!!

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

Successfully merging this pull request may close these issues.

2 participants