From 60074de844e51c70add95583f7a70ab35bbb6625 Mon Sep 17 00:00:00 2001 From: Ian Whitlock Date: Thu, 26 Aug 2021 12:48:00 -0500 Subject: [PATCH] Don't give up import when importing an attachment fails (#18084) --- app/import_functions.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/import_functions.go b/app/import_functions.go index dfd0ec719d..578ae51dd3 100644 --- a/app/import_functions.go +++ b/app/import_functions.go @@ -1100,10 +1100,7 @@ func (a *App) importReplies(c *request.Context, data []ReplyImportData, post *mo reply.Message = *replyData.Message reply.CreateAt = *replyData.CreateAt - fileIDs, err := a.uploadAttachments(c, replyData.Attachments, reply, teamID) - if err != nil { - return err - } + fileIDs := a.uploadAttachments(c, replyData.Attachments, reply, teamID) for _, fileID := range reply.FileIds { if _, ok := fileIDs[fileID]; !ok { a.Srv().Store.FileInfo().PermanentDelete(fileID) @@ -1380,10 +1377,7 @@ func (a *App) importMultiplePostLines(c *request.Context, lines []LineImportWork post.Props = *line.Post.Props } - fileIDs, appErr := a.uploadAttachments(c, line.Post.Attachments, post, team.Id) - if appErr != nil { - return line.LineNumber, appErr - } + fileIDs := a.uploadAttachments(c, line.Post.Attachments, post, team.Id) for _, fileID := range post.FileIds { if _, ok := fileIDs[fileID]; !ok { a.Srv().Store.FileInfo().PermanentDelete(fileID) @@ -1482,20 +1476,29 @@ func (a *App) importMultiplePostLines(c *request.Context, lines []LineImportWork } // uploadAttachments imports new attachments and returns current attachments of the post as a map -func (a *App) uploadAttachments(c *request.Context, attachments *[]AttachmentImportData, post *model.Post, teamID string) (map[string]bool, *model.AppError) { +func (a *App) uploadAttachments(c *request.Context, attachments *[]AttachmentImportData, post *model.Post, teamID string) map[string]bool { if attachments == nil { - return nil, nil + return nil } fileIDs := make(map[string]bool) for _, attachment := range *attachments { attachment := attachment fileInfo, err := a.importAttachment(c, &attachment, post, teamID) if err != nil { - return nil, err + if attachment.Path != nil { + mlog.Warn( + "failed to import attachment", + mlog.String("path", *attachment.Path), + mlog.String("error", err.Error())) + } else { + mlog.Warn("failed to import attachment; path was nil", + mlog.String("error", err.Error())) + } + continue } fileIDs[fileInfo.Id] = true } - return fileIDs, nil + return fileIDs } func (a *App) updateFileInfoWithPostId(post *model.Post) { @@ -1676,10 +1679,7 @@ func (a *App) importMultipleDirectPostLines(c *request.Context, lines []LineImpo post.Props = *line.DirectPost.Props } - fileIDs, err := a.uploadAttachments(c, line.DirectPost.Attachments, post, "noteam") - if err != nil { - return line.LineNumber, err - } + fileIDs := a.uploadAttachments(c, line.DirectPost.Attachments, post, "noteam") for _, fileID := range post.FileIds { if _, ok := fileIDs[fileID]; !ok { a.Srv().Store.FileInfo().PermanentDelete(fileID)