mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #25379 from jfindlay/check_wd
check for cwd before getting it
This commit is contained in:
commit
beb0238392
3 changed files with 16 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue