Skip to content

Commit 75cd9c9

Browse files
committed
fix cross device link error on ubuntu
1 parent 4d23e1d commit 75cd9c9

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

crates/core/src/bridge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77
use version_compare::Version;
88

9-
use crate::github;
9+
use crate::{github, utils};
1010

1111
#[cfg(target_os = "windows")]
1212
const EXE_SUFFIX: &'static str = ".exe";
@@ -127,7 +127,7 @@ fn install() -> Result<PathBuf> {
127127

128128
tracing::debug!("New Bridge version found {}", release.tag_name);
129129

130-
fs::rename(downloaded_file, &path)?;
130+
utils::move_file(&downloaded_file, &path)?;
131131
fs::write(version_path()?, release.tag_name)?;
132132

133133
#[cfg(any(target_os = "linux", target_os = "macos"))]

crates/core/src/defold_annotations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{Context, Result, bail};
88
use version_compare::Version;
99
use zip::ZipArchive;
1010

11-
use crate::{github, project};
11+
use crate::{github, project, utils};
1212

1313
const OWNER: &str = "astrochili";
1414
const REPOSITORY: &str = "defold-annotations";
@@ -112,7 +112,7 @@ pub fn install() -> Result<()> {
112112
);
113113
}
114114

115-
fs::rename(defold_api_dir, defold_dir)?;
115+
utils::move_file(&defold_api_dir, &defold_dir)?;
116116
fs::write(version_path()?, release.tag_name)?;
117117

118118
github::clear_downloads(OWNER, REPOSITORY)?;

crates/core/src/mobdap.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ pub fn update_or_install() -> Result<PathBuf> {
119119
use std::os::unix::fs::PermissionsExt;
120120
use tar::Archive;
121121

122+
use crate::utils;
123+
122124
let tar = GzDecoder::new(file);
123125
let mut archive = Archive::new(tar);
124126
archive.unpack(&parent_dir)?;
@@ -131,7 +133,7 @@ pub fn update_or_install() -> Result<PathBuf> {
131133

132134
fs::set_permissions(&mobdap_path, Permissions::from_mode(0o700))?;
133135

134-
fs::rename(mobdap_path, path()?)?;
136+
utils::move_file(&mobdap_path, &path()?)?;
135137
}
136138

137139
#[cfg(target_os = "windows")]
@@ -147,7 +149,7 @@ pub fn update_or_install() -> Result<PathBuf> {
147149
bail!("mobdap doesnt exist after unpacking?");
148150
}
149151

150-
fs::rename(mobdap_path, path()?)?;
152+
utils::move_file(&mobdap_path, &path()?)?;
151153
}
152154

153155
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]

crates/core/src/neovide.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub fn update_or_install() -> Result<PathBuf> {
120120
use std::os::unix::fs::PermissionsExt;
121121
use tar::Archive;
122122

123+
use crate::utils;
124+
123125
let tar = GzDecoder::new(file);
124126
let mut archive = Archive::new(tar);
125127
archive.unpack(&parent_dir)?;
@@ -132,7 +134,7 @@ pub fn update_or_install() -> Result<PathBuf> {
132134

133135
fs::set_permissions(&neovide_path, Permissions::from_mode(0o700))?;
134136

135-
fs::rename(neovide_path, path()?)?;
137+
utils::move_file(&neovide_path, &path()?)?;
136138
}
137139

138140
#[cfg(target_os = "windows")]
@@ -148,7 +150,7 @@ pub fn update_or_install() -> Result<PathBuf> {
148150
bail!("Neovide doesnt exist after unpacking?");
149151
}
150152

151-
fs::rename(neovide_path, path()?)?;
153+
utils::move_file(&neovide_path, &path()?)?;
152154
}
153155

154156
#[cfg(not(any(target_os = "linux", target_os = "windows")))]

crates/core/src/utils.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,19 @@ pub fn delete_empty_dirs_from(root_dir: &Path) -> Result<()> {
8383
}
8484
Ok(())
8585
}
86+
87+
// Apparently fs::rename doesnt work on tmpfs
88+
pub fn move_file(from: &Path, to: &Path) -> Result<()> {
89+
if let Err(err) = fs::rename(from, to) {
90+
// EXDEV: Cross-device link
91+
if err.raw_os_error() == Some(18) {
92+
fs::copy(from, to)?;
93+
fs::remove_file(from)?;
94+
return Ok(());
95+
}
96+
97+
return Err(err.into());
98+
}
99+
100+
Ok(())
101+
}

0 commit comments

Comments
 (0)