@anysphere/file-service 0.0.0-e3fdf62d → 0.0.0-e492c95a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,40 +0,0 @@
1
- // use crate::merkle_tree::{MerkleNode, File, NodeType};
2
-
3
- // use super::{file_utils, LocalConstruction, MerkleTree};
4
- // use sha2::Digest;
5
- // use tonic::async_trait;
6
- // use std::path::PathBuf;
7
- // use std::{collections::HashMap, fs, path::Path, sync::Arc, sync::Weak};
8
-
9
- // #[async_trait]
10
- // impl RemoteSync for MerkleTree {
11
- // /// Key function:
12
- // /// Syncs the current tree with the remote tree on the server.
13
- // /// PRECONDITION: the current tree is a subset of the remote tree.
14
- // async fn sync_with_remote(
15
- // &mut self,
16
- // client: super::RepositoryClient,
17
- // ) -> Result<Vec<File>, tonic::Status> {
18
- // // alg:
19
- // // start from the root,
20
- // // and diff recursively till you find all the files that are different.
21
-
22
- // Ok(vec![])
23
- // }
24
-
25
- // /// Key function:
26
- // /// Is used to upload a constructed tree to the server.
27
- // /// including sending it for the first time.
28
- // async fn sync_subtree_node(
29
- // &mut self,
30
- // node: &MerkleNode,
31
- // client: super::RepositoryClient,
32
- // ) -> Result<Vec<File>, tonic::Status> {
33
- // // alg:
34
- // // 1. check if you are the same, if so, return empty
35
- // // 2. if you are not the same, then
36
- // // you get the children of the node. you can then figure out which ones are different
37
- // // recurse on those!
38
- // Ok(vec![])
39
- // }
40
- // }
@@ -1,126 +0,0 @@
1
- #[cfg(test)]
2
- mod tests {
3
- use super::super::*;
4
- use std::path::PathBuf;
5
-
6
- use std::fs::File;
7
- use std::io::Write;
8
- use std::path::Path;
9
- use tempfile::tempdir;
10
-
11
- #[tokio::test]
12
- async fn test_empty_tree() {
13
- let tree = MerkleTree::empty_tree();
14
- assert_eq!(tree.root_path, "".to_string());
15
- assert_eq!(tree.files.len(), 0);
16
- }
17
-
18
- #[tokio::test]
19
- async fn test_empty_folder() {
20
- let temp_dir = tempdir().unwrap();
21
- let temp_dir_path = temp_dir.path().to_str().unwrap().to_string();
22
-
23
- // Test new() function
24
- match MerkleTree::new(Some(temp_dir_path.clone())).await {
25
- Ok(tree) => {
26
- assert_eq!(tree.root_path, temp_dir_path);
27
- assert_eq!(tree.files.len(), 0);
28
- }
29
- Err(_) => panic!("Failed to create new MerkleTree"),
30
- }
31
- }
32
-
33
- #[tokio::test]
34
- async fn test_local_construction() {
35
- let temp_dir = tempdir().unwrap();
36
- let temp_dir_path = temp_dir.path().to_str().unwrap().to_string();
37
-
38
- // Create a file in the temp directory
39
- let file_path = temp_dir_path.clone() + "/test.txt";
40
- let mut file = File::create(&file_path).unwrap();
41
- writeln!(file, "Hello, world!").unwrap();
42
- // print the contents of hte directory using ls
43
- // let path = Path::new(&temp_dir_path);
44
-
45
- // Test construct_merkle_tree() function
46
- let tree =
47
- MerkleTree::construct_merkle_tree(temp_dir_path.clone()).await;
48
- let mut tree = match tree {
49
- Ok(tree) => {
50
- assert_eq!(tree.files.len(), 2);
51
- assert!(tree.files.contains_key(&file_path));
52
-
53
- tree
54
- }
55
- Err(_) => panic!("Failed to construct MerkleTree"),
56
- };
57
- // Update the file
58
- writeln!(file, "Hello, again!").unwrap();
59
- match tree.update_file(file_path.clone()).await {
60
- Ok(_) => (),
61
- Err(_) => panic!("Failed to update file"),
62
- };
63
- // Check that the file's hash has been updated in the tree
64
- let file_node_option = tree.files.get(&file_path);
65
- match file_node_option {
66
- Some(file_node) => {
67
- let hash = file_node.node.read().await.hash.clone();
68
- assert_eq!(hash, compute_hash("Hello, world!\nHello, again!\n"));
69
- }
70
- None => panic!("Failed to get file node"),
71
- }
72
- // Test delete_file() function
73
- match tree.delete_file(file_path.clone()).await {
74
- Ok(_) => {
75
- assert!(!tree.files.contains_key(&file_path));
76
- }
77
- Err(_) => panic!("Failed to delete file"),
78
- }
79
- }
80
-
81
- // // TEST: manual sanity test: go to the git root and then index construct a merle tree on the whole repo.
82
- // #[tokio::test]
83
- // async fn test_git_root_merkle_tree() {
84
-
85
- // use std::process::Command;
86
- // // Get the git root path
87
- // let output = Command::new("git")
88
- // .args(&["rev-parse", "--show-toplevel"])
89
- // .output()
90
- // .expect("Failed to get git root path");
91
-
92
- // let git_root_path = String::from_utf8(output.stdout).unwrap().trim().to_string();
93
-
94
- // // Construct the Merkle tree
95
- // let tree = MerkleTree::construct_merkle_tree(git_root_path.clone()).await;
96
- // // Check that the tree is not empty
97
- // assert_ne!(tree.files.len(), 0);
98
- // println!("tree.files.len() = {}", tree.files.len());
99
-
100
- // // print the tree to a file.
101
- // let mut file = File::create("tree.txt").unwrap();
102
- // match write!(file, "{}", tree) {
103
- // Ok(_) => {},
104
- // Err(e) => println!("Failed to write to file: {}", e),
105
- // }
106
- // // write another file with the name of the files
107
- // let mut file = File::create("tree_files.txt").unwrap();
108
- // // create a list of files as a vec
109
- // let mut files: Vec<String> = Vec::new();
110
- // for (file_path, _) in tree.files.iter() {
111
- // files.push(file_path.clone());
112
- // }
113
- // // then sort the vector of files
114
- // files.sort();
115
-
116
- // for file_path in files.iter() {
117
- // match writeln!(file, "{}", file_path) {
118
- // Ok(_) => {},
119
- // Err(e) => println!("Failed to write to file: {}", e),
120
- // }
121
- // }
122
-
123
- // // Check that the root path is correct
124
- // assert_eq!(tree.root_path, git_root_path);
125
- // }
126
- }
File without changes