From 61de01d892bd2f05f1806e4e915280e56254c086 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sat, 19 Aug 2023 06:21:32 +0300 Subject: msd: using .incomplete files instead of .complete --- kvmd/helpers/remount/__init__.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'kvmd/helpers') diff --git a/kvmd/helpers/remount/__init__.py b/kvmd/helpers/remount/__init__.py index 1738a90e..c6373fec 100644 --- a/kvmd/helpers/remount/__init__.py +++ b/kvmd/helpers/remount/__init__.py @@ -57,15 +57,24 @@ def _mkdir(path: str) -> None: raise SystemExit(f"Can't create directory: {err}") -def _rmdir(path: str) -> None: +def _rmtree(path: str) -> None: if exists(path): - _log(f"RMDIR --- {path}") + _log(f"RMALL --- {path}") try: - os.rmdir(path) + shutil.rmtree(path) except Exception as err: raise SystemExit(f"Can't remove directory: {err}") +def _rm(path: str) -> None: + if exists(path): + _log(f"RM --- {path}") + try: + os.remove(path) + except Exception as err: + raise SystemExit(f"Can't remove file: {err}") + + def _move(src: str, dest: str) -> None: _log(f"MOVE --- {src} --> {dest}") try: @@ -85,15 +94,22 @@ def _chown(path: str, user: str) -> None: # ===== def _fix_msd(part: Partition) -> None: + # First images migration images_path = join(part.root_path, "images") meta_path = join(part.root_path, "meta") if exists(images_path) and exists(meta_path): - for name in os.listdir(meta_path): - _move(join(meta_path, name), join(part.root_path, f".__{name}")) - _rmdir(meta_path) for name in os.listdir(images_path): _move(join(images_path, name), os.path.join(part.root_path, name)) - _rmdir(images_path) + if not exists(join(meta_path, f"{name}.complete")): + open(os.path.join(part.root_path, f".__{name}.incomplete")).close() # pylint: disable=consider-using-with + _rmtree(images_path) + _rmtree(meta_path) + + # Second images migration + for name in os.listdir(part.root_path): + if name.startswith(".__") and name.endswith(".complete"): + _rm(join(part.root_path, name)) + if part.user: _chown(part.root_path, part.user) -- cgit v1.2.3