Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions client/client_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,9 @@ def __init__(self, snapshot_file_path):
self.last_status = self._load_status()
self.local_full_snapshot = self.instant_snapshot()

#flag enabled only when there is a conflict in sinchronize. enable inhibit of some check
self.conflicted_sync = False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aggiungi un commento qui....


def local_check(self):
""" check id daemon is synchronized with local directory """
local_global_snapshot = self.global_md5()
Expand Down Expand Up @@ -870,8 +873,11 @@ def save_snapshot(self, timestamp):

def update_snapshot_upload(self, body):
""" update of local full snapshot by upload request"""
self.local_full_snapshot[self.file_snapMd5(
body['src_path'])] = [get_relpath(body["src_path"])]
md5_file = self.file_snapMd5(body['src_path'])
if md5_file in self.local_full_snapshot:
self.local_full_snapshot[md5_file].append(get_relpath(body["src_path"]))
else:
self.local_full_snapshot[md5_file] = [get_relpath(body["src_path"])]

def update_snapshot_update(self, body):
""" update of local full snapshot by update request"""
Expand All @@ -889,24 +895,36 @@ def update_snapshot_update(self, body):

def update_snapshot_copy(self, body):
""" update of local full snapshot by copy request"""
self.local_full_snapshot[self.file_snapMd5(
body['src_path'])].append(get_relpath(body["dst_path"]))
md5_file = self.file_snapMd5(body['src_path'])
paths_of_file = self.local_full_snapshot[md5_file]
paths_of_file.append(get_relpath(body["dst_path"]))

def update_snapshot_move(self, body):
""" update of local full snapshot by move request"""
paths_of_file = self.local_full_snapshot[self.file_snapMd5(
get_abspath(body["dst_path"]))]
paths_of_file.remove(get_relpath(body["src_path"]))
md5_file = self.file_snapMd5(get_abspath(body["dst_path"]))
paths_of_file = self.local_full_snapshot[md5_file]
try:
paths_of_file.remove(get_relpath(body["src_path"]))
except ValueError:
#if it is in internal conflict check sinchronize the error is inhibit
if not self.conflicted_sync:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... e qui :)

raise
paths_of_file.append(get_relpath(body["dst_path"]))

def update_snapshot_delete(self, body):
""" update of local full snapshot by delete request"""
md5_file = self.find_file_md5(self.local_full_snapshot, get_relpath(body['src_path']), False)
logger.debug("find md5: {}".format(md5_file))
if len(self.local_full_snapshot[md5_file]) == 1:
del self.local_full_snapshot[md5_file]
else:
self.local_full_snapshot[md5_file].remove(get_relpath(body['src_path']))
if md5_file in self.local_full_snapshot:
try:
self.local_full_snapshot[md5_file].remove(
get_relpath(body['src_path']))
except ValueError:
#if it is in internal conflict check sinchronize the error is inhibit
if not self.conflicted_sync:
raise
if len(self.local_full_snapshot[md5_file]) == 0:
del self.local_full_snapshot[md5_file]
logger.debug("path deleted: " + get_relpath(body['src_path']))

def save_timestamp(self, timestamp):
Expand Down Expand Up @@ -959,6 +977,7 @@ def synchronize_dispatcher(self, server_timestamp, server_snapshot):
command_list = []
#NO internal conflict
if self.local_check(): # 1)
self.conflicted_sync = False
if not self.is_syncro(server_timestamp): # 1) b.
for new_server_path in new_server_paths: # 1) b 1
server_md5 = self.find_file_md5(server_snapshot, new_server_path)
Expand Down Expand Up @@ -987,6 +1006,7 @@ def synchronize_dispatcher(self, server_timestamp, server_snapshot):

#internal conflicts
else: # 2)
self.conflicted_sync = True
if self.is_syncro(server_timestamp): # 2) a
logger.debug("****\tpush all\t****")
for new_server_path in new_server_paths: # 2) a 1
Expand Down Expand Up @@ -1036,6 +1056,7 @@ def synchronize_dispatcher(self, server_timestamp, server_snapshot):
for new_client_path in new_client_paths: # 2) b 3
logger.debug("remove remote\t{}".format(new_client_path))
command_list.append({'remote_delete': [new_client_path]})
self.conflicted_sync = False

return command_list

Expand Down