Fix error handling when deleting an attachment file
This commit is contained in:
parent
e4a0066e20
commit
733f26f017
2 changed files with 11 additions and 2 deletions
|
@ -17,7 +17,9 @@
|
||||||
package files
|
package files
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -129,9 +131,16 @@ func (f *File) Delete() (err error) {
|
||||||
|
|
||||||
err = afs.Remove(f.getFileName())
|
err = afs.Remove(f.getFileName())
|
||||||
if err != nil {
|
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()
|
_ = s.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ func TestTaskComment_ReadAll(t *testing.T) {
|
||||||
comments := result.([]*TaskComment)
|
comments := result.([]*TaskComment)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, comments, 2)
|
assert.Len(t, comments, 2)
|
||||||
assert.Equal(t, int64(-2), comments[1].AuthorID)
|
assert.Equal(t, int64(-2), comments[0].AuthorID)
|
||||||
assert.NotNil(t, comments[1].Author)
|
assert.NotNil(t, comments[0].Author)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue