Skip to content

Commit

Permalink
Only use last-mod header for files.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
jake authored and jake committed Mar 26, 2024
1 parent 982e148 commit 89c70bd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internetarchive/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import os
import socket
import sys
import time
from contextlib import nullcontext, suppress
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
Expand Down Expand Up @@ -302,17 +301,20 @@ def download(self, file_path=None, verbose=None, ignore_existing=None,
raise exc

# Get timestamp from Last-Modified header
try:
dt = parsedate_to_datetime(response.headers['Last-Modified'])
last_modified = time.mktime(time.gmtime(dt.timestamp()))
except KeyError:
last_modified = 0
if self.name == f"{self.identifier}_files.xml":
try:
dt = parsedate_to_datetime(response.headers['Last-Modified'])
mtime = dt.timestamp()
except KeyError:
mtime = 0
else:
mtime = self.mtime

# Set mtime with mtime from files.xml.
if not no_change_timestamp:
# If we want to set the timestamp to that of the original archive...
with suppress(OSError): # Probably file-like object, e.g. sys.stdout.
os.utime(file_path.encode('utf-8'), (0, last_modified))
os.utime(file_path.encode('utf-8'), (0, mtime))

msg = f'downloaded {self.identifier}/{self.name} to {file_path}'
log.info(msg)
Expand Down

0 comments on commit 89c70bd

Please sign in to comment.