하드링크 실패 시 심볼릭 링크로 만들어보기

This commit is contained in:
2026-03-10 16:56:35 +09:00
parent 6c98a48a5d
commit fe6d37456d

View File

@@ -74,7 +74,6 @@ public class TmpDatasetService {
}
private long link(Path tmp, String type, String part, String fullPath) throws IOException {
if (fullPath == null || fullPath.isBlank()) return 0;
Path src = Path.of(fullPath);
@@ -87,12 +86,26 @@ public class TmpDatasetService {
String fileName = src.getFileName().toString();
Path dst = tmp.resolve(type).resolve(part).resolve(fileName);
// 충돌 시 덮어쓰기
Files.createDirectories(dst.getParent());
if (Files.exists(dst)) {
Files.delete(dst);
}
Files.createLink(dst, src);
try {
Files.createLink(dst, src);
log.info("hardlink created: {} -> {}", dst, src);
} catch (FileSystemException e) {
if (e.getMessage() != null && e.getMessage().contains("Invalid cross-device link")) {
log.warn(
"Hardlink failed due to cross-device link. Fallback to symlink. src={}, dst={}",
src,
dst);
Files.createSymbolicLink(dst, src);
} else {
throw e;
}
}
return 1;
}