Merge lp:~facundo/ubuntuone-client/lr-file-deletion-564774 into lp:ubuntuone-client

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 500
Merged at revision: not available
Proposed branch: lp:~facundo/ubuntuone-client/lr-file-deletion-564774
Merge into: lp:ubuntuone-client
Diff against target: 71 lines (+39/-6)
2 files modified
tests/syncdaemon/test_localrescan.py (+25/-0)
ubuntuone/syncdaemon/local_rescan.py (+14/-6)
To merge this branch: bzr merge lp:~facundo/ubuntuone-client/lr-file-deletion-564774
Reviewer Review Type Date Requested Status
John O'Brien (community) Approve
Tim Cole (community) Approve
Review via email: mp+23567@code.launchpad.net

Commit message

Don't delete the file in an interrupted download with lost partial.

Description of the change

Don't delete the file in an interrupted download with lost partial.

Test included.

To post a comment you must log in.
Revision history for this message
Tim Cole (tcole) wrote :

Looks like an improvement, I think.

review: Approve
Revision history for this message
John O'Brien (jdobrien) wrote :

Good test. Tests pass in client and integration tests.

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 2010-04-12 19:29:50 +0000
3+++ tests/syncdaemon/test_localrescan.py 2010-04-16 17:23:17 +0000
4@@ -1484,6 +1484,31 @@
5 self.startTest(check)
6 return self.deferred
7
8+ def test_SERVER_no_file(self):
9+ """We just queued the Download, and it was interrupted."""
10+ # create the file in metadata
11+ path = os.path.join(self.share.path, "a")
12+ mdid = self.fsm.create(path, self.share.volume_id, is_dir=False, node_id="uuid")
13+ partial_path = os.path.join(self.fsm.partials_dir,
14+ mdid + ".u1partial." + os.path.basename(path))
15+
16+ # this mimic Sync.get_file
17+ self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
18+ self.fsm.create_partial("uuid", self.share.volume_id)
19+
20+ # now, for some reason, we lose the partial file
21+ os.remove(partial_path)
22+
23+ def check(_):
24+ """arrange the metadata so later server_rescan will do ok"""
25+ self.assertEqual(self.eq.pushed, [])
26+ mdobj = self.fsm.get_by_mdid(mdid)
27+ self.assertFalse(mdobj.info.is_partial)
28+ self.assertEqual(mdobj.server_hash, mdobj.local_hash)
29+
30+ self.startTest(check)
31+ return self.deferred
32+
33 def test_SERVER_file_content(self):
34 """We were downloading the file, but it was interrupted, and changed"""
35 # create the file in metadata
36
37=== modified file 'ubuntuone/syncdaemon/local_rescan.py'
38--- ubuntuone/syncdaemon/local_rescan.py 2010-04-12 19:29:50 +0000
39+++ ubuntuone/syncdaemon/local_rescan.py 2010-04-16 17:23:17 +0000
40@@ -507,17 +507,25 @@
41 else:
42 events.append(('FS_FILE_DELETE', fullname))
43 else:
44- if changed not in ("SERVER", "NONE", "LOCAL"):
45+ if changed == 'SERVER':
46+ # download interruped and partial lost
47+ log_debug("comp yield: file %r not in disk, in SERVER "
48+ "state, without partial!", fullname)
49+ mdobj = self.fsm.get_by_path(fullname)
50+ self.fsm.set_by_mdid(mdobj.mdid,
51+ server_hash=mdobj.local_hash)
52+ self.fsm.remove_partial(mdobj.node_id, mdobj.share_id)
53+ elif changed in ('NONE', 'LOCAL'):
54+ # if it had content somewhen, now is really gone (otherwise
55+ # it was never really created in the disk)
56+ log_info("comp yield: file %r is gone!", fullname)
57+ events.append(('FS_FILE_DELETE', fullname))
58+ else:
59 # bad metadata
60 m = "Bad 'changed': removing MD from file %r"
61 log_debug(m, fullname)
62 self.fsm.delete_metadata(fullname)
63- continue
64
65- # if it had content somewhen, now is gone (otherwise it was
66- # never really created in the disk)
67- log_info("comp yield: file %r is gone!", fullname)
68- events.append(('FS_FILE_DELETE', fullname))
69 return events, to_scan_later
70
71 def _paths_filter(self, shrinfo, dirpath, len_shr_path):

Subscribers

People subscribed via source and target branches