From 89bb15d3b6cc1daab01ec1f6c1dfd578de1b892f Mon Sep 17 00:00:00 2001 From: Marcus Huewe Date: Thu, 1 Oct 2020 13:53:19 +0200 Subject: [PATCH] Add .old dir support for source services Some services expect "old" service files (that is, files from a previous service run) to be present in an ".old" dir. Hence, osc should support that. Instead of removing all files from a previous service run, move them to the ".old" dir, run the services, and, finally, remove the ".old" dir. Unfortunately, the location of the ".old" dir is hardcoded in the specific services. That is, we have to be careful if an ".old" dir exists (in this case, we error out). Based on [1]. [1] https://github.com/openSUSE/osc/pull/846 --- osc/core.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/osc/core.py b/osc/core.py index fd2c1a48..f6d1e2ca 100644 --- a/osc/core.py +++ b/osc/core.py @@ -410,16 +410,27 @@ class Serviceinfo: return r def execute(self, dir, callmode = None, singleservice = None, verbose = None): + old_dir = os.path.join(dir, '.old') + if os.path.exists(old_dir) or os.path.islink(old_dir): + msg = '"%s" exists, please remove it' % old_dir + raise oscerr.OscIOError(None, msg) + try: + os.mkdir(old_dir) + return self._execute(dir, old_dir, callmode, singleservice, + verbose) + finally: + if os.path.exists(old_dir): + shutil.rmtree(old_dir) + + def _execute(self, dir, old_dir, callmode=None, singleservice=None, + verbose=None): import tempfile # cleanup existing generated files for filename in os.listdir(dir): if filename.startswith('_service:') or filename.startswith('_service_'): - ent = os.path.join(dir, filename) - if os.path.isdir(ent): - shutil.rmtree(ent) - else: - os.unlink(ent) + os.rename(os.path.join(dir, filename), + os.path.join(old_dir, filename)) allservices = self.services or [] service_names = [s['name'] for s in allservices]