Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix install from failing with different /tmp filesystem #36

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/tool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ impl ToolStorage {
// ends up replaced by this process, we'll still have the file that
// we're supposed to be copying.
log::debug!("Copying own executable into temp dir");
let source_dir = tempfile::tempdir()?;
let source_path = source_dir.path().join(self_name);

// Since renaming a file is not supported between multiple filesystems,
// We make a temp directory inside of the home directory.
// This is necessary on Unix as most partitions use a seperate filesystem for /tmp.

let source_dir = &self.home.path().join("tmp");
fs_err::create_dir_all(source_dir)?;

let source_path = source_dir.join(self_name);
fs_err::copy(&self_path, &source_path)?;
let self_path = source_path;

let junk_dir = tempfile::tempdir()?;
let junk_dir = source_dir;
let aftman_name = format!("aftman{EXE_SUFFIX}");
let mut found_aftman = false;

Expand All @@ -118,7 +125,7 @@ impl ToolStorage {

// Copy the executable into a temp directory so that we can replace
// it even if it's currently running.
fs_err::rename(&path, junk_dir.path().join(name))?;
fs_err::rename(&path, junk_dir.join(name))?;
fs_err::copy(&self_path, path)?;
}

Expand All @@ -131,6 +138,9 @@ impl ToolStorage {

log::info!("Updated Aftman binaries successfully!");

// Since the /tmp file is no longer cleaned up automatically, we have to do it manually.
fs_err::remove_dir_all(junk_dir)?;

Ok(())
}

Expand Down