diff --git a/Cargo.lock b/Cargo.lock index fbd55c2..7bf95e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -370,6 +370,7 @@ dependencies = [ "croner", "dashmap", "dirs", + "dunce", "enum_dispatch", "float-ord", "futures", @@ -1087,6 +1088,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "either" version = "1.15.0" diff --git a/Cargo.toml b/Cargo.toml index 556fad8..4ff066d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ croner = "3.0.1" dashmap = "6.1.0" derivative = "2.2.0" dirs = "6.0.0" +dunce = "1.0.5" enum_dispatch = "0.3.13" float-ord = "0.3.2" futures = "0.3.31" diff --git a/crates/bili_sync/Cargo.toml b/crates/bili_sync/Cargo.toml index 31482bb..9caa4a6 100644 --- a/crates/bili_sync/Cargo.toml +++ b/crates/bili_sync/Cargo.toml @@ -24,6 +24,7 @@ cookie = { workspace = true } croner = { workspace = true } dashmap = { workspace = true } dirs = { workspace = true } +dunce = { workspace = true } enum_dispatch = { workspace = true } float-ord = { workspace = true } futures = { workspace = true } diff --git a/crates/bili_sync/src/workflow.rs b/crates/bili_sync/src/workflow.rs index 3aa16b2..39fde5e 100644 --- a/crates/bili_sync/src/workflow.rs +++ b/crates/bili_sync/src/workflow.rs @@ -236,14 +236,8 @@ pub async fn download_video_pages( .path_safe_render("video", &video_format_args(&video_model, &cx.config.time_format))?, ) }; - - #[cfg(target_family = "windows")] - // windows 系统不允许文件和文件夹以空格结尾,文件有拓展名不会出错,但文件夹可能以空格结尾,需要处理下 - // 此处如果不做修改,创建文件夹操作可以成功,系统会自动创建一个无结尾空格的版本 - // 但由于该路径还用于后续的路径拼接,如果不处理,其它文件路径拼接时使用的还是带结尾空格的版本 - // 导致拼接完的路径不合法,后续的文件操作失败,提示“系统找不到指定的路径” - let base_path = PathBuf::from(base_path.to_string_lossy().trim_end()); - + fs::create_dir_all(&base_path).await?; + let base_path = dunce::canonicalize(base_path).context("canonicalize video path failed")?; let upper_id = video_model.upper_id.to_string(); let base_upper_path = cx .config @@ -424,6 +418,7 @@ pub async fn download_page( )?, ) }; + let base_path = dunce::canonicalize(base_path).context("canonicalize base path failed")?; let (poster_path, video_path, nfo_path, danmaku_path, fanart_path, subtitle_path) = if is_single_page { ( base_path.join(format!("{}-poster.jpg", &base_name)),