Change munkicommon.tmpdir to a function so that importing munkicommon does not create orphaned munki-foo directories in /tmp

This commit is contained in:
Greg Neagle
2014-10-25 10:06:37 -07:00
parent 2b4e04159f
commit 564e4ac368
7 changed files with 25 additions and 20 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ def makeDMG(pkgpath):
pkgname = os.path.basename(pkgpath)
print 'Making disk image containing %s...' % pkgname
diskimagename = os.path.splitext(pkgname)[0] + '.dmg'
diskimagepath = os.path.join(munkicommon.tmpdir, diskimagename)
diskimagepath = os.path.join(munkicommon.tmpdir(), diskimagename)
cmd = ['/usr/bin/hdiutil', 'create', '-srcfolder', pkgpath, diskimagepath]
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+1 -1
View File
@@ -660,7 +660,7 @@ def doAdobeCS5Uninstall(adobeInstallInfo, payloads=None):
munkicommon.display_error("No uninstall.xml in adobe_install_info")
return -1
payloadcount = adobeInstallInfo.get('payload_count', 0)
path = os.path.join(munkicommon.tmpdir, "uninstall.xml")
path = os.path.join(munkicommon.tmpdir(), "uninstall.xml")
deploymentFile = writefile(uninstallxml, path)
if not deploymentFile:
return -1
+1 -1
View File
@@ -727,7 +727,7 @@ def installWithInfo(
munkicommon.display_debug1("suppress_bundle_relocation: %s" %
suppressBundleRelocation )
if 'installer_choices_xml' in item:
choicesXMLfile = os.path.join(munkicommon.tmpdir,
choicesXMLfile = os.path.join(munkicommon.tmpdir(),
"choices.xml")
FoundationPlist.writePlist(item['installer_choices_xml'],
choicesXMLfile)
+1 -1
View File
@@ -223,7 +223,7 @@ def make_client_keychain(certdata=None):
cert_data = read_file(client_cert_path)
key_data = read_file(client_key_path)
# write the combined data
combined_pem = os.path.join(munkicommon.tmpdir, 'combined.pem')
combined_pem = os.path.join(munkicommon.tmpdir(), 'combined.pem')
if write_file(cert_data + key_data, combined_pem):
munkicommon.display_debug1('Importing client cert and key...')
try:
+1 -1
View File
@@ -42,7 +42,7 @@ class Job(object):
'''launchd job object'''
def __init__(self, cmd, environment_vars=None):
tmpdir = munkicommon.tmpdir
tmpdir = munkicommon.tmpdir()
LABELPREFIX = 'com.googlecode.munki.'
# create a unique id for this job
jobid = str(uuid.uuid1())
+18 -10
View File
@@ -831,8 +831,8 @@ def DMGisWritable(dmgpath):
if pliststr:
try:
plist = FoundationPlist.readPlistFromString(pliststr)
format = plist.get('Format')
if format in ['UDSB', 'UDSP', 'UDRW', 'RdWr']:
dmg_format = plist.get('Format')
if dmg_format in ['UDSB', 'UDSP', 'UDRW', 'RdWr']:
return True
except FoundationPlist.NSPropertyListSerializationException:
pass
@@ -1514,7 +1514,7 @@ def getFlatPackageInfo(pkgpath):
# get the absolute path to the pkg because we need to do a chdir later
abspkgpath = os.path.abspath(pkgpath)
# make a tmp dir to expand the flat package into
pkgtmp = tempfile.mkdtemp(dir=tmpdir)
pkgtmp = tempfile.mkdtemp(dir=tmpdir())
# record our current working dir
cwd = os.getcwd()
# change into our tmpdir so we can use xar to unarchive the flat package
@@ -2483,16 +2483,24 @@ def getAvailableDiskSpace(volumepath='/'):
return int(st.f_frsize * st.f_bavail / 1024) # f_bavail matches df(1) output
def tmpdir():
'''Returns a temporary directory for this session'''
global _TMPDIR
if not _TMPDIR:
_TMPDIR = tempfile.mkdtemp(prefix='munki-', dir='/tmp')
return _TMPDIR
def cleanUpTmpDir():
"""Cleans up our temporary directory."""
global tmpdir
if tmpdir:
global _TMPDIR
if _TMPDIR:
try:
shutil.rmtree(tmpdir)
shutil.rmtree(_TMPDIR)
except (OSError, IOError):
display_warning(
'Unable to clean up temporary dir %s: %s', tmpdir, str(e))
tmpdir = None
'Unable to clean up temporary dir %s: %s', _TMPDIR, str(e))
_TMPDIR = None
def listdir(path):
@@ -2602,7 +2610,7 @@ def runEmbeddedScript(scriptname, pkginfo_item, suppress_error=False):
return -1
# write the script to a temp file
scriptpath = os.path.join(tmpdir, scriptname)
scriptpath = os.path.join(tmpdir(), scriptname)
if writefile(script_text, scriptpath):
cmd = ['/bin/chmod', '-R', 'o+x', scriptpath]
retcode = subprocess.call(cmd)
@@ -2728,7 +2736,7 @@ def blockingApplicationsRunning(pkginfoitem):
#debug = False
verbose = 1
munkistatusoutput = False
tmpdir = tempfile.mkdtemp(prefix='munki-', dir='/tmp')
_TMPDIR = None
report = {}
def main():
+2 -5
View File
@@ -2287,10 +2287,7 @@ def processRemoval(manifestitem, cataloglist, installinfo):
iteminfo = {}
iteminfo['name'] = uninstall_item.get('name', '')
iteminfo['display_name'] = uninstall_item.get('display_name', '')
iteminfo['description'] = uninstall_item.get(
'uninstall_description',
'Will be removed.'
)
iteminfo['description'] = 'Will be removed.'
# we will ignore the unattended_uninstall key if the item needs a restart
# or logout...
@@ -3325,7 +3322,7 @@ def getDataFromURL(url):
'''Returns data from url as string. We use the existing
getResourceIfChangedAtomically function so any custom
authentication/authorization headers are reused'''
urldata = os.path.join(munkicommon.tmpdir, 'urldata')
urldata = os.path.join(munkicommon.tmpdir(), 'urldata')
if os.path.exists(urldata):
try:
os.unlink(urldata)