Merge lp:~allenap/launchpad/test-file-creation-oneiric-bug-892955 into lp:launchpad

Proposed by Gavin Panella
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 14417
Proposed branch: lp:~allenap/launchpad/test-file-creation-oneiric-bug-892955
Merge into: lp:launchpad
Diff against target: 75 lines (+14/-8)
2 files modified
lib/lp/poppy/tests/test_twistedsftp.py (+12/-6)
lib/lp/poppy/twistedsftp.py (+2/-2)
To merge this branch: bzr merge lp:~allenap/launchpad/test-file-creation-oneiric-bug-892955
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+83959@code.launchpad.net

Commit message

[r=julian-edwards][bug=892955] Create files with 0644 in SFTPFile.writeChunk() instead of 0664, which was being masked to 0644 by the default umask anyway.

Description of the change

Just use the intended file permissions in writeChunk() in the first place. The test worked before because the umask was 0022. It has now changed to 0002 on Oneiric.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/poppy/tests/test_twistedsftp.py'
2--- lib/lp/poppy/tests/test_twistedsftp.py 2011-08-12 11:37:08 +0000
3+++ lib/lp/poppy/tests/test_twistedsftp.py 2011-11-30 16:31:44 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2010 Canonical Ltd. This software is licensed under the
6+# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Tests for twistedsftp."""
10@@ -6,7 +6,8 @@
11 __metaclass__ = type
12
13 import os
14-import tempfile
15+
16+from fixtures import TempDir
17
18 from lp.poppy.twistedsftp import SFTPServer
19 from lp.services.sshserver.sftp import FileIsADirectory
20@@ -16,10 +17,16 @@
21 class TestSFTPServer(TestCase):
22
23 def setUp(self):
24- self.fs_root = tempfile.mkdtemp()
25+ self.fs_root = self.useFixture(TempDir()).path
26 self.sftp_server = SFTPServer(None, self.fs_root)
27 super(TestSFTPServer, self).setUp()
28
29+ def assertPermissions(self, expected, file_name):
30+ observed = os.stat(file_name).st_mode
31+ self.assertEqual(
32+ expected, observed, "Expected %07o, got %07o, for %s" % (
33+ expected, observed, file_name))
34+
35 def test_gotVersion(self):
36 # gotVersion always returns an empty dict, since the server does not
37 # support any extended features. See ISFTPServer.
38@@ -33,8 +40,7 @@
39 'foo')
40 dir_name = os.path.join(self.sftp_server._current_upload, 'foo')
41 self.assertEqual(os.listdir(dir_name)[0], 'bar')
42- self.assertEqual(
43- os.stat(os.path.join(dir_name, 'bar')).st_mode, 040775)
44+ self.assertPermissions(040775, dir_name)
45 self.sftp_server.removeDirectory('foo/bar')
46 self.assertEqual(
47 os.listdir(os.path.join(self.sftp_server._current_upload,
48@@ -50,7 +56,7 @@
49 test_file = open(file_name, 'r')
50 self.assertEqual(test_file.read(), "This is a test")
51 test_file.close()
52- self.assertEqual(os.stat(file_name).st_mode, 0100644)
53+ self.assertPermissions(0100644, file_name)
54 dir_name = os.path.join(self.sftp_server._current_upload, 'bar/foo')
55 os.makedirs(dir_name)
56 upload_file = self.sftp_server.openFile('bar/foo', None, None)
57
58=== modified file 'lib/lp/poppy/twistedsftp.py'
59--- lib/lp/poppy/twistedsftp.py 2011-05-09 01:57:28 +0000
60+++ lib/lp/poppy/twistedsftp.py 2011-11-30 16:31:44 +0000
61@@ -1,4 +1,4 @@
62-# Copyright 2010 Canonical Ltd. This software is licensed under the
63+# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
64 # GNU Affero General Public License version 3 (see the file LICENSE).
65
66 """Twisted SFTP implementation of the Poppy upload server."""
67@@ -128,7 +128,7 @@
68 def writeChunk(self, offset, data):
69 try:
70 chunk_file = os.open(
71- self.filename, os.O_CREAT | os.O_WRONLY, 0664)
72+ self.filename, os.O_CREAT | os.O_WRONLY, 0644)
73 except OSError, e:
74 if e.errno != errno.EISDIR:
75 raise