Merge lp:~lool/ubuntuone-client/tritcask-use-platform-api into lp:ubuntuone-client

Proposed by Loïc Minier
Status: Merged
Approved by: dobey
Approved revision: 1400
Merged at revision: 1387
Proposed branch: lp:~lool/ubuntuone-client/tritcask-use-platform-api
Merge into: lp:ubuntuone-client
Diff against target: 262 lines (+52/-26)
7 files modified
ubuntuone/platform/__init__.py (+1/-0)
ubuntuone/platform/os_helper/__init__.py (+1/-0)
ubuntuone/platform/os_helper/darwin.py (+1/-0)
ubuntuone/platform/os_helper/linux.py (+1/-0)
ubuntuone/platform/os_helper/unix.py (+5/-0)
ubuntuone/platform/os_helper/windows.py (+6/-0)
ubuntuone/syncdaemon/tritcask.py (+37/-26)
To merge this branch: bzr merge lp:~lool/ubuntuone-client/tritcask-use-platform-api
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
dobey (community) Approve
Review via email: mp+147581@code.launchpad.net

Commit message

Use platform API for os.path.* functions; fixes LP #1101344.

Description of the change

Use platform API for os.path.* functions; fixes bug #1101344.

To post a comment you must log in.
Revision history for this message
Loïc Minier (lool) wrote :

Pushed some more revisions; sorry, there's some history garbage: r1387 to r1390 were attempts to fix the SetFileSecurity issue:
* it's a deprecated function, so I tried using the new SetNamedSecurityInfo function
* I also tried matching permissions with files on my system which have an ACL entry for sysops too
* I dropped some unused function (_get_group_sid)

but I didn't want these revs to end up in this mp, and I forgot to revert my tree to the right revno before committing the other fixes, so r1391 has these changed reverted.

Let me know if you'd like some of them in another mp, but they don't fix the orginal bug so I'm not adding them here.

Revision history for this message
Loïc Minier (lool) wrote :

I pushed a last rev 1397 which is untested; I was hoping using normpath would fix all issues without having to call into the os_helper API for everything, but it didn't help after all, so I'm reverting the normpath changes.

I didn't actually test tritcask.py after reverting though.

Revision history for this message
dobey (dobey) wrote :

44 +is_dir = unit.is_dir

Typo here.

Have you not done ./autogen.sh && make check in the tree?

Revision history for this message
Loïc Minier (lool) wrote :

Sorry I hadn't (I thought I had noted that, but apparently I forgot)

I've pushed r1398 which fixes this particular issue, and then make check exposed another issue which I've fixed in r1399; this should hopefully be good to merge now. NB: some tests were actually skipped, not sure why:
PASSED (skips=12, successes=2759)

Also didn't run some part of the tests it seems:
ubuntuone.devtools.errors.TestError: The Python package providing the requested reactor is not installed. You can find it here: https://github.com/ghtdak/qtreactor

[ Would you mind adding some advice in HACKING on the packages that one should install? I had to install:
  xutils-dev gobject-introspection python-mocker
to run ./autogen.sh && make check, and I can see that other bits like gnome-common are needed. ]

Revision history for this message
dobey (dobey) wrote :

You can use "apt-get build-dep ubuntuone-client" for the most part. python-qt4reactor is packaged, but not in main, so it's not in the build-depends of ubuntuone-client in the main archive. But adding the nightlies ppa (ppa:ubuntuone/nightlies) and then apt-get update && apt-get build-dep ubuntuone-client will pull everything needed.

Also, can you please do a "bzr commit --fixes=lp:1101344 --unchanged" to link the bug into the branch? Thanks.

Revision history for this message
Loïc Minier (lool) wrote :

Done in r1400.

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Mike McCracken (mikemc) wrote :

looks good. tests pass on darwin.

Thanks Loïc!

review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

There was a problem validating some authors of the branch. Authors must be either one of the listed Launchpad users, or a member of one of the listed teams on Launchpad.

Persons or Teams:

    contributor-agreement-canonical
    ubuntuone-hackers

Unaccepted Authors:

    Loïc Minier <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/platform/__init__.py'
