fix(conversation): tolerate non-path-safe ids when cleaning attachments (issue #36)

This commit is contained in:
matevip 2026-04-29 15:07:36 +08:00
parent 8ad0fca4ef
commit 0ecfec474e

View File

@ -21,6 +21,7 @@ import vip.mate.workspace.conversation.vo.MessageVO;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
@ -791,7 +792,17 @@ public class ConversationService {
* 清理会话关联的附件文件
*/
public void cleanAttachmentFiles(String conversationId) {
Path dir = UPLOAD_ROOT.resolve(conversationId);
Path dir;
try {
dir = UPLOAD_ROOT.resolve(conversationId);
} catch (InvalidPathException e) {
// Conversation id contains characters illegal on this filesystem
// (e.g. ':' in cron:<jobId> on Windows). No attachments could
// ever have been written under such an id on this OS, so there
// is nothing to clean.
log.debug("Skipping attachment cleanup for non-path-safe conversation id: {}", conversationId);
return;
}
if (!Files.exists(dir)) {
return;
}