Rearrange the lines in delete_file.

If anything is going to raise an exception here I expect it to be
the item missing from the manifest. In which case let's get that out
of the way early and only delete from disk at the very end.
This commit is contained in:
Ethan Dalool 2020-01-20 17:33:58 -08:00
parent fd73ecfe2e
commit 6386f25cd4

View file

@ -479,12 +479,12 @@ class Epub:
) )
def delete_file(self, id): def delete_file(self, id):
os.remove(self.get_filepath(id).absolute_path) manifest_item = self.opf.manifest.find('item', {'id': id})
manifest_item.extract()
spine_item = self.opf.spine.find('itemref', {'idref': id}) spine_item = self.opf.spine.find('itemref', {'idref': id})
if spine_item: if spine_item:
spine_item.extract() spine_item.extract()
manifest_item = self.opf.manifest.find('item', {'id': id}) os.remove(self.get_filepath(id).absolute_path)
manifest_item.extract()
def get_filepath(self, id): def get_filepath(self, id):
href = self.opf.manifest.find('item', {'id': id})['href'] href = self.opf.manifest.find('item', {'id': id})['href']