압축해제 시, 동일 폴더가 있으면 삭제 후 재업로드 #114
@@ -17,6 +17,7 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -725,6 +726,11 @@ public class FIleChecker {
|
|||||||
|
|
||||||
File destDir = new File(destDirectory, folderName);
|
File destDir = new File(destDirectory, folderName);
|
||||||
|
|
||||||
|
// 동일 폴더가 이미 있으면 삭제
|
||||||
|
if (destDir.exists()) {
|
||||||
|
deleteDirectoryRecursively(destDir.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
if (!destDir.exists()) {
|
if (!destDir.exists()) {
|
||||||
destDir.mkdirs();
|
destDir.mkdirs();
|
||||||
}
|
}
|
||||||
@@ -914,4 +920,22 @@ public class FIleChecker {
|
|||||||
if (session != null) session.disconnect();
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user