Skip to content

Commit

Permalink
lib: remove use of zstd
Browse files Browse the repository at this point in the history
`zstd` is only used to write files in the native backend right now. For now,
jettison it, to unbundle some C code that we don't really need.

(Ideally, a future compression library would be pure Rust, but we'll cross that
bridge when we get to it...)

Signed-off-by: Austin Seipp <[email protected]>
  • Loading branch information
thoughtpolice committed Jan 8, 2025
1 parent 02a7589 commit 992066c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 40 deletions.
30 changes: 0 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ version_check = "0.9.5"
watchman_client = { version = "0.9.0" }
whoami = "1.5.2"
winreg = "0.52"
zstd = "0.12.4"

# put all inter-workspace libraries, i.e. those that use 'path = ...' here in
# their own (alphabetically sorted) block
Expand Down
6 changes: 2 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@
openssh
] ++ linuxNativeDeps;
buildInputs = with pkgs; [
openssl zstd libgit2 libssh2
openssl libgit2 libssh2
] ++ darwinDeps;

ZSTD_SYS_USE_PKG_CONFIG = "1";
LIBSSH2_SYS_USE_PKG_CONFIG = "1";
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
NIX_JJ_GIT_HASH = self.rev or "";
Expand Down Expand Up @@ -175,7 +174,7 @@
})

# Foreign dependencies
openssl zstd libgit2 libssh2
openssl libgit2 libssh2
pkg-config

# Additional tools recommended by contributing.md
Expand Down Expand Up @@ -204,7 +203,6 @@

shellHook = ''
export RUST_BACKTRACE=1
export ZSTD_SYS_USE_PKG_CONFIG=1
export LIBSSH2_SYS_USE_PKG_CONFIG=1
export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}"
Expand Down
1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ tokio = { workspace = true, optional = true }
toml_edit = { workspace = true }
tracing = { workspace = true }
watchman_client = { workspace = true, optional = true }
zstd = { workspace = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions lib/src/local_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl Backend for LocalBackend {
async fn read_file(&self, _path: &RepoPath, id: &FileId) -> BackendResult<Box<dyn Read>> {
let path = self.file_path(id);
let file = File::open(path).map_err(|err| map_not_found_err(err, id))?;
Ok(Box::new(zstd::Decoder::new(file).map_err(to_other_err)?))
Ok(Box::new(file))
}

async fn write_file(
Expand All @@ -196,7 +196,7 @@ impl Backend for LocalBackend {
contents: &mut (dyn Read + Send),
) -> BackendResult<FileId> {
let temp_file = NamedTempFile::new_in(&self.path).map_err(to_other_err)?;
let mut encoder = zstd::Encoder::new(temp_file.as_file(), 0).map_err(to_other_err)?;
let mut file = temp_file.as_file();
let mut hasher = Blake2b512::new();
let mut buff: Vec<u8> = vec![0; 1 << 14];
loop {
Expand All @@ -205,10 +205,10 @@ impl Backend for LocalBackend {
break;
}
let bytes = &buff[..bytes_read];
encoder.write_all(bytes).map_err(to_other_err)?;
file.write_all(bytes).map_err(to_other_err)?;
hasher.update(bytes);
}
encoder.finish().map_err(to_other_err)?;
file.flush().map_err(to_other_err)?;
let id = FileId::new(hasher.finalize().to_vec());

persist_content_addressed_temp_file(temp_file, self.file_path(&id))
Expand Down

0 comments on commit 992066c

Please sign in to comment.