From 40e877750090ad3e22adb0eb15a1e0fc6bafa9fb Mon Sep 17 00:00:00 2001 From: Peter Eckersley Date: Fri, 8 Apr 2016 16:04:47 -0700 Subject: [PATCH 1/2] reverter.finalize_checkpoint() : handle empty checkpoints Should fix #1243 --- letsencrypt/reverter.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/letsencrypt/reverter.py b/letsencrypt/reverter.py index ea54a91ee..0ed75df6f 100644 --- a/letsencrypt/reverter.py +++ b/letsencrypt/reverter.py @@ -481,30 +481,32 @@ class Reverter(object): checkpoint is not able to be finalized. """ - # Adds title to self.config.in_progress_dir CHANGES_SINCE - # Move self.config.in_progress_dir to Backups directory and - # rename the directory as a timestamp # Check to make sure an "in progress" directory exists if not os.path.isdir(self.config.in_progress_dir): return - changes_since_path = os.path.join( - self.config.in_progress_dir, "CHANGES_SINCE") + changes_since_path = os.path.join(self.config.in_progress_dir, "CHANGES_SINCE") + changes_since_tmp_path = os.path.join(self.config.in_progress_dir, "CHANGES_SINCE.tmp") - changes_since_tmp_path = os.path.join( - self.config.in_progress_dir, "CHANGES_SINCE.tmp") + if not os.path.exists(self.config.changes_since_path): + logger.info("Rollback checkpoint is empty (no changes made?)") + with open(self.config.changes_since_path) as f: + f.write("No changes\n") + # Add title to self.config.in_progress_dir CHANGES_SINCE try: with open(changes_since_tmp_path, "w") as changes_tmp: changes_tmp.write("-- %s --\n" % title) with open(changes_since_path, "r") as changes_orig: changes_tmp.write(changes_orig.read()) + # Move self.config.in_progress_dir to Backups directory shutil.move(changes_since_tmp_path, changes_since_path) except (IOError, OSError): logger.error("Unable to finalize checkpoint - adding title") raise errors.ReverterError("Unable to add title") + # rename the directory as a timestamp self._timestamp_progress_dir() def _timestamp_progress_dir(self): From 5e971a5e5a9a7dd8baed9a61091810f3ef4bc1ac Mon Sep 17 00:00:00 2001 From: Peter Eckersley Date: Fri, 8 Apr 2016 16:38:40 -0700 Subject: [PATCH 2/2] Check the right path --- letsencrypt/reverter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letsencrypt/reverter.py b/letsencrypt/reverter.py index 0ed75df6f..b7928220b 100644 --- a/letsencrypt/reverter.py +++ b/letsencrypt/reverter.py @@ -488,7 +488,7 @@ class Reverter(object): changes_since_path = os.path.join(self.config.in_progress_dir, "CHANGES_SINCE") changes_since_tmp_path = os.path.join(self.config.in_progress_dir, "CHANGES_SINCE.tmp") - if not os.path.exists(self.config.changes_since_path): + if not os.path.exists(changes_since_path): logger.info("Rollback checkpoint is empty (no changes made?)") with open(self.config.changes_since_path) as f: f.write("No changes\n")