check for cwd before getting it

Fixes #25337.
This commit is contained in:
Justin Findlay 2015-07-13 12:32:55 -06:00
parent 274622ad9b
commit 6e4547ff38
3 changed files with 16 additions and 5 deletions

View file

@ -174,13 +174,17 @@ def prep_trans_tar(file_client, chunks, file_refs, pillar=None):
os.makedirs(tgt_dir)
shutil.copy(filename, tgt)
continue
cwd = os.getcwd()
try: # cwd may not exist if it was removed but salt was run from it
cwd = os.getcwd()
except OSError:
cwd = None
os.chdir(gendir)
with closing(tarfile.open(trans_tar, 'w:gz')) as tfp:
for root, dirs, files in os.walk(gendir):
for name in files:
full = os.path.join(root, name)
tfp.add(full[len(gendir):].lstrip(os.sep))
os.chdir(cwd)
if cwd:
os.chdir(cwd)
shutil.rmtree(gendir)
return trans_tar

View file

@ -298,7 +298,10 @@ class SaltfileMixIn(object):
# If we're here, no one passed a Saltfile either to the CLI tool or
# as an environment variable.
# Is there a Saltfile in the current directory?
saltfile = os.path.join(os.getcwd(), 'Saltfile')
try: # cwd may not exist if it was removed but salt was run from it
saltfile = os.path.join(os.getcwd(), 'Saltfile')
except OSError:
saltfile = ''
if os.path.isfile(saltfile):
self.options.saltfile = saltfile
else:

View file

@ -151,7 +151,10 @@ def gen_thin(cachedir, extra_mods='', overwrite=False, so_mods=''):
if HAS_MARKUPSAFE:
tops.append(os.path.dirname(markupsafe.__file__))
tfp = tarfile.open(thintar, 'w:gz', dereference=True)
start_dir = os.getcwd()
try: # cwd may not exist if it was removed but salt was run from it
start_dir = os.getcwd()
except OSError:
start_dir = None
tempdir = None
for top in tops:
base = os.path.basename(top)
@ -182,7 +185,8 @@ def gen_thin(cachedir, extra_mods='', overwrite=False, so_mods=''):
fp_.write(salt.version.__version__)
os.chdir(os.path.dirname(thinver))
tfp.add('version')
os.chdir(start_dir)
if start_dir:
os.chdir(start_dir)
tfp.close()
return thintar