aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2019-05-22 13:21:27 +0200
committerBryn M. Reeves <bmr@redhat.com>2019-08-15 16:40:23 +0100
commit47dcdb876dfd01db67c9ff4731f467854505210a (patch)
treeb82f97d759e30021e95a022ba92ee38ea58b7310
parent7b485f02c39b0d8502c224dd90c27024951948dc (diff)
downloadsos-47dcdb876dfd01db67c9ff4731f467854505210a.tar.gz
[plugins] fix mangled command filenames collisions
- Command filenames collisions must be tested tested against absolute path, not relative. Otherwise false positive results about no collisions are returned. - If collision happens for long filenames, ensure that appending ".1" or similar does not exceed the max filename length. Resolves: #1684 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r--sos/plugins/__init__.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index aa268d84..e51ca6a7 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -965,20 +965,27 @@ class Plugin(object):
if subdir:
# only allow a single level of subdir to be created
plugin_dir += "/%s" % subdir.split('/')[0]
- outfn = os.path.join(self.commons['cmddir'], plugin_dir,
- self._mangle_command(exe))
+ outdir = os.path.join(self.commons['cmddir'], plugin_dir)
+ outfn = self._mangle_command(exe)
# check for collisions
- if os.path.exists(outfn):
- inc = 2
+ if os.path.exists(os.path.join(self.archive.get_tmp_dir(),
+ outdir, outfn)):
+ inc = 1
+ name_max = self.archive.name_max()
while True:
- newfn = "%s_%d" % (outfn, inc)
- if not os.path.exists(newfn):
+ suffix = ".%d" % inc
+ newfn = outfn
+ if name_max < len(newfn)+len(suffix):
+ newfn = newfn[:(name_max-len(newfn)-len(suffix))]
+ newfn = newfn + suffix
+ if not os.path.exists(os.path.join(self.archive.get_tmp_dir(),
+ outdir, newfn)):
outfn = newfn
break
inc += 1
- return outfn
+ return os.path.join(outdir, outfn)
def add_env_var(self, name):
"""Add an environment variable to the list of to-be-collected env vars.