Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Commit c20ee9a

Browse files
committed
fix: let move_across_dir to deal with non-exist dst
1 parent 28d2387 commit c20ee9a

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

cli/src/fs/moving.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,47 @@ mod tests {
652652
});
653653
}
654654

655+
#[test]
656+
fn test_move_elements_across_dir_nonexistent_target() {
657+
smol::block_on(async {
658+
let temp_dir = tempdir().expect("Failed to create temp directory");
659+
let src_dir = temp_dir.path().join("src");
660+
let dst_dir = temp_dir.path().join("nonexistent_dst");
661+
662+
// Create source directory structure
663+
fs::create_dir_all(&src_dir)
664+
.await
665+
.expect("Failed to create source directory");
666+
create_test_structure(&src_dir)
667+
.await
668+
.expect("Failed to create test structure");
669+
670+
let replace_options = ReplaceOptions::default();
671+
let result = move_elements_across_dir(&src_dir, &dst_dir, replace_options).await;
672+
assert!(
673+
result.is_ok(),
674+
"Moving to non-existent target should succeed"
675+
);
676+
677+
// Verify the entire directory was moved (renamed)
678+
assert!(!src_dir.exists(), "Source directory should not exist");
679+
assert!(dst_dir.exists(), "Target directory should exist");
680+
681+
// Verify all files were moved
682+
let expected_files = [
683+
("file1.txt", "content1"),
684+
("file2.bms", "content2"),
685+
("subdir/file3.txt", "content3"),
686+
("subdir/nested/file4.txt", "content4"),
687+
];
688+
verify_structure(&dst_dir, &expected_files)
689+
.await
690+
.expect("Failed to verify structure");
691+
692+
cleanup_test_dir(&temp_dir).await;
693+
});
694+
}
695+
655696
#[test]
656697
fn test_move_elements_across_dir_with_ext_specific_rules() {
657698
smol::block_on(async {

cli/src/options/rawpack.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ pub async fn unzip_numeric_to_bms_folder(
9292
root_dir.join(id_str)
9393
};
9494

95-
if !target_dir_path.exists() {
96-
fs::create_dir_all(&target_dir_path).await?;
97-
}
98-
9995
// Move cache to bms dir
10096
info!(
10197
" > Moving files in {} to {}",
@@ -200,11 +196,6 @@ pub async fn unzip_with_name_to_bms_folder(
200196

201197
let target_dir_path = root_dir.join(file_name_without_ext);
202198

203-
// Create New Target dir
204-
if !target_dir_path.exists() {
205-
fs::create_dir_all(&target_dir_path).await?;
206-
}
207-
208199
// Move cache to bms dir
209200
info!(
210201
" > Moving files in {} to {}",

cli/src/options/work.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ pub async fn set_name_by_bms(
138138
target_work_dir.display()
139139
);
140140
if !dry_run {
141-
fs::DirBuilder::new()
142-
.recursive(true)
143-
.create(&target_work_dir)
144-
.await?;
145141
move_elements_across_dir(
146142
work_dir,
147143
target_work_dir,

0 commit comments

Comments
 (0)