하드링크 실패 시 심볼릭 링크로 만들어보기
This commit is contained in:
@@ -74,7 +74,6 @@ public class TmpDatasetService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private long link(Path tmp, String type, String part, String fullPath) throws IOException {
|
private long link(Path tmp, String type, String part, String fullPath) throws IOException {
|
||||||
|
|
||||||
if (fullPath == null || fullPath.isBlank()) return 0;
|
if (fullPath == null || fullPath.isBlank()) return 0;
|
||||||
|
|
||||||
Path src = Path.of(fullPath);
|
Path src = Path.of(fullPath);
|
||||||
@@ -87,12 +86,26 @@ public class TmpDatasetService {
|
|||||||
String fileName = src.getFileName().toString();
|
String fileName = src.getFileName().toString();
|
||||||
Path dst = tmp.resolve(type).resolve(part).resolve(fileName);
|
Path dst = tmp.resolve(type).resolve(part).resolve(fileName);
|
||||||
|
|
||||||
// 충돌 시 덮어쓰기
|
Files.createDirectories(dst.getParent());
|
||||||
|
|
||||||
if (Files.exists(dst)) {
|
if (Files.exists(dst)) {
|
||||||
Files.delete(dst);
|
Files.delete(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
Files.createLink(dst, src);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user