From 9ca27eedccfaf01f1f348362fd973bfe93c7a540 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Sun, 16 Nov 2014 01:13:29 +0100 Subject: [PATCH] apt_repository: fix file mode 'set_mode_if_different' method should be called on dest filename and after 'atomic_move' method --- packaging/os/apt_repository.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packaging/os/apt_repository.py b/packaging/os/apt_repository.py index 2ee5819fc4e..5f252371e4a 100644 --- a/packaging/os/apt_repository.py +++ b/packaging/os/apt_repository.py @@ -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):