Skip to content

Commit

Permalink
Fix self-replace on windows (#2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 authored Feb 26, 2025
1 parent 55cd1e4 commit b8ebe42
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ rustyline = { version = "12.0.0", features = [] }
scoped-tls = "1.0.1"
scopeguard = "1.1.0"
second-stack = "0.3"
self-replace = "1.5"
semver = "1"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = { version = "1.0.128", features = ["raw_value", "arbitrary_precision"] }
Expand Down
1 change: 1 addition & 0 deletions crates/paths/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl VersionBinDir {
#[cfg(windows)]
{
junction::delete(self).ok();
std::fs::remove_dir(self).ok();
// We won't be able to create a junction if the fs isn't NTFS, so fall back to trying
// to make a symlink.
junction::create(path, self)
Expand Down
1 change: 1 addition & 0 deletions crates/update/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ flate2.workspace = true
http-body-util = "0.1.2"
indicatif.workspace = true
reqwest.workspace = true
self-replace.workspace = true
semver = { workspace = true, features = ["serde"] }
serde.workspace = true
tar.workspace = true
Expand Down
22 changes: 7 additions & 15 deletions crates/update/src/cli/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::io::Write;

use anyhow::Context;
use bytes::Buf;
use spacetimedb_paths::SpacetimePaths;

use super::install::{download_and_install, download_with_progress, make_progress_bar};
Expand All @@ -26,23 +25,16 @@ impl Upgrade {
pb.set_message("installing...");
let cli_bin_file = paths.cli_bin_file.clone();
tokio::task::spawn_blocking(move || {
// TODO(noa): try and see if `self_replace` could support providing the binary
// in a buffer, instead of an already existing file, since we're doing the same
// work they are right now
let mut file = tempfile::NamedTempFile::with_prefix_in(
".spacetimedb-update-tmp",
".spacetimedb-self-replace",
cli_bin_file.0.parent().unwrap(),
)?;
#[cfg(unix)]
file.as_file_mut()
.set_permissions(std::os::unix::fs::PermissionsExt::from_mode(0o755))?;
// TODO(noa): write_all_vectored once stabilized
let mut bin = bin.aggregate();
while bin.has_remaining() {
let chunk = bin.chunk();
file.write_all(chunk)?;
bin.advance(chunk.len());
}
file.persist(cli_bin_file)
.map_err(|e| e.error)
.context("failed to overwrite existing spacetime binary")
file.write_all(&bin.to_bytes())?;
self_replace::self_replace(file.path())
.context("failed to overwrite the original spacetime binary")
})
.await??;

Expand Down

2 comments on commit b8ebe42

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callgrind benchmark in progress...

@github-actions
Copy link

@github-actions github-actions bot commented on b8ebe42 Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Criterion benchmark results

Error when comparing benchmarks: Couldn't find AWS credentials in environment, credentials file, or IAM role.

Caused by:
Couldn't find AWS credentials in environment, credentials file, or IAM role.

Please sign in to comment.