do not assume target_host is anything that can be used as a directory name
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
ce26deb706
commit
13d315d718
1 changed files with 9 additions and 8 deletions
|
@ -29,6 +29,7 @@ import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import hashlib
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
import cdist.message
|
import cdist.message
|
||||||
|
@ -55,8 +56,10 @@ class Local(object):
|
||||||
base_path_parent = base_path
|
base_path_parent = base_path
|
||||||
else:
|
else:
|
||||||
base_path_parent = tempfile.mkdtemp()
|
base_path_parent = tempfile.mkdtemp()
|
||||||
import atexit
|
# TODO: the below atexit hook nukes any debug info we would have
|
||||||
atexit.register(lambda: shutil.rmtree(base_path_parent))
|
# if cdist exits with error.
|
||||||
|
#import atexit
|
||||||
|
#atexit.register(lambda: shutil.rmtree(base_path_parent))
|
||||||
self.hostdir = self._hostdir()
|
self.hostdir = self._hostdir()
|
||||||
self.base_path = os.path.join(base_path_parent, self.hostdir)
|
self.base_path = os.path.join(base_path_parent, self.hostdir)
|
||||||
|
|
||||||
|
@ -89,11 +92,9 @@ class Local(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _hostdir(self):
|
def _hostdir(self):
|
||||||
if os.path.isabs(self.target_host):
|
# Do not assume target_host is anything that can be used as a directory name.
|
||||||
hostdir = self.target_host[1:]
|
# Instead use a hash, which is know to work as directory name.
|
||||||
else:
|
return hashlib.md5(self.target_host.encode('utf-8')).hexdigest()
|
||||||
hostdir = self.target_host
|
|
||||||
return hostdir
|
|
||||||
|
|
||||||
def _init_log(self):
|
def _init_log(self):
|
||||||
self.log = logging.getLogger(self.target_host)
|
self.log = logging.getLogger(self.target_host)
|
||||||
|
@ -227,7 +228,7 @@ class Local(object):
|
||||||
|
|
||||||
|
|
||||||
def save_cache(self):
|
def save_cache(self):
|
||||||
destination = os.path.join(self.cache_path, self.hostdir)
|
destination = os.path.join(self.cache_path, self.target_host)
|
||||||
self.log.debug("Saving " + self.base_path + " to " + destination)
|
self.log.debug("Saving " + self.base_path + " to " + destination)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue