Merge lp:~verterok/ubuntuone-client/dont-delete-child-partials into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Elliot Murphy
Approved revision: 274
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/dont-delete-child-partials
Merge into: lp:ubuntuone-client
Diff against target: 180 lines
2 files modified
tests/syncdaemon/test_localrescan.py (+54/-4)
ubuntuone/syncdaemon/local_rescan.py (+12/-10)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/dont-delete-child-partials
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Review via email: mp+14144@code.launchpad.net

Commit message

Check if the file ever existed (facundo's patch), fix partial parent path comparsion and remove extra check_stat.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Check if the file ever existed (facundo's patch) and fix partial parent path comparsion and remove extra check_stat as we don't have 0 bytes files anymore

Revision history for this message
Elliot Murphy (statik) wrote :

It definitely works, was reviewed by facundo and lucio, and tested by kenvandine and joshuahoover.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_localrescan.py'
2--- tests/syncdaemon/test_localrescan.py 2009-10-29 01:12:56 +0000
3+++ tests/syncdaemon/test_localrescan.py 2009-10-29 07:50:23 +0000
4@@ -1136,7 +1136,7 @@
5 mdid + ".u1partial." + os.path.basename(path))
6 self.fsm.set_node_id(path, "uuid")
7
8- # start the download, never complet it
9+ # start the download, never complete it
10 self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
11 self.fsm.create_partial("uuid", self.share.id)
12 fh = self.fsm.get_partial_for_writing("uuid", self.share.id)
13@@ -1162,7 +1162,7 @@
14 mdid + ".u1partial." + os.path.basename(path))
15 self.fsm.set_node_id(path, "uuid")
16
17- # start the download, never complet it
18+ # start the download, never complete it
19 self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
20 self.fsm.create_partial("uuid", self.share.id)
21 fh = self.fsm.get_partial_for_writing("uuid", self.share.id)
22@@ -1193,7 +1193,7 @@
23 mdid + ".u1partial." + os.path.basename(path))
24 self.fsm.set_node_id(path, "uuid")
25
26- # start the download, never complet it
27+ # start the download, never complete it
28 self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
29 self.fsm.create_partial("uuid", self.share.id)
30 fh = self.fsm.get_partial_for_writing("uuid", self.share.id)
31@@ -1263,7 +1263,7 @@
32 mdid = self.fsm.create(path, self.share.id, is_dir=True)
33 self.fsm.set_node_id(path, "uuid")
34
35- # start the download, never complet it
36+ # start the download, never complete it
37 self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
38 self.fsm.create_partial("uuid", self.share.id)
39 fh = self.fsm.get_partial_for_writing("uuid", self.share.id)
40@@ -1442,6 +1442,56 @@
41 self.startTest(check)
42 return self.deferred
43
44+ def test_remove_only_partial_of_childs(self):
45+ '''We were downloading the file, but it was interrupted.
46+ and we have a partial of another fiel in a subdir.'''
47+ # create the file in metadata
48+ path = os.path.join(self.share.path, "a")
49+ mdid = self.fsm.create(path, self.share.id, is_dir=False)
50+ partial_path = os.path.join(self.fsm.partials_dir,
51+ mdid + ".u1partial." + os.path.basename(path))
52+ self.fsm.set_node_id(path, "uuid")
53+
54+ # start the download, never complete it
55+ self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
56+ self.fsm.create_partial("uuid", self.share.id)
57+ fh = self.fsm.get_partial_for_writing("uuid", self.share.id)
58+ fh.write("foobar")
59+ self.assertTrue(os.path.exists(partial_path))
60+
61+ # create another file with a partial, but one level deeper
62+ dir = os.path.join(self.share.path, "dir")
63+ os.mkdir(dir)
64+ path_b = os.path.join(self.share.path, "dir", "b")
65+ open(path_b, "w").close()
66+ mdid_dir = self.fsm.create(dir, self.share.id, is_dir=True)
67+ self.fsm.set_node_id(dir, "uuid2")
68+
69+ mdid_b = self.fsm.create(path_b, self.share.id, is_dir=False)
70+ partial_path_b = os.path.join(self.fsm.partials_dir,
71+ mdid_b + ".u1partial." + os.path.basename(path_b))
72+ self.fsm.set_node_id(path_b, "uuid1")
73+
74+
75+ # start the download, never complete it
76+ self.fsm.set_by_mdid(mdid_b, server_hash="blah-hash-blah-b")
77+ self.fsm.create_partial("uuid1", self.share.id)
78+ fh = self.fsm.get_partial_for_writing("uuid1", self.share.id)
79+ fh.write("foobar")
80+ self.assertTrue(os.path.exists(partial_path_b))
81+
82+ def check(_):
83+ '''arrange the metadata so later server_rescan will do ok'''
84+ mdobj = self.fsm.get_by_mdid(mdid)
85+ self.assertFalse(mdobj.info.is_partial)
86+ self.assertEqual(mdobj.server_hash, mdobj.local_hash)
87+ self.assertFalse(os.path.exists(partial_path))
88+ self.assertFalse(os.path.exists(partial_path_b))
89+ self.assertTrue(os.path.exists(path_b))
90+
91+ self.startTest(check)
92+ return self.deferred
93+
94
95 class TrashTests(TwistedBase):
96 '''Test handling trash.'''
97
98=== modified file 'ubuntuone/syncdaemon/local_rescan.py'
99--- ubuntuone/syncdaemon/local_rescan.py 2009-10-29 01:12:56 +0000
100+++ ubuntuone/syncdaemon/local_rescan.py 2009-10-29 07:50:23 +0000
101@@ -244,7 +244,7 @@
102 for dname in dirnames:
103 fullname = os.path.join(dirpath, dname)
104 if dname in shouldbe:
105- is_dir, statinfo, changed = shouldbe.pop(dname)
106+ is_dir, statinfo, changed, _ = shouldbe.pop(dname)
107 if not is_dir:
108 # it's there, but it's a file!
109 log_debug("comp yield: file %r became a dir!", fullname)
110@@ -277,7 +277,7 @@
111 for fname in filenames:
112 fullname = os.path.join(dirpath, fname)
113 if fname in shouldbe:
114- is_dir, statinfo, changed = shouldbe.pop(fname)
115+ is_dir, statinfo, changed, _ = shouldbe.pop(fname)
116 if is_dir:
117 log_debug("comp yield: dir %r became a file!", fullname)
118 # it's there, but it's a directory!
119@@ -327,7 +327,7 @@
120 os.remove(fullname)
121 continue
122
123- is_dir, statinfo, changed = shouldbe.pop(realname)
124+ is_dir, statinfo, changed, _ = shouldbe.pop(realname)
125 if is_dir:
126 m = ".partial of a file that MD says it's a dir: %r"
127 despair(m, realfullname, also_remove=fullname)
128@@ -382,7 +382,7 @@
129 else:
130 realfullname = self.fsm.get_abspath(mdobj.share_id, mdobj.path)
131
132- if not realfullname.startswith(dirpath):
133+ if os.path.dirname(realfullname) != dirpath:
134 # if this partial isn't for the current dirpath, ignore it!
135 continue
136 if realfullname == dirpath:
137@@ -394,7 +394,7 @@
138 despair(m, realfullname, also_remove=partial_path)
139 continue
140
141- is_dir, statinfo, changed = shouldbe.pop(realname)
142+ is_dir, statinfo, changed, _ = shouldbe.pop(realname)
143 if is_dir:
144 m = ".partial of a file that MD says it's a dir: %r"
145 despair(m, realfullname, also_remove=partial_path)
146@@ -408,10 +408,9 @@
147 self.fsm.set_by_mdid(mdobj.mdid,
148 server_hash=mdobj.local_hash)
149 self.fsm.remove_partial(mdobj.node_id, mdobj.share_id)
150- check_stat(realfullname, statinfo)
151
152 # all these don't exist anymore
153- for name, (is_dir, statinfo, changed) in shouldbe.iteritems():
154+ for name, (is_dir, statinfo, changed, lhash) in shouldbe.iteritems():
155 fullname = os.path.join(dirpath, name)
156 if is_dir:
157 if changed not in ("SERVER", "NONE"):
158@@ -453,8 +452,11 @@
159 self.fsm.delete_metadata(fullname)
160 continue
161
162- log_debug("comp yield: file %r is gone!", fullname)
163- events.append(('FS_FILE_DELETE', fullname))
164+ # if it had content somewhen, now is gone (otherwise it was
165+ # never really created in the disk)
166+ if lhash:
167+ log_debug("comp yield: file %r is gone!", fullname)
168+ events.append(('FS_FILE_DELETE', fullname))
169 return events, to_scan_later
170
171 def _paths_filter(self, shrinfo, dirpath, len_shr_path):
172@@ -489,7 +491,7 @@
173 self.fsm.set_by_path(parent, server_hash="", local_hash="")
174
175 else:
176- filesdirs[fname] = is_dir, statinfo, changed
177+ filesdirs[fname] = is_dir, statinfo, changed, lhash
178 return filesdirs
179
180 def _scan_one_dir(self, scan_info):

Subscribers

People subscribed via source and target branches