Merge lp:~verterok/ubuntuone-client/fix-598189 into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: John O'Brien
Approved revision: 689
Merged at revision: 698
Proposed branch: lp:~verterok/ubuntuone-client/fix-598189
Merge into: lp:ubuntuone-client
Diff against target: 122 lines (+94/-0)
2 files modified
tests/syncdaemon/test_localrescan.py (+72/-0)
ubuntuone/syncdaemon/local_rescan.py (+22/-0)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/fix-598189
Reviewer Review Type Date Requested Status
John O'Brien (community) Approve
Facundo Batista (community) Approve
Review via email: mp+35013@code.launchpad.net

Commit message

Fix Local rescan to process read only shares and resume interrupted downloads.

Description of the change

Local rescan now process read only shares and resume interrupted downloads.

To post a comment you must log in.
Revision history for this message
Facundo Batista (facundo) wrote :

I would use local vars for self.fsm.changed and self.fsm.CHANGED_SERVER instead of accessing self and fsm (twice) inside the double for.

Otherwise, it's ok.

review: Approve
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

good point, fixed and pushed.

689. By Guillermo Gonzalez

avoid dict lookups in the nested for loop

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

Tests say [OK] and I do too.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/syncdaemon/test_localrescan.py'
--- tests/syncdaemon/test_localrescan.py 2010-09-07 19:41:16 +0000
+++ tests/syncdaemon/test_localrescan.py 2010-09-13 16:08:46 +0000
@@ -1894,6 +1894,78 @@
1894 self.startTest(check)1894 self.startTest(check)
1895 return self.deferred1895 return self.deferred
18961896
1897 def test_SERVER_file_ro_share(self):
1898 """We were downloading the file, but it was interrupted in RO share."""
1899 # create the file in metadata
1900 ro_share = self.create_share('share_ro_id', 'share_ro2', self.fsm,
1901 self.shares_dir, access_level='View')
1902 self.fsm.create(ro_share.path, ro_share.id, is_dir=True)
1903 self.fsm.set_node_id(ro_share.path, "uuidshare")
1904 path = os.path.join(ro_share.path, "a")
1905 with self.fsm._enable_share_write(ro_share.id, path):
1906 open(path, "w").close()
1907 mdid = self.fsm.create(path, ro_share.volume_id, is_dir=False)
1908 partial_path = os.path.join(self.fsm.partials_dir,
1909 mdid + ".u1partial." + os.path.basename(path))
1910 self.fsm.set_node_id(path, "uuid")
1911
1912 # start the download, never complete it
1913 self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
1914 self.fsm.create_partial("uuid", ro_share.volume_id)
1915 fh = self.fsm.get_partial_for_writing("uuid", ro_share.volume_id)
1916 fh.write("foobar")
1917 self.assertTrue(os.path.exists(partial_path))
1918
1919 def check(_):
1920 """Compare predictable args, and check fh factory."""
1921 mdobj = self.fsm.get_by_mdid(mdid)
1922 self.assertEqual(self.aq.downloaded[:3], (
1923 mdobj.share_id, mdobj.node_id, mdobj.server_hash))
1924 factory = self.aq.downloaded[-1]
1925 self.assertTrue(isinstance(factory(), file))
1926 self.assertTrue(self.handler.check_debug("comp yield", "SERVER"))
1927
1928 self.startTest(check)
1929 return self.deferred
1930
1931 def test_SERVER_dir_ro_share(self):
1932 """Found a dir in SERVER in a ro_share.
1933
1934 This was valid before, but no more, so we just fix and log in warning.
1935 """
1936 # create the dir in metadata
1937 ro_share = self.create_share('share_ro_id', 'share_ro2', self.fsm,
1938 self.shares_dir, access_level='View')
1939 self.fsm.create(ro_share.path, ro_share.id, is_dir=True)
1940 self.fsm.set_node_id(ro_share.path, "uuidshare")
1941
1942 path = os.path.join(ro_share.path, "a")
1943 mdid = self.fsm.create(path, ro_share.volume_id, is_dir=True)
1944 partial_path = os.path.join(self.fsm.partials_dir,
1945 mdid + ".u1partial." + os.path.basename(path))
1946 self.fsm.set_node_id(path, "uuid")
1947
1948 # start the download, never complete it
1949 self.fsm.set_by_mdid(mdid, server_hash="blah-hash-blah")
1950 self.fsm.create_partial("uuid", ro_share.volume_id)
1951 fh = self.fsm.get_partial_for_writing("uuid", ro_share.volume_id)
1952 fh.write("foobar")
1953 self.assertTrue(os.path.exists(partial_path))
1954
1955 def check(_):
1956 """Several checks."""
1957 mdobj = self.fsm.get_by_mdid(mdid)
1958 # it should be in NONE
1959 self.assertFalse(mdobj.info.is_partial)
1960 self.assertEqual(mdobj.server_hash, mdobj.local_hash)
1961 self.assertFalse(os.path.exists(partial_path))
1962 # logged in warning
1963 self.assertTrue(self.handler.check_warning(
1964 "Found a directory in SERVER"))
1965
1966 self.startTest(check)
1967 return self.deferred
1968
18971969
1898class RootBadStateTests(TwistedBase):1970class RootBadStateTests(TwistedBase):
1899 """Test what happens with volume roots left in a bad state last time."""1971 """Test what happens with volume roots left in a bad state last time."""
19001972
=== modified file 'ubuntuone/syncdaemon/local_rescan.py'
--- ubuntuone/syncdaemon/local_rescan.py 2010-09-07 19:41:16 +0000
+++ ubuntuone/syncdaemon/local_rescan.py 2010-09-13 16:08:46 +0000
@@ -76,6 +76,7 @@
76 # first of all, remove old partials and clean trash76 # first of all, remove old partials and clean trash
77 self._remove_partials()77 self._remove_partials()
78 self._process_limbo()78 self._process_limbo()
79 self._process_ro_shares()
7980
80 yield self._queue_scan()81 yield self._queue_scan()
81 self._show_broken_nodes()82 self._show_broken_nodes()
@@ -129,6 +130,27 @@
129 self.aq.move(share_id, node_id, old_parent_id,130 self.aq.move(share_id, node_id, old_parent_id,
130 new_parent_id, new_name)131 new_parent_id, new_name)
131132
133 def _process_ro_shares(self):
134 """Process ro shares and reschedule interrupted downloads."""
135 # to avoid the lookups in the nested for
136 changed = self.fsm.changed
137 CHANGED_SERVER = self.fsm.CHANGED_SERVER
138 for share in self._get_volumes(all_volumes=False, access_level="View"):
139 for mdobj in self.fsm.get_mdobjs_by_share_id(share.id):
140 if changed(mdid=mdobj.mdid) == CHANGED_SERVER:
141 fullname = os.path.join(share.path, mdobj.path)
142 if mdobj.is_dir:
143 # old state, no sense now with generations
144 # but required for the migration path.
145 log_warning("Found a directory in SERVER: %r", fullname)
146 mdobj = self.fsm.get_by_path(fullname)
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 else:
151 log_debug("comp yield: file %r in SERVER", fullname)
152 self._resume_download(fullname)
153
132 def _show_broken_nodes(self):154 def _show_broken_nodes(self):
133 """Log the broken nodes."""155 """Log the broken nodes."""
134 for mdobj in self.fsm.get_dirty_nodes():156 for mdobj in self.fsm.get_dirty_nodes():

Subscribers

People subscribed via source and target branches