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