@anysphere/file-service 0.0.0-e36a46ab → 0.0.0-e6124fba

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 CHANGED
@@ -9,6 +9,7 @@ crate-type = ["cdylib"]
9
9
  [features]
10
10
  default = ["windows-subsystem"]
11
11
  windows-subsystem = []
12
+ debugfile = []
12
13
 
13
14
  [dependencies]
14
15
  # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anysphere/file-service",
3
- "version": "0.0.0-e36a46ab",
3
+ "version": "0.0.0-e6124fba",
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-e36a46ab",
40
- "@anysphere/file-service-darwin-x64": "0.0.0-e36a46ab",
41
- "@anysphere/file-service-linux-x64-gnu": "0.0.0-e36a46ab",
42
- "@anysphere/file-service-darwin-arm64": "0.0.0-e36a46ab",
43
- "@anysphere/file-service-win32-arm64-msvc": "0.0.0-e36a46ab",
44
- "@anysphere/file-service-darwin-universal": "0.0.0-e36a46ab",
45
- "@anysphere/file-service-linux-arm64-gnu": "0.0.0-e36a46ab"
39
+ "@anysphere/file-service-win32-x64-msvc": "0.0.0-e6124fba",
40
+ "@anysphere/file-service-darwin-x64": "0.0.0-e6124fba",
41
+ "@anysphere/file-service-linux-x64-gnu": "0.0.0-e6124fba",
42
+ "@anysphere/file-service-darwin-arm64": "0.0.0-e6124fba",
43
+ "@anysphere/file-service-win32-arm64-msvc": "0.0.0-e6124fba",
44
+ "@anysphere/file-service-darwin-universal": "0.0.0-e6124fba",
45
+ "@anysphere/file-service-linux-arm64-gnu": "0.0.0-e6124fba"
46
46
  }
47
47
  }
package/src/lib.rs CHANGED
@@ -4,7 +4,7 @@
4
4
  pub mod file_utils;
5
5
  pub mod merkle_tree;
6
6
 
7
- use std::{vec, collections::HashSet};
7
+ use std::{collections::HashSet, vec};
8
8
 
9
9
  use anyhow::Context;
10
10
  use merkle_tree::{LocalConstruction, MerkleTree};
@@ -19,22 +19,27 @@ extern crate napi_derive;
19
19
  pub struct MerkleClient {
20
20
  tree: MerkleTree,
21
21
  absolute_root_directory: String,
22
- _guard: tracing_appender::non_blocking::WorkerGuard,
22
+ _guard: Option<tracing_appender::non_blocking::WorkerGuard>,
23
23
  }
24
24
 
