testing, add folder

This commit is contained in:
Amber 2024-11-05 10:09:46 +01:00
parent d37d577289
commit fb9200469e
2 changed files with 48 additions and 2 deletions

View File

@ -198,6 +198,10 @@ class Manager():
return self.agent
def get_local_snap_diff(self):
'''
`last_tree` is the last tree saved
in file system after last sync
'''
last_tree = self.load_local_hash()
current_tree = self.compute_local_hash()
local_snap_diff = snap.diff_snap(last_tree, current_tree)
@ -247,7 +251,10 @@ class Manager():
for node in nodes:
if node['cur_type'] == 'f':
n = self.store_fdiff(node)
if node.get('remote_file_buf') is not None:
n = self.store_fdiff(node)
else:
n = node
todump.append(n)
continue
todump.append(node)
@ -294,6 +301,18 @@ class Manager():
remote_mount_point = self.get_remote_mount_point(node)
return agent.copy_dir(absolute_local_path, remote_mount_point)
def remove_node_remotely(self, node):
absolute_remote_path = self.get_absolute_remote_path(node)
agent = self.get_agent()
if node['cur_type'] == 'f':
## simply put
return agent.remove_file(absolute_remote_path)
elif node['cur_type'] == 'd':
#cur_hash contains the entire subtree to recreate on remote
## it is better to remove the root node if already exists on remote
# remote_mount_point = self.get_remote_mount_point(node)
return agent.remove_dir(absolute_remote_path)
#maybe useless
# def precheck_remote_unode(self, node):
# '''
@ -388,6 +407,7 @@ class Manager():
# before copy check the remote
## copy node to remote
print(f'Push local node: {absolute_local_path} to remote path: {absolute_remote_path}')
self.remove_node_remotely(node)
self.copy_node_to_remote(node)
new_local_tree = self.update_local_hash('changed', node)
## save new_local_tree
@ -422,11 +442,13 @@ class Manager():
if remote_hash is None and rexists:
# if node is added in local tree,
# but a copy appears in remote tree
#`we don't know before, remote_hash` don't exists
# we don't know before, `remote_hash` don't exists
# it is possible remote_file_buf exists
conflicting = True
unode = node.copy()
unode['last_hash'] = None
unode['remote_hash'] = rhash
if rfile_buf: unode['remote_file_buf'] = rfile_buf
return conflicting, unode
if rhash == remote_hash:

24
src/testing/add.py Normal file
View File

@ -0,0 +1,24 @@
import os
from lib.snapshot.generate import local as _genlocal
from testing import sync
def test_add_folder():
new_path = '/home/luca/sharednotes_dev/test_add/test_add_nested'
try:
os.makedirs(new_path)
except FileExistsError:
print(f'{new_path} already exists skip creation')
m = sync.get_test_manager()
m.sync()
## verify
local_node_hash = _genlocal.generate_tree_hash('/home/luca/sharednotes_dev/test_add/')
agent = m.get_agent()
remote_node_hash = agent.generate_tree_hash_oversftp('/home/notanamber/notes_dev/test_add/')
assert local_node_hash == remote_node_hash
print('Test executed succesfully')