mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-18 10:07:03 +00:00
Add Normalize method for RepositoryConfig
This commit is contained in:
@@ -34,6 +34,16 @@ type RepositoryConfig struct {
|
|||||||
Groupname string `toml:"groupname"`
|
Groupname string `toml:"groupname"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize normalizes paramaters of the RepositoryConfig.
|
||||||
|
func (c *RepositoryConfig) Normalize(rootPath string) {
|
||||||
|
if !filepath.IsAbs(c.DirDatabasePath) {
|
||||||
|
c.DirDatabasePath = filepath.Join(rootPath, c.DirDatabasePath)
|
||||||
|
}
|
||||||
|
if !filepath.IsAbs(c.DirMailDataPath) {
|
||||||
|
c.DirMailDataPath = filepath.Join(rootPath, c.DirMailDataPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultRepositoryConfig returns a RepositoryConfig with default parameter.
|
// DefaultRepositoryConfig returns a RepositoryConfig with default parameter.
|
||||||
func DefaultRepositoryConfig() *RepositoryConfig {
|
func DefaultRepositoryConfig() *RepositoryConfig {
|
||||||
c := &RepositoryConfig{
|
c := &RepositoryConfig{
|
||||||
@@ -111,12 +121,7 @@ func OpenRepository(basePath string) (*Repository, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !filepath.IsAbs(c.DirDatabasePath) {
|
c.Normalize(rootPath)
|
||||||
c.DirDatabasePath = filepath.Join(rootPath, c.DirDatabasePath)
|
|
||||||
}
|
|
||||||
if !filepath.IsAbs(c.DirMailDataPath) {
|
|
||||||
c.DirMailDataPath = filepath.Join(rootPath, c.DirMailDataPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
r, err := NewRepository(c)
|
r, err := NewRepository(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -178,12 +183,7 @@ func InitRepository(rootPath string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !filepath.IsAbs(c.DirDatabasePath) {
|
c.Normalize(rootPath)
|
||||||
c.DirDatabasePath = filepath.Join(rootPath, c.DirDatabasePath)
|
|
||||||
}
|
|
||||||
if !filepath.IsAbs(c.DirMailDataPath) {
|
|
||||||
c.DirMailDataPath = filepath.Join(rootPath, c.DirMailDataPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
fi, err = os.Stat(c.DirDatabasePath)
|
fi, err = os.Stat(c.DirDatabasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user