Don't give up import when importing an attachment fails (#18084)

Этот коммит содержится в:
Ian Whitlock
2021-08-26 12:48:00 -05:00
коммит произвёл GitHub
родитель 5953df22d0
Коммит 60074de844

Просмотреть файл

@@ -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)