Merge lp:~verterok/ubuntuone-client/fix-692496-stable-1-4 into lp:ubuntuone-client/stable-1-4

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: dobey
Approved revision: 743
Merged at revision: 745
Proposed branch: lp:~verterok/ubuntuone-client/fix-692496-stable-1-4
Merge into: lp:ubuntuone-client/stable-1-4
Diff against target: 136 lines (+21/-40)
5 files modified
tests/syncdaemon/test_fsm.py (+9/-21)
tests/syncdaemon/test_localrescan.py (+10/-1)
ubuntuone/syncdaemon/filesystem_manager.py (+0/-8)
ubuntuone/syncdaemon/local_rescan.py (+2/-0)
ubuntuone/syncdaemon/sync.py (+0/-10)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/fix-692496-stable-1-4
Reviewer Review Type Date Requested Status
dobey (community) Approve
Facundo Batista (community) Approve
Review via email: mp+44273@code.launchpad.net

Commit message

Fix local rescan to handle the case of the stat in metadata being None.

Description of the change

This branch fix local rescan to handle the case of the stat in metadata being None, also remove the unused refresh_stat methods from fsm and sync.

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

+1

review: Approve
Revision history for this message
dobey (dobey) :
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_fsm.py'
2--- tests/syncdaemon/test_fsm.py 2010-10-25 19:51:17 +0000
3+++ tests/syncdaemon/test_fsm.py 2010-12-20 20:08:44 +0000
4@@ -121,6 +121,13 @@
5 mdobj = self.fsm.get_by_mdid(mdid)
6 return mdobj
7
8+ def refresh_stat(self, fsm, path):
9+ """Refresh the stat of a md object."""
10+ mdid = fsm._idx_path[path]
11+ mdobj = fsm.fs[mdid]
12+ mdobj["stat"] = os.lstat(path)
13+ fsm.fs[mdid] = mdobj
14+
15
16 class StartupTests(unittest.TestCase):
17 """Test the basic startup behaviour."""
18@@ -888,8 +895,8 @@
19 fsm.set_node_id(path2, "uuid2")
20 self.assertTrue(os.path.exists(fsm.fs.key_file(mdid1+'.old')))
21 self.assertTrue(os.path.exists(fsm.fs.key_file(mdid2+'.old')))
22- fsm.refresh_stat(path1)
23- fsm.refresh_stat(path2)
24+ self.refresh_stat(fsm, path1)
25+ self.refresh_stat(fsm, path2)
26 self.assertTrue(os.path.exists(self.fsm.fs.key_file(mdid1+'.old')))
27 self.assertTrue(os.path.exists(self.fsm.fs.key_file(mdid2+'.old')))
28 # break the second node on purpose but with an invalid pickle
29@@ -1391,25 +1398,6 @@
30 mdobj = self.create_node("thisdir")
31 self.assertEqual(mdobj.stat, os.stat(path))
32
33- def test_refresh(self):
34- """Test that refresh_stat works."""
35- path = os.path.join(self.share.path, "thisfile")
36- open(path, "w").close()
37- mdobj = self.create_node("thisfile")
38- mdid = mdobj.mdid
39- oldstat = os.stat(path)
40- self.assertEqual(mdobj.stat, oldstat)
41-
42- # touch the file, it's not automagically updated
43- open(path, "w").close()
44- mdobj = self.fsm.get_by_mdid(mdid)
45- self.assertEqual(mdobj.stat, oldstat)
46-
47- # it's updated when asked
48- self.fsm.refresh_stat(path)
49- mdobj = self.fsm.get_by_mdid(mdid)
50- self.assertEqual(mdobj.stat, os.stat(path))
51-
52 def test_commit_partial(self):
53 """Test that it's updated in the commit."""
54 path = os.path.join(self.share.path, "thisfile")
55
56=== modified file 'tests/syncdaemon/test_localrescan.py'
57--- tests/syncdaemon/test_localrescan.py 2010-09-16 14:09:12 +0000
58+++ tests/syncdaemon/test_localrescan.py 2010-12-20 20:08:44 +0000
59@@ -1586,7 +1586,9 @@
60 # start a put file, and assume we got interrupted (no server hash)
61 pathhash = self._hash(path)
62 self.fsm.set_by_mdid(mdid, local_hash=pathhash, crc32='foo')
63- self.fsm.refresh_stat(path)
64+ mdobj = self.fsm.fs[mdid]
65+ mdobj["stat"] = os.lstat(path)
66+ self.fsm.fs[mdid] = mdobj
67
68 def check(_):
69 """Compare predictable args, and check fh factory."""
70@@ -2070,6 +2072,13 @@
71 self.startTest(check)
72 return self.deferred
73
74+ def test_check_stat_None(self):
75+ """Test check_stat with oldstat = None."""
76+ # create the file in metadata
77+ path = os.path.join(self.share.path, "a_file")
78+ self.fsm.create(path, self.share.volume_id, is_dir=False)
79+ self.assertTrue(self.lr.check_stat(path, None))
80+
81
82 class RootBadStateTests(TwistedBase):
83 """Test what happens with volume roots left in a bad state last time."""
84
85=== modified file 'ubuntuone/syncdaemon/filesystem_manager.py'
86--- ubuntuone/syncdaemon/filesystem_manager.py 2010-10-25 19:51:17 +0000
87+++ ubuntuone/syncdaemon/filesystem_manager.py 2010-12-20 20:08:44 +0000
88@@ -642,14 +642,6 @@
89 mdid = self._idx_node_id[(share_id, node_id)]
90 self.set_by_mdid(mdid, **kwargs)
91
92- def refresh_stat(self, path):
93- """Refresh the stat of a md object."""
94- log_debug("refresh stat to path=%r", path)
95- mdid = self._idx_path[path]
96- mdobj = self.fs[mdid]
97- mdobj["stat"] = get_stat(path)
98- self.fs[mdid] = mdobj
99-
100 def move_file(self, new_share_id, path_from, path_to):
101 """Move a file/dir from one point to the other."""
102 path_from = os.path.normpath(path_from)
103
104=== modified file 'ubuntuone/syncdaemon/local_rescan.py'
105--- ubuntuone/syncdaemon/local_rescan.py 2010-09-16 14:09:12 +0000
106+++ ubuntuone/syncdaemon/local_rescan.py 2010-12-20 20:08:44 +0000
107@@ -359,6 +359,8 @@
108 - st_size: it changed in size, surely different content
109 - st_mtime: the content could be different even having the same size
110 """
111+ if oldstat is None:
112+ return True
113 newstat = os.stat(fullname)
114 different = (newstat.st_ino != oldstat.st_ino or
115 newstat.st_size != oldstat.st_size or
116
117=== modified file 'ubuntuone/syncdaemon/sync.py'
118--- ubuntuone/syncdaemon/sync.py 2010-11-09 12:50:57 +0000
119+++ ubuntuone/syncdaemon/sync.py 2010-12-20 20:08:44 +0000
120@@ -200,16 +200,6 @@
121 """Move file to conflict."""
122 self.fs.move_to_conflict(self.get_mdid())
123
124- def refresh_stat(self):
125- """Refresh the stat."""
126- path = self["path"]
127- # pylint: disable-msg=W0704
128- try:
129- self.fs.refresh_stat(path)
130- except OSError:
131- # no file to stat, nothing to do
132- pass
133-
134 def safe_get(self, key, default='^_^'):
135 """Safe version of self.get, to be used in the FileLogger."""
136 # catch all errors as we are here to help logging

Subscribers

People subscribed via source and target branches