fix(files): configure the files path in files init instead of globally
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This fixes a regression introduced in daa7ad053c35a97933ca79aee007c388538bab5d where the root path would be included twice in the file path, leading to retrieval issues.
This commit is contained in:
parent
287d4f7de2
commit
5478acfc09
@ -487,13 +487,6 @@ func InitConfig() {
|
||||
log.Warning("service.enablemetrics is deprecated and will be removed in a future release. Please use metrics.enable.")
|
||||
MetricsEnabled.Set(true)
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(FilesBasePath.GetString(), "/") {
|
||||
FilesBasePath.Set(filepath.Join(
|
||||
ServiceRootpath.GetString(),
|
||||
FilesBasePath.GetString(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
func random(length int) (string, error) {
|
||||
|
@ -18,8 +18,11 @@ package files
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||
@ -32,16 +35,27 @@ import (
|
||||
var fs afero.Fs
|
||||
var afs *afero.Afero
|
||||
|
||||
func setDefaultConfig() {
|
||||
if !strings.HasPrefix(config.FilesBasePath.GetString(), "/") {
|
||||
config.FilesBasePath.Set(filepath.Join(
|
||||
config.ServiceRootpath.GetString(),
|
||||
config.FilesBasePath.GetString(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// InitFileHandler creates a new file handler for the file backend we want to use
|
||||
func InitFileHandler() {
|
||||
fs = afero.NewOsFs()
|
||||
afs = &afero.Afero{Fs: fs}
|
||||
setDefaultConfig()
|
||||
}
|
||||
|
||||
// InitTestFileHandler initializes a new memory file system for testing
|
||||
func InitTestFileHandler() {
|
||||
fs = afero.NewMemMapFs()
|
||||
afs = &afero.Afero{Fs: fs}
|
||||
setDefaultConfig()
|
||||
}
|
||||
|
||||
func initFixtures(t *testing.T) {
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
@ -59,12 +58,7 @@ func (*File) TableName() string {
|
||||
}
|
||||
|
||||
func (f *File) getAbsoluteFilePath() string {
|
||||
base := ""
|
||||
if !strings.HasPrefix(config.FilesBasePath.GetString(), "/") {
|
||||
base = config.ServiceRootpath.GetString()
|
||||
}
|
||||
return filepath.Join(
|
||||
base,
|
||||
config.FilesBasePath.GetString(),
|
||||
strconv.FormatInt(f.ID, 10),
|
||||
)
|
||||
|
@ -51,7 +51,7 @@ func TestTaskAttachment_ReadOne(t *testing.T) {
|
||||
// Load the actual attachment file and check its content
|
||||
err = ta.File.LoadFileByID()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, filepath.Join(config.ServiceRootpath.GetString(), config.FilesBasePath.GetString(), "/1"), ta.File.File.Name())
|
||||
assert.Equal(t, filepath.Join(config.ServiceRootpath.GetString(), "files", "1"), ta.File.File.Name())
|
||||
content := make([]byte, 9)
|
||||
read, err := ta.File.File.Read(content)
|
||||
require.NoError(t, err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user