@anysphere/file-service 0.0.0-bff0125b → 0.0.0-c8c4f8fc
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/Cargo.toml +2 -0
- package/index.d.ts +1 -1
- package/package.json +10 -8
- package/src/file_utils.rs +8 -9
- package/src/lib.rs +40 -27
- package/src/merkle_tree/local_construction.rs +10 -3
- package/src/merkle_tree/mod.rs +8 -11
package/Cargo.toml
CHANGED
package/index.d.ts
CHANGED
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-c8c4f8fc",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"additional": [
|
|
10
10
|
"aarch64-apple-darwin",
|
|
11
11
|
"aarch64-pc-windows-msvc",
|
|
12
|
-
"universal-apple-darwin"
|
|
12
|
+
"universal-apple-darwin",
|
|
13
|
+
"aarch64-unknown-linux-gnu"
|
|
13
14
|
]
|
|
14
15
|
}
|
|
15
16
|
},
|
|
@@ -35,11 +36,12 @@
|
|
|
35
36
|
"version": "napi version"
|
|
36
37
|
},
|
|
37
38
|
"optionalDependencies": {
|
|
38
|
-
"@anysphere/file-service-win32-x64-msvc": "0.0.0-
|
|
39
|
-
"@anysphere/file-service-darwin-x64": "0.0.0-
|
|
40
|
-
"@anysphere/file-service-linux-x64-gnu": "0.0.0-
|
|
41
|
-
"@anysphere/file-service-darwin-arm64": "0.0.0-
|
|
42
|
-
"@anysphere/file-service-win32-arm64-msvc": "0.0.0-
|
|
43
|
-
"@anysphere/file-service-darwin-universal": "0.0.0-
|
|
39
|
+
"@anysphere/file-service-win32-x64-msvc": "0.0.0-c8c4f8fc",
|
|
40
|
+
"@anysphere/file-service-darwin-x64": "0.0.0-c8c4f8fc",
|
|
41
|
+
"@anysphere/file-service-linux-x64-gnu": "0.0.0-c8c4f8fc",
|
|
42
|
+
"@anysphere/file-service-darwin-arm64": "0.0.0-c8c4f8fc",
|
|
43
|
+
"@anysphere/file-service-win32-arm64-msvc": "0.0.0-c8c4f8fc",
|
|
44
|
+
"@anysphere/file-service-darwin-universal": "0.0.0-c8c4f8fc",
|
|
45
|
+
"@anysphere/file-service-linux-arm64-gnu": "0.0.0-c8c4f8fc"
|
|
44
46
|
}
|
|
45
47
|
}
|
package/src/file_utils.rs
CHANGED
|
@@ -62,7 +62,7 @@ pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
|
|
|
62
62
|
Some(extension) => match extension.to_str() {
|
|
63
63
|
Some(ext_str) => {
|
|
64
64
|
if bad_extensions.contains(&ext_str) {
|
|
65
|
-
return Err(anyhow::anyhow!("
|
|
65
|
+
return Err(anyhow::anyhow!("Binary file excluded from indexing."));
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
None => {
|
|
@@ -88,10 +88,12 @@ pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
|
|
|
88
88
|
Ok(())
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// use binaryornot::is_binary;
|
|
92
|
+
// use anyhow::Context;
|
|
91
93
|
// implement the buffer above:
|
|
92
94
|
pub async fn is_good_file_runtime_check(
|
|
93
95
|
file_path: &Path,
|
|
94
|
-
|
|
96
|
+
_buffer: &[u8],
|
|
95
97
|
) -> Result<(), Error> {
|
|
96
98
|
match get_file_size(file_path).await {
|
|
97
99
|
Ok(size) if size > 2 * 1024 * 1024 => {
|
|
@@ -101,13 +103,10 @@ pub async fn is_good_file_runtime_check(
|
|
|
101
103
|
_ => {}
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return Err(anyhow::anyhow!("File is not a valid UTF-8 string"));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
106
|
+
// if is_binary(file_path).context("Failed to check if file is binary")? {
|
|
107
|
+
// return Err(anyhow::anyhow!("File is binary"));
|
|
108
|
+
// }
|
|
109
|
+
|
|
111
110
|
Ok(())
|
|
112
111
|
}
|
|
113
112
|
|
package/src/lib.rs
CHANGED
|
@@ -17,7 +17,7 @@ extern crate napi_derive;
|
|
|
17
17
|
#[napi]
|
|
18
18
|
pub struct MerkleClient {
|
|
19
19
|
tree: MerkleTree,
|
|
20
|
-
|
|
20
|
+
absolute_root_directory: String,
|
|
21
21
|
_guard: tracing_appender::non_blocking::WorkerGuard,
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -40,12 +40,22 @@ pub fn init_logger() -> tracing_appender::non_blocking::WorkerGuard {
|
|
|
40
40
|
#[napi]
|
|
41
41
|
impl MerkleClient {
|
|
42
42
|
#[napi(constructor)]
|
|
43
|
-
pub fn new(
|
|
43
|
+
pub fn new(absolute_root_directory: String) -> MerkleClient {
|
|
44
44
|
let _guard = init_logger();
|
|
45
45
|
|
|
46
|
+
let canonical_root_directory = std::path::Path::new(&absolute_root_directory);
|
|
47
|
+
// use dunce::canonicalize;
|
|
48
|
+
let canonical_root_directory = match dunce::canonicalize(&canonical_root_directory) {
|
|
49
|
+
Ok(path) => path.to_str().unwrap_or(&absolute_root_directory).to_string(),
|
|
50
|
+
Err(e) => {
|
|
51
|
+
info!("Error in canonicalizing path: path: {:?}, error {:?}", canonical_root_directory, e);
|
|
52
|
+
absolute_root_directory
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
46
56
|
MerkleClient {
|
|
47
57
|
tree: MerkleTree::empty_tree(),
|
|
48
|
-
|
|
58
|
+
absolute_root_directory: canonical_root_directory,
|
|
49
59
|
_guard,
|
|
50
60
|
}
|
|
51
61
|
}
|
|
@@ -55,6 +65,7 @@ impl MerkleClient {
|
|
|
55
65
|
// 1. compute the merkle tree
|
|
56
66
|
// 2. update the backend
|
|
57
67
|
// 3. sync with the remote
|
|
68
|
+
info!("Merkle tree compute started!");
|
|
58
69
|
unsafe {
|
|
59
70
|
self.compute_merkle_tree().await?;
|
|
60
71
|
}
|
|
@@ -71,18 +82,7 @@ impl MerkleClient {
|
|
|
71
82
|
&mut self,
|
|
72
83
|
) -> Result<(), napi::Error> {
|
|
73
84
|
let t =
|
|
74
|
-
MerkleTree::construct_merkle_tree(self.
|
|
75
|
-
|
|
76
|
-
let files = self.tree.get_all_files().await;
|
|
77
|
-
|
|
78
|
-
match files {
|
|
79
|
-
Ok(files) => {
|
|
80
|
-
info!("files: {:?}", files);
|
|
81
|
-
}
|
|
82
|
-
Err(e) => {
|
|
83
|
-
info!("Error in get_all_files: {:?}", e);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
85
|
+
MerkleTree::construct_merkle_tree(self.absolute_root_directory.clone()).await;
|
|
86
86
|
|
|
87
87
|
match t {
|
|
88
88
|
Ok(tree) => {
|
|
@@ -111,19 +111,36 @@ impl MerkleClient {
|
|
|
111
111
|
&self,
|
|
112
112
|
relative_path: String,
|
|
113
113
|
) -> Result<String, napi::Error> {
|
|
114
|
-
info!("relative_path: {:?}", relative_path);
|
|
115
114
|
let absolute_path =
|
|
116
|
-
std::path::Path::new(&self.
|
|
117
|
-
|
|
115
|
+
std::path::Path::new(&self.absolute_root_directory).join(&relative_path);
|
|
116
|
+
|
|
117
|
+
let canonical_path = match dunce::canonicalize(&absolute_path) {
|
|
118
|
+
Ok(path) => path,
|
|
119
|
+
Err(e) => {
|
|
120
|
+
return Err(napi::Error::new(
|
|
121
|
+
napi::Status::Unknown,
|
|
122
|
+
format!("Error in canonicalizing path: {:?}", e),
|
|
123
|
+
))
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
let cononical_str = match canonical_path.to_str() {
|
|
128
|
+
Some(s) => s,
|
|
129
|
+
None => {
|
|
130
|
+
return Err(napi::Error::new(
|
|
131
|
+
napi::Status::Unknown,
|
|
132
|
+
format!("Error in converting canonical path to string"),
|
|
133
|
+
))
|
|
134
|
+
}
|
|
135
|
+
};
|
|
118
136
|
|
|
119
|
-
|
|
120
|
-
let hash = self.tree.get_subtree_hash(canonical_path).await;
|
|
137
|
+
let hash = self.tree.get_subtree_hash(cononical_str).await;
|
|
121
138
|
|
|
122
139
|
match hash {
|
|
123
140
|
Ok(hash) => Ok(hash),
|
|
124
141
|
Err(e) => Err(napi::Error::new(
|
|
125
142
|
napi::Status::Unknown,
|
|
126
|
-
format!("Error in get_subtree_hash: {:?}", e),
|
|
143
|
+
format!("Error in get_subtree_hash. \nRelative path: {:?}, \nAbsolute path: {:?}, \nCanonical path: {:?}, \nRoot directory: {:?}\nError: {:?}", &relative_path, absolute_path, canonical_path, self.absolute_root_directory, e),
|
|
127
144
|
)),
|
|
128
145
|
}
|
|
129
146
|
}
|
|
@@ -145,7 +162,7 @@ impl MerkleClient {
|
|
|
145
162
|
&self,
|
|
146
163
|
relative_path: String,
|
|
147
164
|
) -> Result<i32, napi::Error> {
|
|
148
|
-
let absolute_path = std::path::Path::new(&self.
|
|
165
|
+
let absolute_path = std::path::Path::new(&self.absolute_root_directory)
|
|
149
166
|
.join(relative_path)
|
|
150
167
|
.canonicalize()?;
|
|
151
168
|
|
|
@@ -209,11 +226,7 @@ impl MerkleClient {
|
|
|
209
226
|
// TODO(sualeh): we should assert that the path is ascending up to the path.
|
|
210
227
|
|
|
211
228
|
let ret = vec![file];
|
|
212
|
-
info!("file: {:?}", ret);
|
|
213
|
-
|
|
214
229
|
let ret = ret.into_iter().chain(path.into_iter()).collect::<Vec<_>>();
|
|
215
|
-
info!("ret to js: {:?}", ret);
|
|
216
|
-
|
|
217
230
|
Ok(ret)
|
|
218
231
|
}
|
|
219
232
|
Err(e) => Err(napi::Error::new(
|
|
@@ -259,6 +272,6 @@ impl MerkleClient {
|
|
|
259
272
|
|
|
260
273
|
#[napi]
|
|
261
274
|
pub fn update_root_directory(&mut self, root_directory: String) {
|
|
262
|
-
self.
|
|
275
|
+
self.absolute_root_directory = root_directory;
|
|
263
276
|
}
|
|
264
277
|
}
|
|
@@ -46,8 +46,6 @@ impl LocalConstruction for MerkleTree {
|
|
|
46
46
|
Err(_e) => HashSet::new(),
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
tracing::info!("git_ignored_files: {:?}", git_ignored_files);
|
|
50
|
-
|
|
51
49
|
let root_node = MerkleNode::new(
|
|
52
50
|
path,
|
|
53
51
|
None,
|
|
@@ -73,6 +71,7 @@ impl LocalConstruction for MerkleTree {
|
|
|
73
71
|
let node_reader = node.read().await;
|
|
74
72
|
match &node_reader.node_type {
|
|
75
73
|
NodeType::Branch(n) => {
|
|
74
|
+
tracing::info!("Branch: {:?}", n.0);
|
|
76
75
|
let children = &n.1;
|
|
77
76
|
files.insert(n.0.clone(), File { node: node.clone() });
|
|
78
77
|
for child in children {
|
|
@@ -81,7 +80,12 @@ impl LocalConstruction for MerkleTree {
|
|
|
81
80
|
}
|
|
82
81
|
NodeType::File(file_name) => {
|
|
83
82
|
let f = File { node: node.clone() };
|
|
84
|
-
|
|
83
|
+
let canonical_file_name = match dunce::canonicalize(file_name) {
|
|
84
|
+
Ok(path) => path.to_str().unwrap_or(file_name).to_string(),
|
|
85
|
+
Err(_) => file_name.clone(),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
files.insert(canonical_file_name, f);
|
|
85
89
|
}
|
|
86
90
|
NodeType::ErrorNode(_) => {
|
|
87
91
|
// do nothing
|
|
@@ -92,6 +96,9 @@ impl LocalConstruction for MerkleTree {
|
|
|
92
96
|
|
|
93
97
|
add_nodes_to_hashmap(&mt.root, &mut mt.files).await;
|
|
94
98
|
|
|
99
|
+
tracing::info!("Merkle tree compute finished!");
|
|
100
|
+
tracing::info!("Merkle tree: {}", mt);
|
|
101
|
+
|
|
95
102
|
Ok(mt)
|
|
96
103
|
}
|
|
97
104
|
|
package/src/merkle_tree/mod.rs
CHANGED
|
@@ -101,21 +101,14 @@ impl MerkleTree {
|
|
|
101
101
|
|
|
102
102
|
pub async fn get_subtree_hash(
|
|
103
103
|
&self,
|
|
104
|
-
absolute_path:
|
|
104
|
+
absolute_path: &str,
|
|
105
105
|
) -> Result<String, anyhow::Error> {
|
|
106
|
-
let abs_string = match absolute_path.to_str() {
|
|
107
|
-
Some(s) => s.to_string(),
|
|
108
|
-
None => {
|
|
109
|
-
return Err(anyhow::anyhow!(
|
|
110
|
-
"get_subtree_hash: Failed to convert path to string"
|
|
111
|
-
))
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
106
|
|
|
115
|
-
let node = match self.files.get(
|
|
107
|
+
let node = match self.files.get(absolute_path) {
|
|
116
108
|
Some(file) => file.node.clone(),
|
|
117
109
|
None => {
|
|
118
|
-
|
|
110
|
+
let all_files: Vec<String> = self.files.keys().cloned().collect();
|
|
111
|
+
return Err(anyhow::anyhow!("Could not find file in tree! Looking for: {}. All files: {:?}", absolute_path, all_files));
|
|
119
112
|
}
|
|
120
113
|
};
|
|
121
114
|
|
|
@@ -806,6 +799,10 @@ impl MerkleNode {
|
|
|
806
799
|
|
|
807
800
|
if is_git_ignored && !bypass_git {
|
|
808
801
|
// println!("skipping directory: {}", path_str);
|
|
802
|
+
tracing::info!(
|
|
803
|
+
"skipping directory because its git ignored: {}",
|
|
804
|
+
path_str
|
|
805
|
+
);
|
|
809
806
|
return Arc::new(RwLock::new(MerkleNode::empty_node(
|
|
810
807
|
Some(absolute_file_or_directory),
|
|
811
808
|
Some("Directory is git ignored!".to_string()),
|