From 5416276b00037daa2c9075ad213596cc1e671079 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 6 Sep 2019 16:54:40 -0700 Subject: [PATCH] Fix relink behavior when subfolder exists with wrong casing. --- epubfile.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/epubfile.py b/epubfile.py index 764ce8d..06d8f10 100644 --- a/epubfile.py +++ b/epubfile.py @@ -1085,10 +1085,15 @@ class Epub: directory = get_directory_for_mimetype(manifest_item['media-type']) directory = self.opf_filepath.parent.with_child(directory) - os.makedirs(directory.absolute_path, exist_ok=True) + if directory.exists: + # On Windows, this will fix any incorrect casing. + # On Linux it is inert. + os.rename(directory.absolute_path, directory.absolute_path) + else: + os.makedirs(directory.absolute_path) new_filepath = directory.with_child(old_filepath.basename) - if new_filepath != old_filepath: + if new_filepath.absolute_path != old_filepath.absolute_path: rename_map[old_filepath] = new_filepath os.rename(old_filepath.absolute_path, new_filepath.absolute_path) manifest_item['href'] = new_filepath.relative_to(self.opf_filepath.parent, simple=True)