Merge lp:~jderose/filestore/ensuredir into lp:filestore

Proposed by Jason Gerard DeRose
Status: Merged
Merged at revision: 185
Proposed branch: lp:~jderose/filestore/ensuredir
Merge into: lp:filestore
Diff against target: 40 lines (+11/-7)
2 files modified
filestore.py (+6/-5)
test_filestore.py (+5/-2)
To merge this branch: bzr merge lp:~jderose/filestore/ensuredir
Reviewer Review Type Date Requested Status
Paul Hummer (community) Approve
Jason Gerard DeRose Needs Resubmitting
Review via email: mp+74310@code.launchpad.net

Description of the change

This is a small tweak to the ensuredir() function so that only one sys call to stat() or lstat() is made.

This makes ensuredir() more atomic and correct. Also should improve FileStore.init_dirs() slightly, although that wasn't the motivation.

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) wrote :

's' is not a very good name for a variable. Sure, the scope is limited, but it looks like you've also got a 'd' variable nearby. I would discourage that even in a language where the variable length might matter (like client-side javascript). You might want to re-think that.

...of course, I'm only a "community" vote.

review: Needs Fixing
Revision history for this message
Jason Gerard DeRose (jderose) wrote :

Paul,

What would you recommend instead of 's'?

Thanks for the review!

lp:~jderose/filestore/ensuredir updated
185. By Jason Gerard DeRose

Improved variable naming in ensuredir()

Revision history for this message
Jason Gerard DeRose (jderose) wrote :

Better?

review: Needs Resubmitting
Revision history for this message
Paul Hummer (rockstar) wrote :

That looks great to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'filestore.py'
2--- filestore.py 2011-08-24 00:31:50 +0000
3+++ filestore.py 2011-09-07 01:28:23 +0000
4@@ -860,12 +860,13 @@
5 os.mkdir(d)
6 return True
7 except OSError:
8- if not path.isdir(d):
9+ mode = os.lstat(d).st_mode
10+ if stat.S_ISLNK(mode):
11+ raise ValueError(
12+ '{!r} is symlink to {!r}'.format(d, os.readlink(d))
13+ )
14+ if not stat.S_ISDIR(mode):
15 raise ValueError('not a directory: {!r}'.format(d))
16- if path.islink(d):
17- raise ValueError(
18- '{!r} is symlink to {!r}'.format(d, os.readlink(d))
19- )
20 return False
21
22
23
24=== modified file 'test_filestore.py'
25--- test_filestore.py 2011-08-21 18:54:48 +0000
26+++ test_filestore.py 2011-09-07 01:28:23 +0000
27@@ -706,9 +706,12 @@
28
29 # Test that os.makedirs() is not used:
30 d = tmp.join('foo', 'bar')
31- with self.assertRaises(ValueError) as cm:
32+ with self.assertRaises(OSError) as cm:
33 f(d)
34- self.assertEqual(str(cm.exception), 'not a directory: {!r}'.format(d))
35+ self.assertEqual(
36+ str(cm.exception),
37+ '[Errno 2] No such file or directory: {!r}'.format(d)
38+ )
39 self.assertFalse(path.exists(d))
40 self.assertFalse(path.exists(tmp.join('foo')))
41

Subscribers

People subscribed via source and target branches