압축해제 시, 동일 폴더가 있으면 삭제 후 재업로드 #114

Merged
gina merged 1 commits from feat/training_260202 into develop 2026-02-18 16:37:14 +09:00

View File

@@ -17,6 +17,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -725,6 +726,11 @@ public class FIleChecker {
File destDir = new File(destDirectory, folderName);
// 동일 폴더가 이미 있으면 삭제
if (destDir.exists()) {
deleteDirectoryRecursively(destDir.toPath());
}
if (!destDir.exists()) {
destDir.mkdirs();
}
@@ -914,4 +920,22 @@ public class FIleChecker {
if (session != null) session.disconnect();
}
}
/** ✅ 폴더 재귀 삭제 */
private static void deleteDirectoryRecursively(Path path) throws IOException {
if (!Files.exists(path)) return;
// 하위부터 지워야 하므로 reverse order
Files.walk(path)
.sorted(Comparator.reverseOrder())
.forEach(
p -> {
try {
Files.deleteIfExists(p);
} catch (IOException e) {
// 여기서 바로 RuntimeException으로 올려서 상위 catch(IOException)로 잡히게 함
throw new UncheckedIOException("폴더 삭제 실패: " + p.toAbsolutePath(), e);
}
});
}
}