25
- pub fn init_logger() -> tracing_appender::non_blocking::WorkerGuard {
26
- let file_appender =
27
- RollingFileAppender::new(Rotation::NEVER, "./", "rust_log.txt");
28
- let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
29
- let subscriber = fmt::Subscriber::builder()
30
- .with_max_level(Level::TRACE)
31
- .with_writer(non_blocking)
32
- .with_ansi(false)
33
- .with_line_number(true)
34
- .finish();
35
-
36
- let _ = tracing::subscriber::set_global_default(subscriber);
37
-
25
+ pub fn init_logger() -> Option<tracing_appender::non_blocking::WorkerGuard> {
26
+ #[cfg(feature = "debugfile")]
27
+ let _guard = {
28
+ let file_appender =
29
+ RollingFileAppender::new(Rotation::NEVER, "./", "rust_log.txt");
30
+ let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
31
+ let subscriber = fmt::Subscriber::builder()
32
+ .with_max_level(Level::TRACE)
33
+ .with_writer(non_blocking)
34
+ .with_ansi(false)
35
+ .with_line_number(true)
36
+ .finish();
37
+
38
+ let _ = tracing::subscriber::set_global_default(subscriber);
39
+ Some(_guard)
40
+ };
41
+ #[cfg(not(feature = "debugfile"))]
42
+ let _guard = { None };
38
43
  _guard
39
44
  }
40
45
 
@@ -62,13 +67,20 @@ impl MerkleClient {
62
67
  }
63
68
 
64
69
  #[napi]
65
- pub async unsafe fn init(&mut self, git_ignored_files: Vec<String>, is_git_repo: bool) -> Result<(), napi::Error> {
70
+ pub async unsafe fn init(
71
+ &mut self,
72
+ git_ignored_files: Vec<String>,
73
+ is_git_repo: bool,
74
+ ) -> Result<(), napi::Error> {
66
75
  // 1. compute the merkle tree
67
76
  // 2. update the backend
68
77
  // 3. sync with the remote
69
78
  info!("Merkle tree compute started!");
79
+ info!("Root directory: {:?}", self.absolute_root_directory);
70
80
  unsafe {
71
- self.compute_merkle_tree(git_ignored_files, is_git_repo).await?;
81
+ self
82
+ .compute_merkle_tree(git_ignored_files, is_git_repo)
83
+ .await?;
72
84
  }
73
85
 
74
86
  Ok(())
@@ -82,14 +94,19 @@ impl MerkleClient {
82
94
  pub async unsafe fn compute_merkle_tree(
83
95
  &mut self,
84
96
  git_ignored_files: Vec<String>,
85
- is_git_repo: bool
97
+ is_git_repo: bool,
86
98
  ) -> Result<(), napi::Error> {
87
99
  // make the git ignored files into a hash set
88
100
  let git_ignored_set = HashSet::from_iter(git_ignored_files.into_iter());
89
101
 
90
- let t =
91
- MerkleTree::construct_merkle_tree(self.absolute_root_directory.clone(), git_ignored_set, is_git_repo)
92
- .await;
102
+ info!("Git ignored set: {:?}", git_ignored_set);
103
+
104
+ let t = MerkleTree::construct_merkle_tree(
105
+ self.absolute_root_directory.clone(),
106
+ git_ignored_set,
107
+ is_git_repo,
108
+ )
109
+ .await;
93
110
 
94
111
  match t {
95
112
  Ok(tree) => {
@@ -66,7 +66,7 @@ impl LocalConstruction for MerkleTree {
66
66
  files: BTreeMap::new(),
67
67
  root_path: absolute_path_to_root_directory,
68
68
  cursor: None,
69
- git_ignored_files_and_dirs: git_ignored_files_and_dirs,
69
+ git_ignored_files_and_dirs,
70
70
  is_git_repo
71
71
  };
72
72
 
@@ -322,16 +322,13 @@ impl MerkleTree {
322
322
  &self,
323
323
  absolute_path: &str,
324
324
  ) -> Result<Vec<String>, anyhow::Error> {
325
- info!("get_spline called with absolute_path: {}", absolute_path);
326
325
  let mut files = Vec::new();
327
326
 
328
327
  let current_node = match self.files.get(absolute_path) {
329
328
  Some(node) => {
330
- info!("Found node for absolute_path: {}", absolute_path);
331
329
  node.node.clone()
332
330
  }
333
331
  None => {
334
- info!("File not found for absolute_path: {}", absolute_path);
335
332
  return Err(anyhow::anyhow!("File not found: {}", absolute_path));
336
333
  }
337
334
  };
@@ -342,7 +339,6 @@ impl MerkleTree {
342
339
  while let Some(node) = stack.pop() {
343
340
  let parent = node.read().await.parent.clone();
344
341
  if let Some(parent) = parent {
345
- info!("Adding parent hash to files vector");
346
342
  {
347
343
  let parent_node = parent.read().await;
348
344
  match &parent_node.node_type {
@@ -361,7 +357,6 @@ impl MerkleTree {
361
357
  stack.push(parent);
362
358
  }
363
359
  }
364
- info!("Returning files vector with {} elements", files.len());
365
360
  Ok(files)
366
361
  }
367
362
 
@@ -749,7 +744,6 @@ impl MerkleNode {
749
744
  "constructing node for absolute_file_or_directory: {:?}",
750
745
  absolute_file_or_directory
751
746
  );
752
- info!("bypass_git: {}, is_git_repo: {}", bypass_git, is_git_repo);
753
747
 
754
748
  MerkleNode::construct_node(
755
749
  Path::new(&absolute_file_or_directory),