From f5c7f90d19d62fdc955fa78521ec5740d8b7cc63 Mon Sep 17 00:00:00 2001 From: Jackson Kruger Date: Mon, 30 Oct 2023 20:27:30 -0500 Subject: [PATCH] Fix handling of paths longer than 260 chars on Windows during export (#847) --- theseus/src/error.rs | 3 +++ theseus/src/state/profiles.rs | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/theseus/src/error.rs b/theseus/src/error.rs index d036a1051..2ea915c84 100644 --- a/theseus/src/error.rs +++ b/theseus/src/error.rs @@ -34,6 +34,9 @@ pub enum ErrorKind { #[error("I/O error: {0}")] IOError(#[from] util::io::IOError), + #[error("I/O (std) error: {0}")] + StdIOError(#[from] std::io::Error), + #[error("Error launching Minecraft: {0}")] LauncherError(String), diff --git a/theseus/src/state/profiles.rs b/theseus/src/state/profiles.rs index add80b399..b62f9854d 100644 --- a/theseus/src/state/profiles.rs +++ b/theseus/src/state/profiles.rs @@ -142,10 +142,13 @@ pub struct ProjectPathId(pub PathBuf); impl ProjectPathId { // Create a new ProjectPathId from a full file path pub async fn from_fs_path(path: &PathBuf) -> crate::Result { - let profiles_dir: PathBuf = io::canonicalize( + // This is avoiding dunce::canonicalize deliberately. On Windows, paths will always be convert to UNC, + // but this is ok because we are stripping that with the prefix. Using std::fs avoids different behaviors with dunce that + // come with too-long paths + let profiles_dir: PathBuf = std::fs::canonicalize( State::get().await?.directories.profiles_dir().await, )?; - let path: PathBuf = io::canonicalize(path)?; + let path: PathBuf = std::fs::canonicalize(path)?; let path = path .strip_prefix(profiles_dir) .ok()