From 33feaa81cac6350185dd6b5a544704ab3109f91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 13 Sep 2017 11:22:38 +0200 Subject: [PATCH] Orphan finder: refuse to find orphans when orphan-files.txt exists. --- pillar/cli/maintenance.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pillar/cli/maintenance.py b/pillar/cli/maintenance.py index dc4671a5..ee73ead5 100644 --- a/pillar/cli/maintenance.py +++ b/pillar/cli/maintenance.py @@ -600,6 +600,12 @@ def find_orphan_files(proj_url): This is a heavy operation that inspects *everything* in MongoDB. Use with care. """ from jinja2.filters import do_filesizeformat + from pathlib import Path + + output_fpath = Path('orphan-files.txt') + if output_fpath.exists(): + log.error('Output filename %s already exists, remove it first.', output_fpath) + return 1 start_timestamp = datetime.datetime.now() @@ -650,5 +656,5 @@ def find_orphan_files(proj_url): log.info('Finding orphans took %s', duration) log.info('Writing Object IDs to orphan-files.txt') - with open('orphan-files.txt', 'w') as outfile: + with output_fpath.open('w', encoding='ascii') as outfile: outfile.write('\n'.join(str(oid) for oid in sorted(orphans)) + '\n')