38
38
class FSKey(object):
39
"""This encapsulates the problem of getting the metadata with different
39
"""Encapsulate the problem of getting the metadata with different keys."""
41
40
__slots__ = ('fs', 'keys', 'mdid', '_changes')
43
42
def __init__(self, fs, **keys):
98
96
self._changes.update(kwargs)
101
"""sync the changes back to FSM"""
99
"""Sync the changes back to FSM."""
102
100
if self._changes and self.has_metadata():
103
101
self.fs.set_by_mdid(self.get_mdid(), **self._changes)
104
102
self._changes = {}
150
148
def upload_finished(self, server_hash):
151
"""signal that we have uploaded the file"""
149
"""Signal that we have uploaded the file."""
152
150
mdid = self.get_mdid()
153
151
self.fs.upload_finished(mdid, server_hash)
155
153
def delete_file(self):
156
"""delete the file and metadata"""
154
"""Delete the file and metadata."""
157
155
path = self["path"]
158
156
self.fs.delete_file(path)
160
158
self._changes = {}
162
160
def delete_to_trash(self):
163
"""Move the node to trash"""
161
"""Move the node to trash."""
164
162
self.fs.delete_to_trash(self.get_mdid(), self["parent_id"])
166
164
def remove_from_trash(self, share_id, node_id):
167
"""Remove the node from trash"""
165
"""Remove the node from trash."""
168
166
self.fs.remove_from_trash(share_id, node_id)
170
168
def delete_metadata(self):
171
"""delete the metadata"""
169
"""Delete the metadata."""
172
170
path = self["path"]
173
171
self.fs.delete_metadata(path)
175
173
self._changes = {}
177
175
def move_file(self, new_share_id, new_parent_id, new_name):
178
"""get the stuff we need to move the file."""
176
"""Get the stuff we need to move the file."""
179
177
source_path = self['path']
180
178
parent_path = self.fs.get_by_node_id(new_share_id, new_parent_id).path
181
179
dest_path = os.path.join(
184
182
self.fs.move_file(new_share_id, source_path, dest_path)
186
184
def moved(self, new_share_id, path_to):
187
"""change the metadata of a moved file."""
185
"""Change the metadata of a moved file."""
188
186
self.fs.moved(new_share_id, self['path'], path_to)
189
187
if "path" in self.keys:
190
188
self.keys["path"] = path_to
192
190
def remove_partial(self):
193
"""remove a partial file"""
191
"""Remove a partial file."""
194
192
# pylint: disable-msg=W0704
196
194
self.fs.remove_partial(self["node_id"], self["share_id"])
201
199
def move_to_conflict(self):
202
"""Move file to conflict"""
200
"""Move file to conflict."""
203
201
self.fs.move_to_conflict(self.get_mdid())
205
203
def refresh_stat(self):
206
"""refresh the stat"""
204
"""Refresh the stat."""
207
205
path = self["path"]
208
206
# pylint: disable-msg=W0704
215
213
def safe_get(self, key, default='^_^'):
216
""" safe version of self.get, to be used in the FileLogger. """
214
"""Safe version of self.get, to be used in the FileLogger."""
217
215
# catch all errors as we are here to help logging
218
216
# pylint: disable-msg=W0703
509
507
new_name = os.path.basename(path_to)
510
508
new_parent = FSKey(self.m.fs, path=new_path)
511
509
new_parent_id = new_parent['node_id']
510
share_id = self.key['share_id']
511
node_id = self.key['node_id']
513
self.m.action_q.move(share_id=self.key['share_id'],
514
node_id=self.key['node_id'], old_parent_id=old_parent_id,
515
new_parent_id=new_parent_id, new_name=new_name)
516
self.key.moved(self.key['share_id'], path_to)
513
self.m.action_q.move(share_id, node_id, old_parent_id,
514
new_parent_id, new_name)
515
self.m.fs.add_to_move_limbo(share_id, node_id, old_parent_id,
516
new_parent_id, new_name)
517
self.key.moved(share_id, path_to)
518
519
# we only hash it if we're a file, not a directory
519
520
if not self.key.is_dir():
738
739
"""Remove the node from trash."""
739
740
self.key.remove_from_trash(share_id, node_id)
742
def clean_move_limbo(self, event, params, share_id, node_id):
743
"""Remove the node from move limbo."""
744
self.m.fs.remove_from_move_limbo(share_id, node_id)
741
746
def server_moved(self, event, params, share_id, node_id,
742
747
new_share_id, new_parent_id, new_name):
743
748
"""file was moved on the server"""
1044
1049
key = FSKey(self.m.fs, share_id=share_id, node_id=node_id)
1045
1050
log = FileLogger(self.logger, key)
1046
1051
ssmr = SyncStateMachineRunner(self.fsm, self.m, key, log)
1052
ssmr.on_event("AQ_MOVE_OK", {}, share_id, node_id)
1047
1053
ssmr.update_generation(share_id, node_id, new_generation)
1055
def handle_AQ_MOVE_ERROR(self, share_id, node_id, parent_id, error):
1056
"""On AQ_MOVE_ERROR."""
1057
key = FSKey(self.m.fs, share_id=share_id, node_id=node_id)
1058
log = FileLogger(self.logger, key)
1059
ssmr = SyncStateMachineRunner(self.fsm, self.m, key, log)
1060
ssmr.on_event("AQ_MOVE_ERROR", {}, share_id, node_id)
1049
1062
def handle_AQ_DELTA_OK(self, volume_id, delta_content, end_generation,
1050
1063
full, free_bytes):
1051
1064
"""We got a new delta. Apply item by item of the delta.