mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
7d5a38355a
commit
25f99cc540
@ -3,7 +3,7 @@ Make strings safe for use as ASCII filenames, while trying to preserve as much
|
|||||||
meaning as possible.
|
meaning as possible.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, errno
|
import os
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
from calibre import sanitize_file_name, isbytestring, force_unicode
|
from calibre import sanitize_file_name, isbytestring, force_unicode
|
||||||
@ -152,25 +152,21 @@ def case_preserving_open_file(path, mode='wb', mkdir_mode=0777):
|
|||||||
# the first os.listdir works correctly
|
# the first os.listdir works correctly
|
||||||
cpath = components[0].upper() + sep
|
cpath = components[0].upper() + sep
|
||||||
|
|
||||||
# Create all the directories in path, putting the on disk case version of
|
bdir = path if mode is None else os.path.dirname(path)
|
||||||
|
if not os.path.exists(bdir):
|
||||||
|
os.makedirs(bdir, mkdir_mode)
|
||||||
|
|
||||||
|
# Walk all the directories in path, putting the on disk case version of
|
||||||
# the directory into cpath
|
# the directory into cpath
|
||||||
dirs = components[1:] if mode is None else components[1:-1]
|
dirs = components[1:] if mode is None else components[1:-1]
|
||||||
for comp in dirs:
|
for comp in dirs:
|
||||||
cdir = os.path.join(cpath, comp)
|
cdir = os.path.join(cpath, comp)
|
||||||
try:
|
|
||||||
os.mkdir(cdir, mkdir_mode)
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno != errno.EEXIST:
|
|
||||||
if not os.path.exists(cdir):
|
|
||||||
# Check for exists again, as we could have got a permission
|
|
||||||
# denied error
|
|
||||||
raise
|
|
||||||
# This component already exists, ensure the case is correct
|
|
||||||
cl = comp.lower()
|
cl = comp.lower()
|
||||||
try:
|
try:
|
||||||
candidates = [c for c in os.listdir(cpath) if c.lower() == cl]
|
candidates = [c for c in os.listdir(cpath) if c.lower() == cl]
|
||||||
except:
|
except:
|
||||||
# No permission to do a listdir, just use the original case
|
# Dont have permission to do the listdir, assume the case is
|
||||||
|
# correct
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if len(candidates) == 1:
|
if len(candidates) == 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user