-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
Initial change Still to do |
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. |
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. |
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. |
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.
If it works, it works!! Here are a few suggestions, especially about the comments.
beets/importer.py
Outdated
# fixing #4392 | ||
|
||
for f in archive.infolist(): | ||
# path to this extracted f-item |
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 comment doesn't seem important.
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.
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)) |
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.
Maybe we should just put the relevant assignment closer to here?
os.utime(fullpath, (date_time, date_time)) | |
fullpath = os.path.join(extract_to, f.filename) | |
os.utime(fullpath, (date_time, date_time)) |
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 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)) |
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 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?
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 added the question and answer from the stackoverflow link
beets/importer.py
Outdated
# From here: | ||
# https://stackoverflow.com/questions/9813243/extract-files-from-zip-file-and-retain-mod-date | ||
# fixing #4392 | ||
|
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.
# 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 |
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.
Changed as requested
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. |
Very nice work; thanks for your effort on this!! |
Description
Fixes #X.
(...)
To Do
docs/
to describe it.)docs/changelog.rst
near the top of the document.)