auto(1dc9423ac708): session end @ 2026-06-11T13:42:38 (+1f)
This commit is contained in:
1 parent
4c86353e9f
commit
d3ebd6c63e
1 file changed
+8
-57
@@ -11,7 +11,6 @@ import java.io.IOException;
|
||||
import java.io.Console;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -128,8 +127,10 @@ public class ClearAppCommand implements Callable<Integer> {
|
||||
private boolean skipDb;
|
||||
|
||||
@Option(names = {"--restart"},
|
||||
description = "清理后询问是否立即 initapp 重建一个新 app (Y/N). 不会静默重启")
|
||||
private boolean restart;
|
||||
defaultValue = "true",
|
||||
fallbackValue = "true",
|
||||
description = "清理后询问是否立即 initapp 重建一个新 app (Y/N). 默认开启, 传 --no-restart 跳过")
|
||||
private boolean restart = true;
|
||||
|
||||
@Option(names = {"--workspace"},
|
||||
description = "工程根目录 (默认 \\$ccWorkDir 或当前目录)")
|
||||
@@ -351,7 +352,7 @@ public class ClearAppCommand implements Callable<Integer> {
|
||||
manifest.append("\n");
|
||||
}
|
||||
|
||||
// 6.2 文件备份+删除
|
||||
// 6.2 文件备份+移动 (Files.move 原子 rename, 比 copy+delete 省一半磁盘)
|
||||
if (!fileTargets.isEmpty()) {
|
||||
manifest.append("[Files] ----------------------------\n");
|
||||
Path filesBak = bakRoot.resolve("files");
|
||||
@@ -360,18 +361,9 @@ public class ClearAppCommand implements Callable<Integer> {
|
||||
Path rel = workspace.relativize(t.path);
|
||||
Path dest = filesBak.resolve(rel.toString());
|
||||
Files.createDirectories(dest.getParent());
|
||||
if (t.isDir) {
|
||||
copyTree(t.path, dest);
|
||||
} else {
|
||||
Files.copy(t.path, dest, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
Files.move(t.path, dest, StandardCopyOption.REPLACE_EXISTING);
|
||||
manifest.append("backup file : files/").append(rel).append("\n");
|
||||
if (t.isDir) {
|
||||
deleteTree(t.path);
|
||||
} else {
|
||||
Files.delete(t.path);
|
||||
}
|
||||
println(red(" [DEL] ") + rel + (t.isDir ? "/" : "") + " (已备份)");
|
||||
println(red(" [MOVE] ") + rel + (t.isDir ? "/" : "") + " (已移到 history-bak)");
|
||||
}
|
||||
manifest.append("\n");
|
||||
}
|
||||
@@ -463,14 +455,12 @@ public class ClearAppCommand implements Callable<Integer> {
|
||||
}
|
||||
println(blue(" 还原步骤: " + bakRoot.resolve("MANIFEST.txt")));
|
||||
|
||||
// --restart: 询问是否立即 initapp 重建 (Y/N, opt-in, 不会静默做)
|
||||
// --restart (默认开): 询问是否立即 initapp 重建 (Y/N, 不会静默做)
|
||||
if (restart) {
|
||||
if (maybeInitApp(layout)) {
|
||||
return 0; // initapp 已执行, 不再需要后续
|
||||
}
|
||||
// 用户选 N 或 initapp 失败 → 打印引导
|
||||
} else {
|
||||
println(yellow("\n 提示: 用了 --restart 可在清理后立即调 initapp 重建"));
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -821,45 +811,6 @@ public class ClearAppCommand implements Callable<Integer> {
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// 文件/目录工具
|
||||
// =====================================================================
|
||||
private static void copyTree(Path src, Path dest) throws IOException {
|
||||
Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
|
||||
throws IOException {
|
||||
Path target = dest.resolve(src.relativize(dir).toString());
|
||||
if (!Files.exists(target)) Files.createDirectories(target);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
|
||||
throws IOException {
|
||||
Path target = dest.resolve(src.relativize(file).toString());
|
||||
Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void deleteTree(Path src) throws IOException {
|
||||
Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
|
||||
throws IOException {
|
||||
Files.delete(file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
|
||||
throws IOException {
|
||||
Files.delete(dir);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// 预览渲染
|
||||
// =====================================================================
|
||||
|
||||
Reference in new issue
Block a user