[파일 업로드] tusHook 작업
- 파일 이동작업
This commit is contained in:
@@ -320,6 +320,7 @@ public class FileService {
|
||||
// 1회 빠른 이동 시도 (성공하면 MOVE_YN=Y)
|
||||
tryMoveNowByFileUuid(tusHookDto.getFileUuid());
|
||||
} catch (Exception moveEx) {
|
||||
log.error("Immediate move failed. fileUuid={}", tusHookDto.getFileUuid(), moveEx);
|
||||
// 실패하면 큐 처리 대상으로 남기기 (MOVE_YN=N, 에러 기록)
|
||||
markMovePending(tusHookDto.getFileUuid(), truncateErr(moveEx.getMessage()));
|
||||
}
|
||||
@@ -332,26 +333,25 @@ public class FileService {
|
||||
public void tryMoveNowByFileUuid(String fileUuid) throws IOException {
|
||||
FileMoveTaskDto task = fileMapper.selectMoveTaskByFileUuid(fileUuid);
|
||||
if (task == null) return;
|
||||
if (!"N".equalsIgnoreCase(task.getMoveYn())) return;
|
||||
|
||||
// 임시 경로 계산 (운영 경로 규칙에 맞게 구현)
|
||||
Path tmpPath = resolveTmpPath(task); // ex) /uploads/tmp/{tusUploadId}
|
||||
Path finalPath = buildFinalPath(task); // ex) /uploads/{yyyy}/{MM}/{uuid}.{ext}
|
||||
if (task.getMoveYn() != null && !"N".equalsIgnoreCase(task.getMoveYn())) return;
|
||||
|
||||
Path tmpPath = resolveTmpPath(task);
|
||||
Path finalPath = buildFinalPath(task);
|
||||
Files.createDirectories(finalPath.getParent());
|
||||
|
||||
try {
|
||||
Files.move(tmpPath, finalPath, StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (AtomicMoveNotSupportedException ex) {
|
||||
// cross-device 대비 fallback
|
||||
Files.copy(tmpPath, finalPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.deleteIfExists(tmpPath);
|
||||
} catch (Exception ex) {
|
||||
log.error("Move failed. fileUuid={}, tmpPath={}, finalPath={}", fileUuid, tmpPath, finalPath, ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
task.setSavePath(toSavePath(finalPath)); // DB 저장용 상대경로
|
||||
task.setSavePath(toSavePath(finalPath));
|
||||
task.setSaveName(finalPath.getFileName().toString());
|
||||
task.setExt(extractExt(task.getSaveName()));
|
||||
|
||||
fileMapper.updateFileMoveSuccess(task);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user