diff options
author | Jose Castillo <jcastillo@redhat.com> | 2021-02-02 14:35:07 +0100 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2021-02-09 13:21:01 -0500 |
commit | aca3a9b9f9159bd38f94903dcc82313ae1fb9841 (patch) | |
tree | 4ca5ff4e58399bc58b2198f0df7eb7cd7f9c804d | |
parent | f9db680ec67de3e97aaa233ffccdf4ccdb5ad307 (diff) | |
download | sos-aca3a9b9f9159bd38f94903dcc82313ae1fb9841.tar.gz |
[cleaner] Automatically create directory for sos-cleaner default_mapping
When /etc/sos/cleaner directory is missing, cleaner fails to store
new default_mapping file due to:
[cleaner] Could not update mapping config file:
[Errno 2] No such file or directory: '/etc/sos/cleaner/default_mapping'
This patch adds the code to check the existence of the directory
and create it if necessary.
Resolves: RHBZ#1923937
Closes: #2393
Resolves: #2397
Signed-off-by: Jose Castillo <jcastillo@redhat.com>
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/cleaner/__init__.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py index 66036f0f..ba972ad4 100644 --- a/sos/cleaner/__init__.py +++ b/sos/cleaner/__init__.py @@ -405,7 +405,12 @@ third party. able to provide the same consistent mapping """ if self.opts.map_file and not self.opts.no_update: + cleaner_dir = os.path.dirname(self.opts.map_file) + """ Attempt to create the directory /etc/sos/cleaner + just in case it didn't exist previously + """ try: + os.makedirs(cleaner_dir, exist_ok=True) self.write_map_to_file(_map, self.opts.map_file) self.log_debug("Wrote mapping to %s" % self.opts.map_file) except Exception as err: |