Refactor file handling in LibraryMergeService to use move instead of copy for audio, lyrics, and cover files. Update MergeTab.vue to include a warning about files being moved to the main library.

This commit is contained in:
liu
2026-01-30 00:17:28 +08:00
parent 89be3ba0bd
commit 7170df2aee
2 changed files with 14 additions and 7 deletions

View File

@@ -141,7 +141,7 @@ public class LibraryMergeService {
targetPath.getFileName().toString() + ".backup"); targetPath.getFileName().toString() + ".backup");
Files.copy(targetPath, backupPath, StandardCopyOption.REPLACE_EXISTING); Files.copy(targetPath, backupPath, StandardCopyOption.REPLACE_EXISTING);
} }
Files.copy(audioFile, targetPath, StandardCopyOption.REPLACE_EXISTING); Files.move(audioFile, targetPath, StandardCopyOption.REPLACE_EXISTING);
wasUpgraded = true; wasUpgraded = true;
upgraded.incrementAndGet(); upgraded.incrementAndGet();
} else { } else {
@@ -166,9 +166,9 @@ public class LibraryMergeService {
continue; continue;
} }
} else { } else {
// 新文件,直接复制 // 新文件,直接移动
Files.createDirectories(targetPath.getParent()); Files.createDirectories(targetPath.getParent());
Files.copy(audioFile, targetPath, StandardCopyOption.REPLACE_EXISTING); Files.move(audioFile, targetPath, StandardCopyOption.REPLACE_EXISTING);
} }
tracksMerged.incrementAndGet(); tracksMerged.incrementAndGet();
@@ -178,7 +178,7 @@ public class LibraryMergeService {
if (lyricsFile != null && Files.exists(lyricsFile)) { if (lyricsFile != null && Files.exists(lyricsFile)) {
Path lyricsTarget = targetPath.resolveSibling(lyricsFile.getFileName().toString()); Path lyricsTarget = targetPath.resolveSibling(lyricsFile.getFileName().toString());
if (!Files.exists(lyricsTarget) || wasUpgraded) { if (!Files.exists(lyricsTarget) || wasUpgraded) {
Files.copy(lyricsFile, lyricsTarget, StandardCopyOption.REPLACE_EXISTING); Files.move(lyricsFile, lyricsTarget, StandardCopyOption.REPLACE_EXISTING);
} }
} }
@@ -189,8 +189,8 @@ public class LibraryMergeService {
if (coverFile != null && Files.exists(coverFile)) { if (coverFile != null && Files.exists(coverFile)) {
Path coverTarget = albumDir.resolve("cover.jpg"); Path coverTarget = albumDir.resolve("cover.jpg");
if (!Files.exists(coverTarget)) { if (!Files.exists(coverTarget)) {
// 目标目录没有封面,直接复制 // 目标目录没有封面,直接移动
Files.copy(coverFile, coverTarget, StandardCopyOption.REPLACE_EXISTING); Files.move(coverFile, coverTarget, StandardCopyOption.REPLACE_EXISTING);
} else { } else {
// 比较封面,保留更好的版本 // 比较封面,保留更好的版本
if (isBetterCover(coverFile, coverTarget)) { if (isBetterCover(coverFile, coverTarget)) {
@@ -198,7 +198,7 @@ public class LibraryMergeService {
Path backupPath = coverTarget.resolveSibling("cover.jpg.backup"); Path backupPath = coverTarget.resolveSibling("cover.jpg.backup");
Files.copy(coverTarget, backupPath, StandardCopyOption.REPLACE_EXISTING); Files.copy(coverTarget, backupPath, StandardCopyOption.REPLACE_EXISTING);
} }
Files.copy(coverFile, coverTarget, StandardCopyOption.REPLACE_EXISTING); Files.move(coverFile, coverTarget, StandardCopyOption.REPLACE_EXISTING);
} }
} }
} }

View File

@@ -36,6 +36,13 @@
</el-input> </el-input>
</el-form-item> </el-form-item>
<div class="strategy-tip merge-tip">
<el-icon class="tip-icon"><Warning /></el-icon>
<div class="tip-content">
<strong>重要提示</strong>文件会<strong>移动</strong>到主库源目录 staging 中的文件会被移走不保留歌词和封面一并移动
</div>
</div>
<el-form-item label="合并策略"> <el-form-item label="合并策略">
<el-checkbox v-model="form.smartUpgrade">启用智能升级</el-checkbox> <el-checkbox v-model="form.smartUpgrade">启用智能升级</el-checkbox>
<el-checkbox v-model="form.keepBackup">保留旧版本备份</el-checkbox> <el-checkbox v-model="form.keepBackup">保留旧版本备份</el-checkbox>