Merge pull request from phred/fix-fetch-module

Make 'fetch' test for local directories before creating.  Fixes issue 
This commit is contained in:
Michael DeHaan 2012-06-08 12:06:02 -07:00
commit ef074f3b61

View file

@ -463,7 +463,7 @@ class Runner(object):
dest = options.get('dest', None) dest = options.get('dest', None)
if source is None or dest is None: if source is None or dest is None:
results = dict(failed=True, msg="src and dest are required") results = dict(failed=True, msg="src and dest are required")
return ReturnData(host=conn.host, error=True, results=results) return ReturnData(host=conn.host, result=results)
# apply templating to source argument # apply templating to source argument
inject = self.setup_cache.get(conn.host,{}) inject = self.setup_cache.get(conn.host,{})
@ -482,10 +482,11 @@ class Runner(object):
local_md5 = None local_md5 = None
if os.path.exists(dest): if os.path.exists(dest):
local_md5 = os.popen("md5sum %s" % dest).read().split()[0] local_md5 = os.popen("md5sum %s" % dest).read().split()[0]
remote_md5 = self._low_level_exec_command(conn, "md5sum %s" % source, tmp, True)[0].split()[0] remote_md5 = self._low_level_exec_command(conn, "md5sum %s" % source, tmp, True).split()[0]
if remote_md5 != local_md5: if remote_md5 != local_md5:
# create the containing directories, if needed # create the containing directories, if needed
if not os.path.isdir(os.path.dirname(dest)):
os.makedirs(os.path.dirname(dest)) os.makedirs(os.path.dirname(dest))
# fetch the file and check for changes # fetch the file and check for changes