fix(文件管理): 修复文件转存时校验文件是否存在方法的bug
This commit is contained in:
parent
43c1ac26dc
commit
06fd44ce12
|
@ -148,7 +148,7 @@ public class FileMetadataService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileMetadata genFileMetadata(String filePath, String storage, long size, boolean enable, String projectId, String moduleId, String operator) {
|
public FileMetadata genFileMetadata(String fileSpecifyName, String filePath, String storage, long size, boolean enable, String projectId, String moduleId, String operator) {
|
||||||
if (size > maxFileSize.toBytes()) {
|
if (size > maxFileSize.toBytes()) {
|
||||||
throw new MSException(Translator.get("file.size.is.too.large"));
|
throw new MSException(Translator.get("file.size.is.too.large"));
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,10 @@ public class FileMetadataService {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
this.checkEnableFile(fileMetadata.getType());
|
this.checkEnableFile(fileMetadata.getType());
|
||||||
}
|
}
|
||||||
|
// 指定了文件名称,则替换原文件名
|
||||||
|
if (StringUtils.isNotBlank(fileSpecifyName)) {
|
||||||
|
fileMetadata.setName(fileSpecifyName);
|
||||||
|
}
|
||||||
//检查处理后的用户名合法性
|
//检查处理后的用户名合法性
|
||||||
if (StringUtils.equals(storage, StorageType.MINIO.name())) {
|
if (StringUtils.equals(storage, StorageType.MINIO.name())) {
|
||||||
this.checkMinIOFileName(null, fileMetadata.getName(), fileMetadata.getType(), projectId);
|
this.checkMinIOFileName(null, fileMetadata.getName(), fileMetadata.getType(), projectId);
|
||||||
|
@ -186,7 +190,7 @@ public class FileMetadataService {
|
||||||
|
|
||||||
String fileName = StringUtils.trim(uploadFile.getOriginalFilename());
|
String fileName = StringUtils.trim(uploadFile.getOriginalFilename());
|
||||||
|
|
||||||
FileMetadata fileMetadata = this.genFileMetadata(fileName, StorageType.MINIO.name(), uploadFile.getSize(), request.isEnable(), request.getProjectId(), request.getModuleId(), operator);
|
FileMetadata fileMetadata = this.genFileMetadata(null, fileName, StorageType.MINIO.name(), uploadFile.getSize(), request.isEnable(), request.getProjectId(), request.getModuleId(), operator);
|
||||||
|
|
||||||
// 上传文件
|
// 上传文件
|
||||||
String filePath = this.uploadFile(fileMetadata, uploadFile);
|
String filePath = this.uploadFile(fileMetadata, uploadFile);
|
||||||
|
@ -215,7 +219,7 @@ public class FileMetadataService {
|
||||||
if (StringUtils.isBlank(originFileName)) {
|
if (StringUtils.isBlank(originFileName)) {
|
||||||
throw new MSException(Translator.get("file.name.cannot.be.empty"));
|
throw new MSException(Translator.get("file.name.cannot.be.empty"));
|
||||||
}
|
}
|
||||||
FileMetadata fileMetadata = this.genFileMetadata(originFileName, StorageType.MINIO.name(), fileBytes.length, false, projectId, moduleId, operator);
|
FileMetadata fileMetadata = this.genFileMetadata(fileName, originFileName, StorageType.MINIO.name(), fileBytes.length, false, projectId, moduleId, operator);
|
||||||
if (StringUtils.isNotBlank(fileName)) {
|
if (StringUtils.isNotBlank(fileName)) {
|
||||||
fileMetadata.setName(fileName);
|
fileMetadata.setName(fileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class FileRepositoryService extends FileModuleService {
|
||||||
if (fileAttachInfo == null || fileAttachInfo.fileIsNotExist()) {
|
if (fileAttachInfo == null || fileAttachInfo.fileIsNotExist()) {
|
||||||
throw new MSException(Translator.get("file.not.exist"));
|
throw new MSException(Translator.get("file.not.exist"));
|
||||||
}
|
}
|
||||||
FileMetadata fileMetadata = fileMetadataService.genFileMetadata(request.getFilePath(), StorageType.GIT.name(), fileAttachInfo.getSize(), request.isEnable(),
|
FileMetadata fileMetadata = fileMetadataService.genFileMetadata(null, request.getFilePath(), StorageType.GIT.name(), fileAttachInfo.getSize(), request.isEnable(),
|
||||||
fileModule.getProjectId(), fileModule.getId(), operator);
|
fileModule.getProjectId(), fileModule.getId(), operator);
|
||||||
|
|
||||||
//判断文件是否存在: 同一存储库下文件路径和分支不能重复
|
//判断文件是否存在: 同一存储库下文件路径和分支不能重复
|
||||||
|
|
Loading…
Reference in New Issue