Merge lp:~andreserl/maas/maas_set_correct_file_permissions into lp:~maas-committers/maas/trunk

Proposed by Julian Edwards
Status: Rejected
Rejected by: Julian Edwards
Proposed branch: lp:~andreserl/maas/maas_set_correct_file_permissions
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~andreserl/maas/maas_fix_broken_tftppath_tests
Diff against target: 33 lines (+5/-0)
2 files modified
src/provisioningserver/pxe/install_image.py (+1/-0)
src/provisioningserver/utils.py (+4/-0)
To merge this branch: bzr merge lp:~andreserl/maas/maas_set_correct_file_permissions
Reviewer Review Type Date Requested Status
Julian Edwards (community) Needs Fixing
Review via email: mp+121974@code.launchpad.net

This proposal supersedes a proposal from 2012-08-29.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

This is great! But it needs tests...

review: Needs Fixing
Revision history for this message
Julian Edwards (julian-edwards) wrote :

BTW I took the liberty of re-proposing the merge so it has the pre-requisite branch set, which makes the diff only show what this branch changes.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

In src/provisioningserver/pxe/install_image.py, the chmod is unnecessarily being done in the critical section that we want to keep as brief as possible. Do it before, not during!

In src/provisioningserver/utils.py, the comment says we "assume" that 'filename' is not a file -- right after the "if not os.is_file(filename) that actually proves it. Can you find a better way to word that?

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Ah, I rubbed the sleep out of my eyes and took a better look. I was completely mistaken about the second issue -- although I still can't figure out what the basis for the assumption is. I suspect that chmod inside atomic_write may belong in the caller.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Nope, caller is no good for this. It can't be done before or after atomic_write. But the chmod is in the wrong place: it effectively makes the write non-atomic by creating a race window where the file may be non-accessible for no good reason.

I still can't make sense of the comment... Clearly "filename" is not a directory. It is the file you just wrote.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Anyway, as per the kanban board I already had a branch in progress for this. I'll move that forward; it's a bit simpler. I also marked the bug as in-progress and assigned to myself, to match the board.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/pxe/install_image.py'
2--- src/provisioningserver/pxe/install_image.py 2012-07-23 10:24:39 +0000
3+++ src/provisioningserver/pxe/install_image.py 2012-08-30 02:02:23 +0000
4@@ -108,6 +108,7 @@
5 if os.path.isdir(old):
6 os.rename(old, '%s.old' % old)
7 os.rename('%s.new' % old, old)
8+ os.chmod(old, 0755)
9 # End of critical window.
10
11 # Now delete the old image directory at leisure.
12
13=== modified file 'src/provisioningserver/utils.py'
14--- src/provisioningserver/utils.py 2012-08-24 09:21:34 +0000
15+++ src/provisioningserver/utils.py 2012-08-30 02:02:23 +0000
16@@ -75,6 +75,9 @@
17 if not os.path.isfile(filename):
18 temp_file = _write_temp_file(content, filename)
19 os.rename(temp_file, filename)
20+ # Setting 0755 as we assume `filename` is not a file
21+ # but rather it is a directory.
22+ os.chmod(filename, 0755)
23 finally:
24 # Release the lock.
25 lock.release()
26@@ -83,6 +86,7 @@
27 # POSIX systems.
28 temp_file = _write_temp_file(content, filename)
29 os.rename(temp_file, filename)
30+ os.chmod(filename, 0644)
31
32
33 def incremental_write(content, filename):