mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Cleanup some zipfile code
This commit is contained in:
parent
1ebbf424c2
commit
b4251ab1be
@ -1147,7 +1147,7 @@ class ZipFile:
|
|||||||
if upperdirs and not os.path.exists(upperdirs):
|
if upperdirs and not os.path.exists(upperdirs):
|
||||||
try:
|
try:
|
||||||
os.makedirs(upperdirs)
|
os.makedirs(upperdirs)
|
||||||
except: # Added by Kovid
|
except OSError: # Added by Kovid
|
||||||
targetpath = os.path.join(base_target,
|
targetpath = os.path.join(base_target,
|
||||||
sanitize_file_name(fname))
|
sanitize_file_name(fname))
|
||||||
upperdirs = os.path.dirname(targetpath)
|
upperdirs = os.path.dirname(targetpath)
|
||||||
@ -1158,7 +1158,7 @@ class ZipFile:
|
|||||||
if not os.path.isdir(targetpath):
|
if not os.path.isdir(targetpath):
|
||||||
try:
|
try:
|
||||||
os.mkdir(targetpath)
|
os.mkdir(targetpath)
|
||||||
except Exception: # Added by Kovid
|
except OSError: # Added by Kovid
|
||||||
targetpath = os.path.join(base_target, sanitize_file_name(fname))
|
targetpath = os.path.join(base_target, sanitize_file_name(fname))
|
||||||
os.mkdir(targetpath)
|
os.mkdir(targetpath)
|
||||||
return targetpath
|
return targetpath
|
||||||
@ -1166,16 +1166,15 @@ class ZipFile:
|
|||||||
if not os.path.exists(targetpath):
|
if not os.path.exists(targetpath):
|
||||||
# Kovid: Could be a previously automatically created directory
|
# Kovid: Could be a previously automatically created directory
|
||||||
# in which case it is ignored
|
# in which case it is ignored
|
||||||
with closing(self.open(member, pwd=pwd)) as source:
|
|
||||||
try:
|
try:
|
||||||
with open(targetpath, 'wb') as target:
|
target = open(targetpath, 'wb')
|
||||||
shutil.copyfileobj(source, target)
|
except OSError:
|
||||||
except:
|
|
||||||
# Try sanitizing the file name to remove invalid characters
|
|
||||||
components = list(os.path.split(targetpath))
|
components = list(os.path.split(targetpath))
|
||||||
components[-1] = sanitize_file_name(components[-1])
|
components[-1] = sanitize_file_name(components[-1])
|
||||||
targetpath = os.sep.join(components)
|
targetpath = os.sep.join(components)
|
||||||
with open(targetpath, 'wb') as target:
|
target = open(targetpath, 'wb')
|
||||||
|
|
||||||
|
with target, closing(self.open(member, pwd=pwd)) as source:
|
||||||
shutil.copyfileobj(source, target)
|
shutil.copyfileobj(source, target)
|
||||||
# Kovid: Try to preserve the timestamps in the ZIP file
|
# Kovid: Try to preserve the timestamps in the ZIP file
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user