mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Windows: Fix empty data folder getting created in directory calibre is launched from when changing title/author for a book with an existing data folder
This commit is contained in:
parent
99ef684419
commit
efe1e31731
@ -213,6 +213,7 @@ def identity_transform(src_path: str, dest_path: str) -> str:
|
|||||||
def register_folder_recursively(
|
def register_folder_recursively(
|
||||||
src: str, copier: Union[UnixFileCopier, WindowsFileCopier], dest_dir: str,
|
src: str, copier: Union[UnixFileCopier, WindowsFileCopier], dest_dir: str,
|
||||||
transform_destination_filename: Callable[[str, str], str] = identity_transform,
|
transform_destination_filename: Callable[[str, str], str] = identity_transform,
|
||||||
|
read_only: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
def dest_from_entry(dirpath: str, x: str) -> str:
|
def dest_from_entry(dirpath: str, x: str) -> str:
|
||||||
@ -228,14 +229,15 @@ def register_folder_recursively(
|
|||||||
for d in dirnames:
|
for d in dirnames:
|
||||||
path = os.path.join(dirpath, d)
|
path = os.path.join(dirpath, d)
|
||||||
dest = dest_from_entry(dirpath, d)
|
dest = dest_from_entry(dirpath, d)
|
||||||
os.makedirs(make_long_path_useable(dest), exist_ok=True)
|
if not read_only:
|
||||||
shutil.copystat(make_long_path_useable(path), make_long_path_useable(dest), follow_symlinks=False)
|
os.makedirs(make_long_path_useable(dest), exist_ok=True)
|
||||||
|
shutil.copystat(make_long_path_useable(path), make_long_path_useable(dest), follow_symlinks=False)
|
||||||
copier.register_folder(path)
|
copier.register_folder(path)
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
path = os.path.join(dirpath, f)
|
path = os.path.join(dirpath, f)
|
||||||
dest = dest_from_entry(dirpath, f)
|
dest = dest_from_entry(dirpath, f)
|
||||||
dest = transform_destination_filename(path, dest)
|
dest = transform_destination_filename(path, dest)
|
||||||
if not iswindows:
|
if not iswindows and not read_only:
|
||||||
s = os.stat(path, follow_symlinks=False)
|
s = os.stat(path, follow_symlinks=False)
|
||||||
if stat.S_ISLNK(s.st_mode):
|
if stat.S_ISLNK(s.st_mode):
|
||||||
link_dest = os.readlink(path)
|
link_dest = os.readlink(path)
|
||||||
@ -246,7 +248,7 @@ def register_folder_recursively(
|
|||||||
|
|
||||||
def windows_check_if_files_in_use(src_folder: str) -> None:
|
def windows_check_if_files_in_use(src_folder: str) -> None:
|
||||||
copier = get_copier()
|
copier = get_copier()
|
||||||
register_folder_recursively(src_folder, copier, os.getcwd())
|
register_folder_recursively(src_folder, copier, os.getcwd(), read_only=True)
|
||||||
with copier:
|
with copier:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user