From 36a9a23c9d501b74f386fda826d8efaf53e02376 Mon Sep 17 00:00:00 2001 From: Alexander Hughes Date: Wed, 10 Jul 2019 22:53:34 -0500 Subject: [PATCH] Allow Pegleg to overwrite existing files Pegleg currently raises an exception when a filepath exists before writing to it in the case of yaml.dump actions. This is not always desired behavior, and with the addition of the flags passed into the files methods for write/append is no longer necessary. Removing these so that overwrite options can take place for example when rotating passphrases or secrets. Change-Id: I2200cc681a797d91a90f6237662fd1ee77954906 --- pegleg/engine/util/files.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pegleg/engine/util/files.py b/pegleg/engine/util/files.py index 644e5cab..f5184134 100644 --- a/pegleg/engine/util/files.py +++ b/pegleg/engine/util/files.py @@ -239,9 +239,6 @@ def slurp(path): def dump(data, path, flag='w', **kwargs): - if flag == 'w' and os.path.exists(path): - raise click.ClickException('%s already exists, aborting' % path) - os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True) with open(path, flag) as f: @@ -249,9 +246,6 @@ def dump(data, path, flag='w', **kwargs): def safe_dump(data, path, flag='w', **kwargs): - if flag == 'w' and os.path.exists(path): - raise click.ClickException('%s already exists, aborting' % path) - os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True) with open(path, flag) as f: @@ -259,9 +253,6 @@ def safe_dump(data, path, flag='w', **kwargs): def dump_all(data, path, flag='w', **kwargs): - if flag == 'w' and os.path.exists(path): - raise click.ClickException('%s already exists, aborting' % path) - os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True) with open(path, flag) as f: