From 733f26f017c6227ff07fdc56b9a309fd212d16cb Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 20 Jul 2021 10:14:49 +0200 Subject: [PATCH] Fix error handling when deleting an attachment file --- pkg/files/files.go | 9 +++++++++ pkg/models/task_comments_test.go | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/files/files.go b/pkg/files/files.go index b24a7b6d..1357434d 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -17,7 +17,9 @@ package files import ( + "code.vikunja.io/api/pkg/log" "io" + "os" "strconv" "time" @@ -129,9 +131,16 @@ func (f *File) Delete() (err error) { err = afs.Remove(f.getFileName()) if err != nil { + if e, is := err.(*os.PathError); is { + // Don't fail when removing the file failed + log.Errorf("Error deleting file %d: %s", e.Error()) + return s.Commit() + } + _ = s.Rollback() return err } + return } diff --git a/pkg/models/task_comments_test.go b/pkg/models/task_comments_test.go index ecc16ae0..ea272e27 100644 --- a/pkg/models/task_comments_test.go +++ b/pkg/models/task_comments_test.go @@ -195,7 +195,7 @@ func TestTaskComment_ReadAll(t *testing.T) { comments := result.([]*TaskComment) assert.NoError(t, err) assert.Len(t, comments, 2) - assert.Equal(t, int64(-2), comments[1].AuthorID) - assert.NotNil(t, comments[1].Author) + assert.Equal(t, int64(-2), comments[0].AuthorID) + assert.NotNil(t, comments[0].Author) }) }