From e7f942e9686b0f7544c5e82ea68c53cec80155d4 Mon Sep 17 00:00:00 2001 From: Joshument <74075169+Joshument@users.noreply.github.com> Date: Sat, 1 Oct 2022 21:05:09 -0400 Subject: [PATCH 1/2] fix install from failing with different /tmp filesystem --- src/tool_storage.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tool_storage.rs b/src/tool_storage.rs index cf5ec27..c4b17bc 100644 --- a/src/tool_storage.rs +++ b/src/tool_storage.rs @@ -118,7 +118,9 @@ 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::copy(&path, junk_dir.path().join(name))?; + + // There is no need to remove original file as this line will overwrite it. fs_err::copy(&self_path, path)?; } From f1ff757529ddf26c11ec36a010fdcc979a1b696f Mon Sep 17 00:00:00 2001 From: Joshument <74075169+Joshument@users.noreply.github.com> Date: Sun, 2 Oct 2022 13:41:59 -0400 Subject: [PATCH 2/2] fix issue with seperate filesystem renaming using own tmp directory --- src/tool_storage.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/tool_storage.rs b/src/tool_storage.rs index c4b17bc..32ef2e3 100644 --- a/src/tool_storage.rs +++ b/src/tool_storage.rs @@ -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; @@ -118,9 +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::copy(&path, junk_dir.path().join(name))?; - - // There is no need to remove original file as this line will overwrite it. + fs_err::rename(&path, junk_dir.join(name))?; fs_err::copy(&self_path, path)?; } @@ -133,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(()) }