From 0938cf934aa94c20d60e905e3f8ae0b134c857c2 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 4 Jun 2022 17:15:52 +0900 Subject: [PATCH] Add some path validation/dir-creation --- update.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/update.py b/update.py index 6a9a170..9797246 100755 --- a/update.py +++ b/update.py @@ -849,10 +849,6 @@ def update_pkg_list( pkg_state[pkg]["build_status"] = "success" - log_print("Ensuring pkgs directory exists...") - if not os.path.exists(other_state['pkg_out_dir']): - pkg_out_dir_path = Path(other_state['pkg_out_dir']) - pkg_out_dir_path.mkdir(parents=True) log_print("Moving pkg to pkgs directory...") for f in pkg_list: log_print(f'Moving "{f}"...') @@ -958,6 +954,30 @@ def test_gpg_passphrase(signing_gpg_dir, signing_key_fp, passphrase): return True +def validate_and_verify_paths(other_state): + if not os.path.exists(other_state['chroot']): + log_print(f"ERROR: chroot at "{other_state['chroot']}" does not exist") + sys.exit(1) + log_print("Ensuring pkgs directory exists...") + if not os.path.exists(other_state['pkg_out_dir']): + pkg_out_dir_path = Path(other_state['pkg_out_dir']) + pkg_out_dir_path.mkdir(parents=True) + if not os.path.exists(other_state['gpg_home']): + log_print(f"ERROR: checkingGPG at "{other_state['gpg_home']}" does not exist") + sys.exit(1) + log_print("Ensuring logs directory exists...") + if other_state['logs_dir'] is None: + log_print('ERROR: "logs_dir" was not specified!') + sys.exit(1) + if not os.path.exists(other_state['logs_dir']): + logs_dir_path = Path(other_state['logs_dir']) + logs_dir_path.mkdir(parents=True) + log_print("Ensuring clones directory exists...") + if not os.path.exists(other_state['clones_dir']): + clones_dir_path = Path(other_state['clones_dir']) + clones_dir_path.mkdir(parents=True) + + if __name__ == "__main__": editor = None parser = argparse.ArgumentParser(description="Update AUR pkgs") @@ -1121,6 +1141,8 @@ if __name__ == "__main__": log_print('ERROR: At least "--config" or "--pkg" must be specified') sys.exit(1) + validate_and_verify_paths(other_state) + if args.editor is not None: editor = args.editor