You've already forked DataMate
fix: 修复 Codex 审查发现的两个数据一致性问题
- [P1] 调整删除顺序:先删除数据库记录,成功后再删除派生文件
避免源文件删除失败时派生文件已被删除导致的数据不一致
- [P2] 完善 logicalPath 空值判断:使用 StringUtils.isBlank() 处理
null、空字符串和纯空白字符,防止误删其他文件
Fixes review comments from commits f9f4ea3
This commit is contained in:
@@ -36,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
@@ -587,8 +588,8 @@ public class DatasetFileApplicationService {
|
|||||||
}
|
}
|
||||||
String logicalPath = file.getLogicalPath();
|
String logicalPath = file.getLogicalPath();
|
||||||
|
|
||||||
// 如果 logicalPath 为 null,直接删除当前文件(兼容旧数据)
|
// 如果 logicalPath 为 null、空字符串或纯空白字符,直接删除当前文件(兼容旧数据)
|
||||||
if (logicalPath == null) {
|
if (StringUtils.isBlank(logicalPath)) {
|
||||||
deleteDatasetFileInternal(datasetId, file);
|
deleteDatasetFileInternal(datasetId, file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -606,10 +607,7 @@ public class DatasetFileApplicationService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSourceDocument(file)) {
|
// 先删除数据库记录,确保数据库操作成功后再清理派生文件
|
||||||
deleteDerivedTextFileQuietly(datasetId, file.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
datasetFileRepository.removeById(file.getId());
|
datasetFileRepository.removeById(file.getId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -618,6 +616,11 @@ public class DatasetFileApplicationService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 数据库删除成功后,再删除派生文件
|
||||||
|
if (isSourceDocument(file)) {
|
||||||
|
deleteDerivedTextFileQuietly(datasetId, file.getId());
|
||||||
|
}
|
||||||
|
|
||||||
if (!isArchivedStatus(file)) {
|
if (!isArchivedStatus(file)) {
|
||||||
try {
|
try {
|
||||||
dataset.setFiles(new ArrayList<>(Collections.singleton(file)));
|
dataset.setFiles(new ArrayList<>(Collections.singleton(file)));
|
||||||
|
|||||||
Reference in New Issue
Block a user