aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFernando Royo <froyo@redhat.com>2023-02-07 16:34:10 +0100
committerJake Hunsaker <jhunsake@redhat.com>2023-02-08 15:42:34 -0500
commitf7e7b735bee9117d130aeffafe5c0f22c3c338cb (patch)
tree7dd10a908592ecdca9c1be83978cf6ff64a566da
parentda23b44644ae6bb5a2abda444f0cd8e5cc50184e (diff)
downloadsos-f7e7b735bee9117d130aeffafe5c0f22c3c338cb.tar.gz
Avoid overwrite symbolic link for a command output
Every output of a command run on a container is saved in the sos_commands folder, also additionally a symbolic link is created from the sos_container folder to link the container where it was run to the output file. When there is a duplicated command on the list to be run on the container, the symbolic link creation will fail due to file already exists error. To avoid this error we can trust on the check_path method, that will give us a clue avoid if the file already exists or not to continue with the symbolic link creation. Signed-off-by: Fernando Royo <froyo@redhat.com>
-rw-r--r--sos/report/plugins/__init__.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py
index 1624ca37..b75053bf 100644
--- a/sos/report/plugins/__init__.py
+++ b/sos/report/plugins/__init__.py
@@ -16,7 +16,7 @@ from sos.utilities import (sos_get_command_output, import_module, grep,
listdir, path_join, bold, file_is_binary,
recursive_dict_values_by_key)
-from sos.archive import P_FILE
+from sos.archive import P_FILE, P_LINK
import contextlib
import os
import glob
@@ -2645,8 +2645,11 @@ class Plugin():
cmdfn = self._mangle_command(cmd)
conlnk = "%s/%s" % (_cdir, cmdfn)
- self.archive.check_path(conlnk, P_FILE)
- os.symlink(_outloc, self.archive.dest_path(conlnk))
+ # If check_path return None, it means that the sym link already exits,
+ # so to avoid Error 17, trying to recreate, we will skip creation and
+ # trust on the existing sym link (e.g. duplicate command)
+ if self.archive.check_path(conlnk, P_LINK):
+ os.symlink(_outloc, self.archive.dest_path(conlnk))
manifest['filepath'] = conlnk
self.manifest.containers[container]['commands'].append(manifest)