diff --git a/mdrsclient/__main__.py b/mdrsclient/__main__.py index ee712ce..7ccd188 100644 --- a/mdrsclient/__main__.py +++ b/mdrsclient/__main__.py @@ -50,6 +50,8 @@ def main() -> None: except MDRSException as e: print(f"Error: {e}") sys.exit(2) + except KeyboardInterrupt: + sys.exit(130) if __name__ == "__main__": diff --git a/mdrsclient/config.py b/mdrsclient/config.py index 282d543..5aa5abe 100644 --- a/mdrsclient/config.py +++ b/mdrsclient/config.py @@ -6,6 +6,7 @@ import validators from mdrsclient.exceptions import IllegalArgumentException from mdrsclient.settings import CONFIG_DIRNAME +from mdrsclient.utils import FileLock class ConfigFile: @@ -70,7 +71,9 @@ class ConfigFile: def __save(self) -> None: self.__ensure_cache_dir() with open(self.__config_path, "w") as f: + FileLock.lock(f) self.__config.write(f) + FileLock.unlock(f) os.chmod(self.__config_path, 0o600) def __ensure_cache_dir(self) -> None: diff --git a/mdrsclient/utils.py b/mdrsclient/utils.py index a002d30..b4ea263 100644 --- a/mdrsclient/utils.py +++ b/mdrsclient/utils.py @@ -3,7 +3,6 @@ from typing import IO, Any if os.name == "nt": import msvcrt - elif os.name == "posix": import fcntl