@anysphere/file-service 0.0.0-dbd43428 → 0.0.0-e0c70bcd
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 +1 -0
- package/package.json +10 -8
- package/src/file_utils.rs +9 -10
- package/src/lib.rs +12 -21
- package/src/merkle_tree/local_construction.rs +5 -2
- package/src/merkle_tree/mod.rs +6 -1
package/Cargo.toml
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-e0c70bcd",
|
|
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-e0c70bcd",
|
|
40
|
+
"@anysphere/file-service-darwin-x64": "0.0.0-e0c70bcd",
|
|
41
|
+
"@anysphere/file-service-linux-x64-gnu": "0.0.0-e0c70bcd",
|
|
42
|
+
"@anysphere/file-service-darwin-arm64": "0.0.0-e0c70bcd",
|
|
43
|
+
"@anysphere/file-service-win32-arm64-msvc": "0.0.0-e0c70bcd",
|
|
44
|
+
"@anysphere/file-service-darwin-universal": "0.0.0-e0c70bcd",
|
|
45
|
+
"@anysphere/file-service-linux-arm64-gnu": "0.0.0-e0c70bcd"
|
|
44
46
|
}
|
|
45
47
|
}
|
package/src/file_utils.rs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// 4. vscode.fs.stat
|
|
6
6
|
|
|
7
7
|
use anyhow::Error;
|
|
8
|
-
use std::path::Path;
|
|
8
|
+
use std::{path::Path, any};
|
|
9
9
|
use tokio::fs;
|
|
10
10
|
|
|
11
11
|
pub fn is_in_bad_dir(file_path: &Path) -> Result<bool, Error> {
|
|
@@ -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
|
@@ -55,6 +55,7 @@ impl MerkleClient {
|
|
|
55
55
|
// 1. compute the merkle tree
|
|
56
56
|
// 2. update the backend
|
|
57
57
|
// 3. sync with the remote
|
|
58
|
+
info!("Merkle tree compute started!");
|
|
58
59
|
unsafe {
|
|
59
60
|
self.compute_merkle_tree().await?;
|
|
60
61
|
}
|
|
@@ -73,17 +74,6 @@ impl MerkleClient {
|
|
|
73
74
|
let t =
|
|
74
75
|
MerkleTree::construct_merkle_tree(self.root_directory.clone()).await;
|
|
75
76
|
|
|
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
|
-
}
|
|
86
|
-
|
|
87
77
|
match t {
|
|
88
78
|
Ok(tree) => {
|
|
89
79
|
self.tree = tree;
|
|
@@ -111,19 +101,24 @@ impl MerkleClient {
|
|
|
111
101
|
&self,
|
|
112
102
|
relative_path: String,
|
|
113
103
|
) -> Result<String, napi::Error> {
|
|
114
|
-
info!("relative_path: {:?}", relative_path);
|
|
115
104
|
let absolute_path =
|
|
116
|
-
std::path::Path::new(&self.root_directory).join(relative_path);
|
|
117
|
-
|
|
105
|
+
std::path::Path::new(&self.root_directory).join(&relative_path);
|
|
106
|
+
|
|
107
|
+
let canonical_path = match absolute_path.canonicalize() {
|
|
108
|
+
Ok(path) => path,
|
|
109
|
+
Err(e) => return Err(napi::Error::new(
|
|
110
|
+
napi::Status::Unknown,
|
|
111
|
+
format!("Error in canonicalizing path: {:?}", e),
|
|
112
|
+
)),
|
|
113
|
+
};
|
|
118
114
|
|
|
119
|
-
|
|
120
|
-
let hash = self.tree.get_subtree_hash(canonical_path).await;
|
|
115
|
+
let hash = self.tree.get_subtree_hash(canonical_path.clone()).await;
|
|
121
116
|
|
|
122
117
|
match hash {
|
|
123
118
|
Ok(hash) => Ok(hash),
|
|
124
119
|
Err(e) => Err(napi::Error::new(
|
|
125
120
|
napi::Status::Unknown,
|
|
126
|
-
format!("Error in get_subtree_hash: {:?}", e),
|
|
121
|
+
format!("Error in get_subtree_hash. \nRelative path: {:?}, \nAbsolute path: {:?}, \nCanonical path: {:?}, \nRoot directory: {:?}\nError: {:?}", &relative_path, absolute_path, canonical_path, self.root_directory, e),
|
|
127
122
|
)),
|
|
128
123
|
}
|
|
129
124
|
}
|
|
@@ -209,11 +204,7 @@ impl MerkleClient {
|
|
|
209
204
|
// TODO(sualeh): we should assert that the path is ascending up to the path.
|
|
210
205
|
|
|
211
206
|
let ret = vec![file];
|
|
212
|
-
info!("file: {:?}", ret);
|
|
213
|
-
|
|
214
207
|
let ret = ret.into_iter().chain(path.into_iter()).collect::<Vec<_>>();
|
|
215
|
-
info!("ret to js: {:?}", ret);
|
|
216
|
-
|
|
217
208
|
Ok(ret)
|
|
218
209
|
}
|
|
219
210
|
Err(e) => Err(napi::Error::new(
|
|
@@ -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,6 +80,7 @@ impl LocalConstruction for MerkleTree {
|
|
|
81
80
|
}
|
|
82
81
|
NodeType::File(file_name) => {
|
|
83
82
|
let f = File { node: node.clone() };
|
|
83
|
+
tracing::info!("File: {:?}", file_name);
|
|
84
84
|
files.insert(file_name.clone(), f);
|
|
85
85
|
}
|
|
86
86
|
NodeType::ErrorNode(_) => {
|
|
@@ -92,6 +92,9 @@ impl LocalConstruction for MerkleTree {
|
|
|
92
92
|
|
|
93
93
|
add_nodes_to_hashmap(&mt.root, &mut mt.files).await;
|
|
94
94
|
|
|
95
|
+
tracing::info!("Merkle tree compute finished!");
|
|
96
|
+
tracing::info!("Merkle tree: {}", mt);
|
|
97
|
+
|
|
95
98
|
Ok(mt)
|
|
96
99
|
}
|
|
97
100
|
|
package/src/merkle_tree/mod.rs
CHANGED
|
@@ -115,7 +115,8 @@ impl MerkleTree {
|
|
|
115
115
|
let node = match self.files.get(&abs_string) {
|
|
116
116
|
Some(file) => file.node.clone(),
|
|
117
117
|
None => {
|
|
118
|
-
|
|
118
|
+
let all_files: Vec<String> = self.files.keys().cloned().collect();
|
|
119
|
+
return Err(anyhow::anyhow!("Could not find file in tree! Looking for: {}. All files: {:?}", abs_string, all_files));
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
122
|
|
|
@@ -806,6 +807,10 @@ impl MerkleNode {
|
|
|
806
807
|
|
|
807
808
|
if is_git_ignored && !bypass_git {
|
|
808
809
|
// println!("skipping directory: {}", path_str);
|
|
810
|
+
tracing::info!(
|
|
811
|
+
"skipping directory because its git ignored: {}",
|
|
812
|
+
path_str
|
|
813
|
+
);
|
|
809
814
|
return Arc::new(RwLock::new(MerkleNode::empty_node(
|
|
810
815
|
Some(absolute_file_or_directory),
|
|
811
816
|
Some("Directory is git ignored!".to_string()),
|