mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Don't send a copy to the recycle bin when changing metadata on windows
This commit is contained in:
parent
55a4f4a208
commit
2ca1777869
@ -40,11 +40,15 @@ def delete_file(path):
|
|||||||
except:
|
except:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
def delete_tree(path):
|
def delete_tree(path, permanent=False):
|
||||||
try:
|
if permanent:
|
||||||
winshell.delete_file(path, silent=True, no_confirm=True)
|
|
||||||
except:
|
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
if not permanent:
|
||||||
|
winshell.delete_file(path, silent=True, no_confirm=True)
|
||||||
|
except:
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
||||||
|
|
||||||
@ -661,9 +665,9 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
name = name[:-1]
|
name = name[:-1]
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def rmtree(self, path):
|
def rmtree(self, path, permanent=False):
|
||||||
if not self.normpath(self.library_path).startswith(self.normpath(path)):
|
if not self.normpath(self.library_path).startswith(self.normpath(path)):
|
||||||
delete_tree(path)
|
delete_tree(path, permanent=permanent)
|
||||||
|
|
||||||
def normpath(self, path):
|
def normpath(self, path):
|
||||||
path = os.path.abspath(os.path.realpath(path))
|
path = os.path.abspath(os.path.realpath(path))
|
||||||
@ -715,10 +719,10 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
# Delete not needed directories
|
# Delete not needed directories
|
||||||
if current_path and os.path.exists(spath):
|
if current_path and os.path.exists(spath):
|
||||||
if self.normpath(spath) != self.normpath(tpath):
|
if self.normpath(spath) != self.normpath(tpath):
|
||||||
self.rmtree(spath)
|
self.rmtree(spath, permanent=True)
|
||||||
parent = os.path.dirname(spath)
|
parent = os.path.dirname(spath)
|
||||||
if len(os.listdir(parent)) == 0:
|
if len(os.listdir(parent)) == 0:
|
||||||
self.rmtree(parent)
|
self.rmtree(parent, permanent=True)
|
||||||
|
|
||||||
def add_listener(self, listener):
|
def add_listener(self, listener):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user