sync_manager

This commit is contained in:
Amber 2024-10-29 16:58:03 +01:00
parent 39038c826c
commit 957a1fd9b8

View File

@ -292,54 +292,54 @@ class Manager():
return agent.copy_dir(absolute_local_path, remote_mount_point)
#maybe useless
def precheck_remote_unode(self, node):
'''
Check the unmerged node on remote before solve conflict
Consideration about unode:
1. We have generated `cur_hash` starting from `last_hash` version of node on local tree
2. We are aware on remote the hash is changed at the moment we `sync`, the value is stored in `remote_hash`
we expect
`remote_hash` is unchanged, then we can proceed with solving the conflict
`remote_hash` is changed, then we can generate a new conflict with `remote_hash` equals to the new remote hash
'''
rstatus = self.get_rnode_status(node)
rfile_buf, rhash, rexists = map(rstatus.get, ['iobuffer', 'hash', 'exists'])
remote_hash = node['remote_hash']
if not (remote_hash == rhash):
unmerged = self.load_unmerged_diff()
name = node['name']
path = node['rel_path']
unmerged = self.load_unmerged_diff()
found = {}
for n, unode in enumerate(unmerged):
if unode['name'] == name and unode['rel_path'] == path:
found = unode
break
else:
n = -1
if n == -1:
raise Exception('No node conflicting found!!')
print(f'remote hash changed you...generate a new conflict')
## update the conflicting node by index
# (cur_hash, cur_buf) = _genlocal.generate_file_hash(self.get_absolute_local_path(found))
found['cur_hash'] = cur_hash
found['last_hash'] = found['remote_hash']
found['remote_hash'] = rhash
found['remote_file_buf'] = rfile_buf
self.store_unmerged_diff(unmerged)
## store diff in diffs path
self.store_fdiff(found)
return False, 'Generate conflict'
return True, 'You can proceed'
# def precheck_remote_unode(self, node):
# '''
# Check the unmerged node on remote before solve conflict
# Consideration about unode:
# 1. We have generated `cur_hash` starting from `last_hash` version of node on local tree
# 2. We are aware on remote the hash is changed at the moment we `sync`, the value is stored in `remote_hash`
#
# we expect
# `remote_hash` is unchanged, then we can proceed with solving the conflict
# `remote_hash` is changed, then we can generate a new conflict with `remote_hash` equals to the new remote hash
#
# '''
# rstatus = self.get_rnode_status(node)
# rfile_buf, rhash, rexists = map(rstatus.get, ['iobuffer', 'hash', 'exists'])
#
# remote_hash = node['remote_hash']
#
# if not (remote_hash == rhash):
# unmerged = self.load_unmerged_diff()
# name = node['name']
# path = node['rel_path']
#
# unmerged = self.load_unmerged_diff()
#
# found = {}
# for n, unode in enumerate(unmerged):
# if unode['name'] == name and unode['rel_path'] == path:
# found = unode
# break
# else:
# n = -1
#
# if n == -1:
# raise Exception('No node conflicting found!!')
#
# print(f'remote hash changed you...generate a new conflict')
# ## update the conflicting node by index
# # (cur_hash, cur_buf) = _genlocal.generate_file_hash(self.get_absolute_local_path(found))
# found['cur_hash'] = cur_hash
# found['last_hash'] = found['remote_hash']
# found['remote_hash'] = rhash
# found['remote_file_buf'] = rfile_buf
# self.store_unmerged_diff(unmerged)
# ## store diff in diffs path
# self.store_fdiff(found)
# return False, 'Generate conflict'
#
# return True, 'You can proceed'
@ -392,33 +392,32 @@ class Manager():
# raise Exception
pass
def check_for_conflict(self, node, onlyprint=False):
def check_remote_for_conflict(self, node):
'''
i receive a node i'll check on remote the hash
for verify if equal to `last_hash` and eventually i generate a conflict
i return if there is a conflict and the unmerged node
'''
conflicting = False
rstatus = self.get_rnode_status(node)
rfile_buf, rhash, rexists = map(rstatus.get, ['iobuffer', 'hash', 'exists'])
print(f'Remote status file exists {rexists}, {rhash}')
remote_hash = node['remote_hash']
if rhash == remote_hash:
return conflicting
return conflicting, {}
conflicting = True
unode = node.copy()
# (cur_hash, cur_buf) = _genlocal.generate_file_hash(self.get_absolute_local_path(node))
# node['cur_hash'] = cur_hash
# node['last_hash'] = found['remote_hash']
node['remote_hash'] = rhash
node['remote_file_buf'] = rfile_buf
if onlyprint:
return conflicting
self.store_unmerged_diff(unmerged)
## store diff in diffs path
self.store_fdiff(found)
return conflicting
unode['last_hash'] = node['remote_hash']
unode['remote_hash'] = rhash
unode['remote_file_buf'] = rfile_buf
return conflicting, unode
def mark_conflicting_node_as_solved(self, node):
name = node['name']
@ -441,21 +440,16 @@ class Manager():
## if you mark the node as conflict solved
## you have incorporated the `remote_hash`
## you must verify this is the actual hash in the server side
rstatus = self.get_rnode_status(node)
rfile_buf, rhash, rexists = map(rstatus.get, ['iobuffer', 'hash', 'exists'])
if not (remote_hash == rhash):
conflicting, unode = self.check_remote_for_conflict(node)
if conflicting:
print(f'remote hash changed you...generate a new conflict')
## update the conflicting node by index
(cur_hash, cur_buf) = _genlocal.generate_file_hash(self.get_absolute_local_path(found))
found['cur_hash'] = cur_hash
found['last_hash'] = found['remote_hash']
found['remote_hash'] = rhash
found['remote_file_buf'] = rfile_buf
unmerged[n] = unode
self.store_unmerged_diff(unmerged)
## store diff in diffs path
self.store_fdiff(found)
self.store_fdiff(unode)
return
## found the node in unmerged path
# unmerged_local_path = self.get_unmerged_local_path(node)
# absolute_remote_path = self.get_absolute_remote_path(node)