2--- ubuntuone/platform/__init__.py 2012-09-25 22:51:42 +0000
3+++ ubuntuone/platform/__init__.py 2013-02-13 18:06:22 +0000
4@@ -76,6 +76,7 @@
5 allow_writes = os_helper.allow_writes
6 can_write = os_helper.can_write
7 get_path_list = os_helper.get_path_list
8+is_dir = os_helper.is_dir
9 is_link = os_helper.is_link
10 is_root = os_helper.is_root
11 listdir = os_helper.listdir
12
13=== modified file 'ubuntuone/platform/os_helper/__init__.py'
14--- ubuntuone/platform/os_helper/__init__.py 2012-08-07 13:29:42 +0000
15+++ ubuntuone/platform/os_helper/__init__.py 2013-02-13 18:06:22 +0000
16@@ -51,6 +51,7 @@
17 remove_tree = source.remove_tree
18 remove_dir = source.remove_dir
19 path_exists = source.path_exists
20+is_dir = source.is_dir
21 make_dir = source.make_dir
22 open_file = source.open_file
23 rename = source.rename
24
25=== modified file 'ubuntuone/platform/os_helper/darwin.py'
26--- ubuntuone/platform/os_helper/darwin.py 2012-08-01 11:34:37 +0000
27+++ ubuntuone/platform/os_helper/darwin.py 2013-02-13 18:06:22 +0000
28@@ -56,6 +56,7 @@
29 remove_tree = unix.remove_tree
30 remove_dir = unix.remove_dir
31 path_exists = unix.path_exists
32+is_dir = unix.is_dir
33 make_dir = unix.make_dir
34 open_file = unix.open_file
35 rename = unix.rename
36
37=== modified file 'ubuntuone/platform/os_helper/linux.py'
38--- ubuntuone/platform/os_helper/linux.py 2013-01-28 20:17:45 +0000
39+++ ubuntuone/platform/os_helper/linux.py 2013-02-13 18:06:22 +0000
40@@ -101,6 +101,7 @@
41 remove_tree = unix.remove_tree
42 remove_dir = unix.remove_dir
43 path_exists = unix.path_exists
44+is_dir = unix.is_dir
45 make_dir = unix.make_dir
46 open_file = unix.open_file
47 rename = unix.rename
48
49=== modified file 'ubuntuone/platform/os_helper/unix.py'
50--- ubuntuone/platform/os_helper/unix.py 2012-08-07 13:29:42 +0000
51+++ ubuntuone/platform/os_helper/unix.py 2013-02-13 18:06:22 +0000
52@@ -98,6 +98,11 @@
53 return os.path.exists(path)
54
55
56+def is_dir(path):
57+ """Return if the path is an existing directory."""
58+ return os.path.isdir(path)
59+
60+
61 def make_dir(path, recursive=False):
62 """Make a dir, optionally creating all the middle ones."""
63 if recursive:
64
65=== modified file 'ubuntuone/platform/os_helper/windows.py'
66--- ubuntuone/platform/os_helper/windows.py 2012-08-07 13:29:42 +0000
67+++ ubuntuone/platform/os_helper/windows.py 2013-02-13 18:06:22 +0000
68@@ -591,6 +591,12 @@
69
70
71 @windowspath()
72+def is_dir(path):
73+ """Return if the path is an existing directory."""
74+ return os.path.isdir(path)
75+
76+
77+@windowspath()
78 def make_dir(path, recursive=False):
79 """Make a dir, optionally creating all the middle ones."""
80 if recursive:
81
82=== modified file 'ubuntuone/syncdaemon/tritcask.py'
83--- ubuntuone/syncdaemon/tritcask.py 2013-01-25 20:38:01 +0000
84+++ ubuntuone/syncdaemon/tritcask.py 2013-02-13 18:06:22 +0000
85@@ -49,6 +49,17 @@
86 from collections import namedtuple
87 from UserDict import DictMixin
88
89+from ubuntuone.platform import (
90+ is_dir,
91+ listdir,
92+ make_dir,
93+ open_file,
94+ path_exists,
95+ remove_file,
96+ rename,
97+ stat_path,
98+)
99+
100
101 crc32_fmt = '>i'
102 crc32_size = struct.calcsize(crc32_fmt)
103@@ -200,7 +211,7 @@
104
105 @property
106 def size(self):
107- return os.stat(self.filename).st_size
108+ return stat_path(self.filename).st_size
109
110 @classmethod
111 def _get_next_file_id(cls):
112@@ -216,30 +227,30 @@
113 @property
114 def has_hint(self):
115 """Return true if there is a hint file on-disk."""
116- return os.path.exists(self.hint_filename)
117+ return path_exists(self.hint_filename)
118
119 @property
120 def hint_size(self):
121 """Return the hint file size."""
122 if self.has_hint:
123- return os.stat(self.hint_filename).st_size
124+ return stat_path(self.hint_filename).st_size
125 return 0
126
127 def exists(self):
128- return os.path.exists(self.filename)
129+ return path_exists(self.filename)
130
131 def make_immutable(self):
132 """Make this data file immutable."""
133 self.close()
134 new_name = self.filename.replace(LIVE, INACTIVE)
135- os.rename(self.filename, new_name)
136+ rename(self.filename, new_name)
137 return ImmutableDataFile(*os.path.split(new_name))
138
139 def _open(self):
140- if not os.path.exists(self.filename):
141+ if not path_exists(self.filename):
142 # create the file and open it for append
143- open(self.filename, 'wb').close()
144- self.fd = open(self.filename, 'a+b')
145+ open_file(self.filename, 'wb').close()
146+ self.fd = open_file(self.filename, 'a+b')
147
148 def close(self):
149 """Close the file descriptor"""
150@@ -361,16 +372,16 @@
151 new_name = self.filename.replace(INACTIVE, DEAD)
152 new_hint_name = self.hint_filename.replace(INACTIVE, DEAD)
153 self.close()
154- os.rename(self.filename, new_name)
155+ rename(self.filename, new_name)
156 self.filename = new_name
157 if self.has_hint:
158- os.rename(self.hint_filename, new_hint_name)
159+ rename(self.hint_filename, new_hint_name)
160 self.hint_filename = new_hint_name
161 self._open()
162 return self
163
164 def _open(self):
165- self.fd = open(self.filename, 'rb')
166+ self.fd = open_file(self.filename, 'rb')
167 fmmap = mmap.mmap(self.fd.fileno(), 0, access=mmap.ACCESS_READ)
168 self.fmmap = fmmap
169
170@@ -410,9 +421,9 @@
171
172 def delete(self):
173 """Delete this file and the hint if exists."""
174- os.unlink(self.filename)
175+ remove_file(self.filename)
176 if self.has_hint:
177- os.unlink(self.hint_filename)
178+ remove_file(self.hint_filename)
179
180 # make all inherited methods to fail
181 def _not_implemented(self, *args, **kwargs):
182@@ -436,19 +447,19 @@
183 """Make this data file immutable."""
184 self.close()
185 new_name = self.filename.replace(self.temp_name, INACTIVE)
186- os.rename(self.filename, new_name)
187+ rename(self.filename, new_name)
188 if self.has_hint:
189 new_hint_name = self.hint_filename.replace(self.temp_name,
190 INACTIVE)
191- os.rename(self.hint_filename, new_hint_name)
192+ rename(self.hint_filename, new_hint_name)
193 return ImmutableDataFile(*os.path.split(new_name))
194
195 def delete(self):
196 """Delete this file and the hint if exists."""
197 self.close()
198- os.unlink(self.filename)
199+ remove_file(self.filename)
200 if self.has_hint:
201- os.unlink(self.hint_filename)
202+ remove_file(self.hint_filename)
203
204
205 class HintFile(object):
206@@ -458,13 +469,13 @@
207 """Create the instance."""
208 self.path = path
209 self.tempfile = None
210- if os.path.exists(self.path) and os.stat(self.path).st_size > 0:
211+ if path_exists(self.path) and stat_path(self.path).st_size > 0:
212 # if it's there and size > 0, open only for read
213- self.fd = open(self.path, 'rb')
214+ self.fd = open_file(self.path, 'rb')
215 else:
216 # this is a new hint file, lets create it as a tempfile.
217 self.tempfile = tempfile.mktemp(dir=os.path.dirname(self.path))
218- self.fd = open(self.tempfile, 'w+b')
219+ self.fd = open_file(self.tempfile, 'w+b')
220
221 def iter_entries(self):
222 """Return a generator over the hint entries."""
223@@ -508,7 +519,7 @@
224 self.fd.close()
225 # if this is a new hint file, rename it to the real path.
226 if self.tempfile:
227- os.rename(self.tempfile, self.path)
228+ rename(self.tempfile, self.path)
229
230
231 class Keydir(dict):
232@@ -627,9 +638,9 @@
233 self.dead_bytes_threshold = dead_bytes_threshold
234 self.max_immutable_files = max_immutable_files
235 self.auto_merge = auto_merge
236- if not os.path.exists(self.base_path):
237- os.makedirs(self.base_path)
238- elif not os.path.isdir(self.base_path):
239+ if not path_exists(self.base_path):
240+ make_dir(self.base_path, recursive=True)
241+ elif not is_dir(self.base_path):
242 raise ValueError('path must be a directory.')
243 self.live_file = None
244 self._immutable = {}
245@@ -719,7 +730,7 @@
246 base_path = self.base_path
247 if not base_path.endswith(os.path.sep):
248 base_path += os.path.sep
249- files = os.listdir(self.base_path)
250+ files = listdir(self.base_path)
251 for filename in files:
252 # first check for hint and dead
253 if is_hint(filename):
254@@ -748,7 +759,7 @@
255 logger.warning("Failed to open %s, renaming it to: %s - "
256 "error: %s", orig, dest, e)
257 # rename it to "broken"
258- os.rename(orig, dest)
259+ rename(orig, dest)
260 # immutable files + live
261 logger.info("found %s data files, %s dead and %s broken files",
262 len(self._immutable) + 1, dead_files, broken_files)

Subscribers

People subscribed via source and target branches