From b8d1ac94758379947d3a538d7168ef45d5da774d Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Tue, 1 Aug 2023 17:34:14 -0700 Subject: [PATCH] Allow long form resolver config to be of type MEM Signed-off-by: Derek Collison --- server/opts.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/server/opts.go b/server/opts.go index 0699f77b..ca45d585 100644 --- a/server/opts.go +++ b/server/opts.go @@ -1186,17 +1186,22 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error *errors = append(*errors, &configErr{tk, err.Error()}) return } - if dir == "" { - *errors = append(*errors, &configErr{tk, "dir has no value and needs to point to a directory"}) - return - } - if info, _ := os.Stat(dir); info != nil && (!info.IsDir() || info.Mode().Perm()&(1<<(uint(7))) == 0) { - *errors = append(*errors, &configErr{tk, "dir needs to point to an accessible directory"}) - return + + checkDir := func() { + if dir == _EMPTY_ { + *errors = append(*errors, &configErr{tk, "dir has no value and needs to point to a directory"}) + return + } + if info, _ := os.Stat(dir); info != nil && (!info.IsDir() || info.Mode().Perm()&(1<<(uint(7))) == 0) { + *errors = append(*errors, &configErr{tk, "dir needs to point to an accessible directory"}) + return + } } + var res AccountResolver switch strings.ToUpper(dirType) { case "CACHE": + checkDir() if sync != 0 { *errors = append(*errors, &configErr{tk, "CACHE does not accept sync"}) } @@ -1208,6 +1213,7 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error } res, err = NewCacheDirAccResolver(dir, limit, ttl, opts...) case "FULL": + checkDir() if ttl != 0 { *errors = append(*errors, &configErr{tk, "FULL does not accept ttl"}) } @@ -1223,6 +1229,8 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error } } res, err = NewDirAccResolver(dir, limit, sync, delete, opts...) + case "MEM", "MEMORY": + res = &MemAccResolver{} } if err != nil { *errors = append(*errors, &configErr{tk, err.Error()})