apt_repository: fix file mode

'set_mode_if_different' method should be called on dest filename and after
'atomic_move' method
This commit is contained in:
Pierre-Louis Bonicoli 2014-11-16 01:13:29 +01:00 committed by Matt Clay
parent b318bc8b43
commit c366e7acb2

View file

@ -238,10 +238,6 @@ class SourcesList(object):
d, fn = os.path.split(filename)
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')
for n, valid, enabled, source, comment in sources:
chunks = []
@ -259,6 +255,10 @@ class SourcesList(object):
except IOError, err:
module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err)))
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:
del self.files[filename]
if os.path.exists(filename):