You've already forked DataMate
refactor: 修改调整数据归集实现,删除无用代码,优化代码结构 (#20)
This commit is contained in:
@@ -60,7 +60,7 @@ public class FileService {
|
||||
boolean isFinish = Objects.equals(preRequest.getUploadedFileNum(), preRequest.getTotalFileNum());
|
||||
if (isFinish) {
|
||||
// 删除存分片的临时路径
|
||||
ChunksSaver.deleteFiles(new File(preRequest.getUploadPath(),
|
||||
ChunksSaver.deleteFolder(new File(preRequest.getUploadPath(),
|
||||
String.format(ChunksSaver.TEMP_DIR_NAME_FORMAT, preRequest.getId())).getPath());
|
||||
chunkUploadRequestMapper.deleteById(preRequest.getId());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.datamate.common.domain.utils;
|
||||
|
||||
import com.datamate.common.domain.model.ChunkUploadPreRequest;
|
||||
import com.datamate.common.domain.model.ChunkUploadRequest;
|
||||
import com.datamate.common.infrastructure.exception.BusinessException;
|
||||
import com.datamate.common.infrastructure.exception.SystemErrorCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -106,29 +108,17 @@ public class ChunksSaver {
|
||||
*
|
||||
* @param uploadPath 文件路径
|
||||
*/
|
||||
public static void deleteFiles(String uploadPath) {
|
||||
File dic = new File(uploadPath);
|
||||
if (!dic.exists()) {
|
||||
return;
|
||||
}
|
||||
File[] files = dic.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
dic.delete();
|
||||
public static void deleteFolder(String uploadPath) {
|
||||
File folder = new File(uploadPath);
|
||||
|
||||
if (!folder.exists()) {
|
||||
log.info("folder {} does not exist", uploadPath);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteFiles(file.getPath());
|
||||
} else {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
if (dic.exists()) {
|
||||
dic.delete();
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
log.warn("Fail to delete file", e);
|
||||
FileUtils.deleteDirectory(folder);
|
||||
} catch (IOException e) {
|
||||
throw BusinessException.of(SystemErrorCode.FILE_SYSTEM_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user