fix(keyringctl): restore cwd before deleting the temporary working dir
This avoids potential issues with wrapped runtime like ipython or pdb that try to invoke functions at exit and access the current working directory, which will ultimately lead to an error in case we deleted it before changing the current working directory.
This commit is contained in:
parent
92f07f0d4b
commit
a0199b0b04
49
keyringctl
49
keyringctl
@ -1074,31 +1074,30 @@ if __name__ == '__main__':
|
|||||||
# temporary working directory that gets auto cleaned
|
# temporary working directory that gets auto cleaned
|
||||||
with TemporaryDirectory() as tempdir:
|
with TemporaryDirectory() as tempdir:
|
||||||
working_dir = Path(tempdir)
|
working_dir = Path(tempdir)
|
||||||
chdir(working_dir)
|
|
||||||
debug(f'Working directory: {working_dir}')
|
debug(f'Working directory: {working_dir}')
|
||||||
|
with cwd(working_dir):
|
||||||
|
if args.subcommand in ["convert", "import"]:
|
||||||
|
if args.target:
|
||||||
|
args.target.mkdir(parents=True, exist_ok=True)
|
||||||
|
target_dir = args.target
|
||||||
|
else:
|
||||||
|
# persistent target directory
|
||||||
|
target_dir = Path(mkdtemp()).absolute()
|
||||||
|
|
||||||
if args.subcommand in ["convert", "import"]:
|
if 'convert' == args.subcommand:
|
||||||
if args.target:
|
print(convert(working_dir, args.source, target_dir))
|
||||||
args.target.mkdir(parents=True, exist_ok=True)
|
elif 'import' == args.subcommand:
|
||||||
target_dir = args.target
|
keyring_import(working_dir, args.source, target_dir)
|
||||||
else:
|
elif 'export' == args.subcommand:
|
||||||
# persistent target directory
|
export_keyring(
|
||||||
target_dir = Path(mkdtemp()).absolute()
|
working_dir=working_dir,
|
||||||
|
main=args.main,
|
||||||
|
sources=args.source,
|
||||||
|
output=args.output,
|
||||||
|
force=args.force,
|
||||||
|
pacman_integration=args.pacman_integration,
|
||||||
|
)
|
||||||
|
|
||||||
if 'convert' == args.subcommand:
|
if args.wait:
|
||||||
print(convert(working_dir, args.source, target_dir))
|
print('Press [ENTER] to continue')
|
||||||
elif 'import' == args.subcommand:
|
input()
|
||||||
keyring_import(working_dir, args.source, target_dir)
|
|
||||||
elif 'export' == args.subcommand:
|
|
||||||
export_keyring(
|
|
||||||
working_dir=working_dir,
|
|
||||||
main=args.main,
|
|
||||||
sources=args.source,
|
|
||||||
output=args.output,
|
|
||||||
force=args.force,
|
|
||||||
pacman_integration=args.pacman_integration,
|
|
||||||
)
|
|
||||||
|
|
||||||
if args.wait:
|
|
||||||
print('Press [ENTER] to continue')
|
|
||||||
input()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user