Set session and indexers' data files rel to AppDataPath (#2192)

* Set session and indexers' data files rel to AppDataPath

The setting AppDataPath is now relative to the working directory.
The session svc's PROVIDER_CONFIG now defaults to AppDataPath/data/sessions.
The issue indexer's IssuePath now defaults to AppDataPath/indexers/issues.bleves.

* fix bug
This commit is contained in:
Guillaume Dube 2017-11-03 04:56:20 -04:00 committed by Lauris BH
parent 95637e046f
commit 8798cf4e3b
5 changed files with 73 additions and 74 deletions

View file

@ -11,11 +11,11 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"strings"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
// Needed for the MySQL driver
_ "github.com/go-sql-driver/mysql"
@ -152,11 +152,15 @@ func LoadConfigs() {
DbCfg.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
sec = setting.Cfg.Section("indexer")
setting.Indexer.IssuePath = absolutePath(
sec.Key("ISSUE_INDEXER_PATH").MustString("indexers/issues.bleve"))
setting.Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(setting.AppDataPath, "indexers/issues.bleve"))
if !filepath.IsAbs(setting.Indexer.IssuePath) {
setting.Indexer.IssuePath = path.Join(setting.AppWorkPath, setting.Indexer.IssuePath)
}
setting.Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
setting.Indexer.RepoPath = absolutePath(
sec.Key("REPO_INDEXER_PATH").MustString("indexers/repos.bleve"))
setting.Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(setting.AppDataPath, "indexers/repos.bleve"))
if !filepath.IsAbs(setting.Indexer.RepoPath) {
setting.Indexer.RepoPath = path.Join(setting.AppWorkPath, setting.Indexer.RepoPath)
}
setting.Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
setting.Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(512 * 1024 * 1024)
}
@ -343,12 +347,3 @@ func DumpDatabase(filePath string, dbType string) error {
}
return x.DumpTablesToFile(tbs, filePath)
}
// absolutePath make path absolute if it is relative
func absolutePath(path string) string {
workDir, err := setting.WorkDir()
if err != nil {
log.Fatal(4, "Failed to get work directory: %v", err)
}
return util.EnsureAbsolutePath(path, workDir)
}