31
32
from ubuntuone.syncdaemon import file_shelf
32
33
from ubuntuone.syncdaemon.volume_manager import VolumeDoesNotExist
34
from ubuntuone.syncdaemon.interfaces import IMarker
35
from ubuntuone.syncdaemon.marker import MDMarker
35
37
METADATA_VERSION = "5"
175
177
class TrashFileShelf(file_shelf.CachedFileShelf):
176
178
"""Custom file shelf that supports share and node as keys."""
180
_marker_flag = 'marker'
181
_marker_len = len(_marker_flag)
178
183
def key_file(self, key):
179
"""Supports share and node as keys."""
184
"""Support share and node as keys."""
180
185
share_id, node_id = key
187
# convert the markers to a string that flags them
188
if IMarker.providedBy(share_id):
189
share_id = str(share_id) + self._marker_flag
190
if IMarker.providedBy(node_id):
191
node_id = str(node_id) + self._marker_flag
182
193
# build a string with the node_id first to have a more sparse
184
195
key = "%s|%s" % (node_id, share_id)
185
196
return super(TrashFileShelf, self).key_file(key)
188
"""Restores the share/node pair"""
199
"""Restore the share/node pair"""
189
200
for key in super(TrashFileShelf, self).keys():
190
201
node_id, share_id = key.split("|")
202
if node_id == 'None':
204
elif node_id.endswith(self._marker_flag):
205
node_id = MDMarker(node_id[:-self._marker_len])
206
if share_id.endswith(self._marker_flag):
207
share_id = MDMarker(share_id[:-self._marker_len])
191
208
yield (share_id, node_id)
217
234
fsmdir = os.path.join(data_dir, 'fsm')
218
235
trashdir = os.path.join(data_dir, 'trash')
236
movelimbodir = os.path.join(data_dir, 'move_limbo')
219
237
self.partials_dir = partials_dir
220
238
if not os.path.exists(self.partials_dir):
221
239
os.makedirs(self.partials_dir)
226
244
cache_compact_threshold=4)
227
245
self.trash = TrashFileShelf(trashdir, cache_size=100,
228
246
cache_compact_threshold=4)
247
self.move_limbo = TrashFileShelf(movelimbodir, cache_size=100,
248
cache_compact_threshold=4)
231
251
self.eq = None # this will be registered later
1159
1179
if v.get('dirty'):
1160
1180
yield _MDObject(**v)
1182
def add_to_move_limbo(self, share_id, node_id, old_parent_id,
1183
new_parent_id, new_name):
1184
"""Add the operation info to the move limbo."""
1185
log_debug("add to move limbo: share=%r, node=%r, old_parent=%r, "
1186
"new_parent=%r, new_name=%r", share_id, node_id,
1187
old_parent_id, new_parent_id, new_name)
1188
self.move_limbo[(share_id, node_id)] = (old_parent_id,
1189
new_parent_id, new_name)
1191
def remove_from_move_limbo(self, share_id, node_id):
1192
"""Remove the node from the move limbo."""
1193
log_debug("remove from move limbo: share=%r, node=%r",
1195
if (share_id, node_id) in self.move_limbo:
1196
del self.move_limbo[(share_id, node_id)]
1198
def get_iter_move_limbo(self):
1199
"""Return the move limbo node by node."""
1200
for k, v in self.move_limbo.iteritems():
1201
share_id, node_id = k
1202
old_parent_id, new_parent_id, new_name = v
1203
yield share_id, node_id, old_parent_id, new_parent_id, new_name
1163
1206
class EnableShareWrite(object):
1164
1207
""" Context manager to allow write in ro-shares. """