Merge pull request #338 from pilou-/apt_repository_filemode

apt_repository: fix file mode
This commit is contained in:
Toshio Kuratomi 2015-06-24 16:01:45 -07:00
commit 720632f568

View file

@ -238,10 +238,6 @@ class SourcesList(object):
d, fn = os.path.split(filename) d, fn = os.path.split(filename)
fd, tmp_path = tempfile.mkstemp(prefix=".%s-" % fn, dir=d) fd, tmp_path = tempfile.mkstemp(prefix=".%s-" % fn, dir=d)
# allow the user to override the default mode
this_mode = module.params['mode']
module.set_mode_if_different(tmp_path, this_mode, False)
f = os.fdopen(fd, 'w') f = os.fdopen(fd, 'w')
for n, valid, enabled, source, comment in sources: for n, valid, enabled, source, comment in sources:
chunks = [] chunks = []
@ -259,6 +255,10 @@ class SourcesList(object):
except IOError, err: except IOError, err:
module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err))) module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err)))
module.atomic_move(tmp_path, filename) module.atomic_move(tmp_path, filename)
# allow the user to override the default mode
this_mode = module.params['mode']
module.set_mode_if_different(filename, this_mode, False)
else: else:
del self.files[filename] del self.files[filename]
if os.path.exists(filename): if os.path.exists(filename):