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
=== modified file 'src/provisioningserver/pxe/install_image.py'
--- src/provisioningserver/pxe/install_image.py 2012-07-23 10:24:39 +0000
+++ src/provisioningserver/pxe/install_image.py 2012-08-30 02:02:23 +0000
@@ -108,6 +108,7 @@
108 if os.path.isdir(old):108 if os.path.isdir(old):
109 os.rename(old, '%s.old' % old)109 os.rename(old, '%s.old' % old)
110 os.rename('%s.new' % old, old)110 os.rename('%s.new' % old, old)
111 os.chmod(old, 0755)
111 # End of critical window.112 # End of critical window.
112113
113 # Now delete the old image directory at leisure.114 # Now delete the old image directory at leisure.
114115
=== modified file 'src/provisioningserver/utils.py'
--- src/provisioningserver/utils.py 2012-08-24 09:21:34 +0000
+++ src/provisioningserver/utils.py 2012-08-30 02:02:23 +0000
@@ -75,6 +75,9 @@
75 if not os.path.isfile(filename):75 if not os.path.isfile(filename):
76 temp_file = _write_temp_file(content, filename)76 temp_file = _write_temp_file(content, filename)
77 os.rename(temp_file, filename)77 os.rename(temp_file, filename)
78 # Setting 0755 as we assume `filename` is not a file
79 # but rather it is a directory.
80 os.chmod(filename, 0755)
78 finally:81 finally:
79 # Release the lock.82 # Release the lock.
80 lock.release()83 lock.release()
@@ -83,6 +86,7 @@
83 # POSIX systems.86 # POSIX systems.
84 temp_file = _write_temp_file(content, filename)87 temp_file = _write_temp_file(content, filename)
85 os.rename(temp_file, filename)88 os.rename(temp_file, filename)
89 os.chmod(filename, 0644)
8690
8791
88def incremental_write(content, filename):92def incremental_write(content, filename):