@anysphere/file-service 0.0.0-e6124fba → 0.0.0-e9ef07ca
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.
- package/package.json +8 -8
- package/src/lib.rs +31 -7
- package/src/merkle_tree/local_construction.rs +7 -5
- package/src/merkle_tree/mod.rs +12 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anysphere/file-service",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-e9ef07ca",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"version": "napi version"
|
|
37
37
|
},
|
|
38
38
|
"optionalDependencies": {
|
|
39
|
-
"@anysphere/file-service-win32-x64-msvc": "0.0.0-
|
|
40
|
-
"@anysphere/file-service-darwin-x64": "0.0.0-
|
|
41
|
-
"@anysphere/file-service-linux-x64-gnu": "0.0.0-
|
|
42
|
-
"@anysphere/file-service-darwin-arm64": "0.0.0-
|
|
43
|
-
"@anysphere/file-service-win32-arm64-msvc": "0.0.0-
|
|
44
|
-
"@anysphere/file-service-darwin-universal": "0.0.0-
|
|
45
|
-
"@anysphere/file-service-linux-arm64-gnu": "0.0.0-
|
|
39
|
+
"@anysphere/file-service-win32-x64-msvc": "0.0.0-e9ef07ca",
|
|
40
|
+
"@anysphere/file-service-darwin-x64": "0.0.0-e9ef07ca",
|
|
41
|
+
"@anysphere/file-service-linux-x64-gnu": "0.0.0-e9ef07ca",
|
|
42
|
+
"@anysphere/file-service-darwin-arm64": "0.0.0-e9ef07ca",
|
|
43
|
+
"@anysphere/file-service-win32-arm64-msvc": "0.0.0-e9ef07ca",
|
|
44
|
+
"@anysphere/file-service-darwin-universal": "0.0.0-e9ef07ca",
|
|
45
|
+
"@anysphere/file-service-linux-arm64-gnu": "0.0.0-e9ef07ca"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/lib.rs
CHANGED
|
@@ -8,21 +8,28 @@ use std::{collections::HashSet, vec};
|
|
|
8
8
|
|
|
9
9
|
use anyhow::Context;
|
|
10
10
|
use merkle_tree::{LocalConstruction, MerkleTree};
|
|
11
|
-
use tracing::{info, Level};
|
|
11
|
+
use tracing::{info, Level, subscriber};
|
|
12
12
|
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
|
13
13
|
use tracing_subscriber::fmt;
|
|
14
|
+
use tracing_subscriber::prelude::*;
|
|
15
|
+
use tracing_appender::non_blocking::WorkerGuard;
|
|
14
16
|
|
|
15
17
|
#[macro_use]
|
|
16
18
|
extern crate napi_derive;
|
|
17
19
|
|
|
20
|
+
pub enum GuardType {
|
|
21
|
+
// Guard(tracing_axiom::Guard),
|
|
22
|
+
WorkerGuard(tracing_appender::non_blocking::WorkerGuard),
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
#[napi]
|
|
19
26
|
pub struct MerkleClient {
|
|
20
27
|
tree: MerkleTree,
|
|
21
28
|
absolute_root_directory: String,
|
|
22
|
-
_guard: Option<
|
|
29
|
+
_guard: Option<GuardType>,
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
pub fn init_logger() -> Option<
|
|
32
|
+
pub fn init_logger() -> Option<GuardType> {
|
|
26
33
|
#[cfg(feature = "debugfile")]
|
|
27
34
|
let _guard = {
|
|
28
35
|
let file_appender =
|
|
@@ -36,10 +43,23 @@ pub fn init_logger() -> Option<tracing_appender::non_blocking::WorkerGuard> {
|
|
|
36
43
|
.finish();
|
|
37
44
|
|
|
38
45
|
let _ = tracing::subscriber::set_global_default(subscriber);
|
|
39
|
-
|
|
46
|
+
|
|
47
|
+
Some(GuardType::WorkerGuard(_guard))
|
|
40
48
|
};
|
|
49
|
+
|
|
41
50
|
#[cfg(not(feature = "debugfile"))]
|
|
42
|
-
|
|
51
|
+
let _guard = {
|
|
52
|
+
// let (axiom_layer, _guard) = tracing_axiom::builder().with_token("xaat-a51088e6-7889-41c0-b440-cfd4601acdd7").with_dataset("local-indexing").layer().ok()?;
|
|
53
|
+
// // let fmt_layer = fmt::layer().with_level(true).with_ansi(false).with_line_number(true);
|
|
54
|
+
|
|
55
|
+
// let _ = tracing_subscriber::registry().with(axiom_layer).try_init().ok()?;
|
|
56
|
+
// // let _ = tracing::subscriber::set_global_default(subscriber);
|
|
57
|
+
|
|
58
|
+
// info!("Tracing initialized! in rust");
|
|
59
|
+
|
|
60
|
+
None
|
|
61
|
+
};
|
|
62
|
+
|
|
43
63
|
_guard
|
|
44
64
|
}
|
|
45
65
|
|
|
@@ -97,9 +117,13 @@ impl MerkleClient {
|
|
|
97
117
|
is_git_repo: bool,
|
|
98
118
|
) -> Result<(), napi::Error> {
|
|
99
119
|
// make the git ignored files into a hash set
|
|
100
|
-
let git_ignored_set = HashSet::from_iter(git_ignored_files.into_iter());
|
|
120
|
+
let mut git_ignored_set = HashSet::from_iter(git_ignored_files.into_iter());
|
|
101
121
|
|
|
102
|
-
|
|
122
|
+
// if the hashset itself contains the root directory, then we should remove it.
|
|
123
|
+
// this is because the root directory is not a file, and we don't want to ignore it.
|
|
124
|
+
if git_ignored_set.contains(&self.absolute_root_directory) {
|
|
125
|
+
git_ignored_set.remove(&self.absolute_root_directory);
|
|
126
|
+
}
|
|
103
127
|
|
|
104
128
|
let t = MerkleTree::construct_merkle_tree(
|
|
105
129
|
self.absolute_root_directory.clone(),
|
|
@@ -9,6 +9,7 @@ use tonic::async_trait;
|
|
|
9
9
|
|
|
10
10
|
#[async_trait]
|
|
11
11
|
impl LocalConstruction for MerkleTree {
|
|
12
|
+
#[tracing::instrument]
|
|
12
13
|
async fn new(
|
|
13
14
|
root_directory: Option<String>,
|
|
14
15
|
) -> Result<MerkleTree, anyhow::Error> {
|
|
@@ -32,6 +33,7 @@ impl LocalConstruction for MerkleTree {
|
|
|
32
33
|
/// 2. compute hash for each file
|
|
33
34
|
/// 3. construct merkle tree
|
|
34
35
|
/// 4. return merkle tree
|
|
36
|
+
#[tracing::instrument(skip(git_ignored_files_and_dirs))]
|
|
35
37
|
async fn construct_merkle_tree(
|
|
36
38
|
absolute_path_to_root_directory: String,
|
|
37
39
|
git_ignored_files_and_dirs: HashSet<String>,
|
|
@@ -59,8 +61,8 @@ impl LocalConstruction for MerkleTree {
|
|
|
59
61
|
&git_ignored_files_and_dirs,
|
|
60
62
|
absolute_path_to_root_directory.as_str(),
|
|
61
63
|
is_git_repo
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
+
).await;
|
|
65
|
+
|
|
64
66
|
let mut mt = MerkleTree {
|
|
65
67
|
root: root_node,
|
|
66
68
|
files: BTreeMap::new(),
|
|
@@ -80,7 +82,6 @@ impl LocalConstruction for MerkleTree {
|
|
|
80
82
|
let node_reader = node.read().await;
|
|
81
83
|
match &node_reader.node_type {
|
|
82
84
|
NodeType::Branch(n) => {
|
|
83
|
-
tracing::info!("Branch: {:?}", n.0);
|
|
84
85
|
let children = &n.1;
|
|
85
86
|
files.insert(n.0.clone(), File { node: node.clone() });
|
|
86
87
|
for child in children {
|
|
@@ -107,12 +108,12 @@ impl LocalConstruction for MerkleTree {
|
|
|
107
108
|
|
|
108
109
|
add_nodes_to_hashmap(&mt.root, &mut mt.files).await;
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
tracing::info!("Merkle tree: {}", mt);
|
|
111
|
+
tracing::info!("number of files in the tree: {}", mt.files.len());
|
|
112
112
|
|
|
113
113
|
Ok(mt)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
#[tracing::instrument]
|
|
116
117
|
async fn update_file(
|
|
117
118
|
&mut self,
|
|
118
119
|
file_path: String,
|
|
@@ -152,6 +153,7 @@ impl LocalConstruction for MerkleTree {
|
|
|
152
153
|
Ok(())
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
#[tracing::instrument]
|
|
155
157
|
async fn delete_file(
|
|
156
158
|
&mut self,
|
|
157
159
|
file_path: String,
|
package/src/merkle_tree/mod.rs
CHANGED
|
@@ -13,6 +13,7 @@ pub mod test;
|
|
|
13
13
|
|
|
14
14
|
pub type MerkleNodePtr = Arc<RwLock<MerkleNode>>;
|
|
15
15
|
|
|
16
|
+
#[derive(Debug)]
|
|
16
17
|
pub struct MerkleTree {
|
|
17
18
|
root_path: String,
|
|
18
19
|
root: MerkleNodePtr,
|
|
@@ -103,6 +104,7 @@ impl MerkleTree {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
#[tracing::instrument]
|
|
106
108
|
pub async fn get_subtree_hash(
|
|
107
109
|
&self,
|
|
108
110
|
absolute_path: &str,
|
|
@@ -122,11 +124,6 @@ impl MerkleTree {
|
|
|
122
124
|
let node_reader = node.read().await;
|
|
123
125
|
let node_hash = node_reader.hash.clone();
|
|
124
126
|
|
|
125
|
-
info!(
|
|
126
|
-
"get_subtree_hash for path: {}, node_hash: {}",
|
|
127
|
-
absolute_path, node_hash
|
|
128
|
-
);
|
|
129
|
-
|
|
130
127
|
Ok(node_hash)
|
|
131
128
|
}
|
|
132
129
|
|
|
@@ -731,6 +728,7 @@ impl MerkleNode {
|
|
|
731
728
|
.await
|
|
732
729
|
}
|
|
733
730
|
|
|
731
|
+
#[tracing::instrument]
|
|
734
732
|
async fn new(
|
|
735
733
|
absolute_file_or_directory: PathBuf,
|
|
736
734
|
parent: ParentPtr,
|
|
@@ -772,7 +770,9 @@ impl MerkleNode {
|
|
|
772
770
|
Box::pin(async move {
|
|
773
771
|
// check if it is a file
|
|
774
772
|
let path_str = absolute_file_or_directory.to_str().unwrap().to_string();
|
|
773
|
+
|
|
775
774
|
if absolute_file_or_directory.is_file() {
|
|
775
|
+
tracing::info!("constructing file node for path_str: {}", path_str);
|
|
776
776
|
return Arc::new(RwLock::new(
|
|
777
777
|
MerkleNode::construct_file_node_or_error_node(
|
|
778
778
|
absolute_file_or_directory,
|
|
@@ -783,6 +783,8 @@ impl MerkleNode {
|
|
|
783
783
|
));
|
|
784
784
|
}
|
|
785
785
|
|
|
786
|
+
tracing::info!("constructing directory node for path_str: {}", path_str);
|
|
787
|
+
|
|
786
788
|
// check if the directory fails the bad dir test.
|
|
787
789
|
let is_bad_dir = file_utils::is_in_bad_dir(absolute_file_or_directory);
|
|
788
790
|
if is_bad_dir.is_err() || is_bad_dir.unwrap_or(false) {
|
|
@@ -794,8 +796,10 @@ impl MerkleNode {
|
|
|
794
796
|
}
|
|
795
797
|
|
|
796
798
|
let is_git_ignored_dir = ignored_files.contains(&path_str);
|
|
799
|
+
tracing::info!("is_git_ignored_dir: {}", is_git_ignored_dir);
|
|
797
800
|
|
|
798
801
|
if is_git_ignored_dir && !bypass_git {
|
|
802
|
+
tracing::info!("skipping directory: {}", path_str);
|
|
799
803
|
return Arc::new(RwLock::new(MerkleNode::empty_node(
|
|
800
804
|
Some(absolute_file_or_directory),
|
|
801
805
|
Some("Directory is git ignored!".to_string()),
|
|
@@ -806,6 +810,7 @@ impl MerkleNode {
|
|
|
806
810
|
match entries {
|
|
807
811
|
Ok(_) => (),
|
|
808
812
|
Err(e) => {
|
|
813
|
+
tracing::error!("error reading directory: {}", e);
|
|
809
814
|
return Arc::new(RwLock::new(MerkleNode::empty_node(
|
|
810
815
|
Some(absolute_file_or_directory),
|
|
811
816
|
Some(e.to_string()),
|
|
@@ -838,6 +843,7 @@ impl MerkleNode {
|
|
|
838
843
|
);
|
|
839
844
|
}
|
|
840
845
|
Err(e) => {
|
|
846
|
+
tracing::error!("error reading directory: {}", e);
|
|
841
847
|
children.push(Arc::new(RwLock::new(MerkleNode::empty_node(
|
|
842
848
|
Some(absolute_file_or_directory),
|
|
843
849
|
Some(e.to_string()),
|
|
@@ -934,6 +940,7 @@ impl MerkleNode {
|
|
|
934
940
|
Err(e) => {
|
|
935
941
|
// println!("constructing error node. error: {}", e);
|
|
936
942
|
// println!("file_path: {:?}", file_path);
|
|
943
|
+
tracing::error!("constructing error node. error: {}", e);
|
|
937
944
|
MerkleNode::empty_node(Some(absolute_file_path), Some(e))
|
|
938
945
|
}
|
|
939
946
|
};
|
|
@@ -995,7 +1002,6 @@ impl MerkleNode {
|
|
|
995
1002
|
if hash == "" {
|
|
996
1003
|
continue;
|
|
997
1004
|
}
|
|
998
|
-
info!("name: {}, hash: {}", name, hash);
|
|
999
1005
|
hasher.update(hash);
|
|
1000
1006
|
}
|
|
1001
1007
|
|