From c308cd3ee78951174d1732fe90be7e837e5f6350 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 2 Oct 2009 23:12:22 -0400 Subject: [PATCH] Migrate reverts if keyboard interrupted. Signed-off-by: Edward Z. Yang --- TODO | 7 ++----- wizard/command/migrate.py | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index f395d69..800c532 100644 --- a/TODO +++ b/TODO @@ -9,9 +9,8 @@ TODO NOW: --limit and then increase. - Allow to migrate just one user (user filtering of installs, also has userland capabilities, although it means we need some way of - selectively publishing the versions directory) -- Make migrate script rollback if it's interrupted (especially if - by signal) + selectively publishing the versions directory--likely a suid + executable that reads it would be the best way here) - Make parallel-find.pl use `sudo -u username git describe --tags` to determine version. Make parallel-find.pl have this have greater @@ -28,8 +27,6 @@ TODO NOW: - Better error message if daemon/scripts-security-upd is not on scripts-security-upd list -- MediaWiki upgrade script does not give proper exit code; - if it fails, so be sure to check for "Done" in the last 10 characters. - Custom merge algo: absolute php.ini symlinks to relative symlinks - Custom merge algo: re-constitute AdminSettings.php if missing. It looks like this is the case for most 1.5.8 installs (check what the merges diff --git a/wizard/command/migrate.py b/wizard/command/migrate.py index 420564e..4e5837d 100644 --- a/wizard/command/migrate.py +++ b/wizard/command/migrate.py @@ -49,16 +49,24 @@ def main(argv, baton): # XXX: turn this into a context try: try: - os.open(".scripts-migrate-lock", os.O_CREAT | os.O_EXCL) - except OSError as e: - if e.errno == errno.EEXIST: - raise DirectoryLockedError - elif e.errno == errno.EACCES: - raise command.PermissionsError(dir) - raise - if options.force: perform_force(options) - make_repository(sh, options, repo, tag) - check_variables(deployment, options) + try: + os.open(".scripts-migrate-lock", os.O_CREAT | os.O_EXCL) + except OSError as e: + if e.errno == errno.EEXIST: + raise DirectoryLockedError + elif e.errno == errno.EACCES: + raise command.PermissionsError(dir) + raise + if options.force: perform_force(options) + make_repository(sh, options, repo, tag) + check_variables(deployment, options) + except KeyboardInterrupt: + # revert it; barring a particularly zany race condition + # this is safe + if os.path.exists(".scripts"): + shutil.rmtree(".scripts") + if os.path.exists(".git"): + shutil.rmtree(".git") finally: try: os.unlink(".scripts-migrate-lock") -- 2.45.2