Skip to content

Commit

Permalink
Adding hard_delete option on resolver configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Viard de Galbert <jviarddegalbert@scaleway.com>
  • Loading branch information
JulienVdG committed Apr 5, 2023
1 parent d5a525b commit 1b1610f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
8 changes: 2 additions & 6 deletions server/accounts.go
Expand Up @@ -4049,18 +4049,14 @@ func (dr *DirAccResolver) apply(opts ...DirResOption) error {
return nil
}

func NewDirAccResolver(path string, limit int64, syncInterval time.Duration, delete bool, opts ...DirResOption) (*DirAccResolver, error) {
func NewDirAccResolver(path string, limit int64, syncInterval time.Duration, delete deleteType, opts ...DirResOption) (*DirAccResolver, error) {
if limit == 0 {
limit = math.MaxInt64
}
if syncInterval <= 0 {
syncInterval = time.Minute
}
deleteType := NoDelete
if delete {
deleteType = RenameDeleted
}
store, err := NewExpiringDirJWTStore(path, false, true, deleteType, 0, limit, false, 0, nil)
store, err := NewExpiringDirJWTStore(path, false, true, delete, 0, limit, false, 0, nil)
if err != nil {
return nil, err
}
Expand Down
23 changes: 22 additions & 1 deletion server/opts.go
Expand Up @@ -1130,6 +1130,8 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error
}
case map[string]interface{}:
del := false
hdel := false
hdel_set := false
dir := ""
dirType := ""
limit := int64(0)
Expand All @@ -1149,6 +1151,11 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error
_, v := unwrapValue(v, &lt)
del = v.(bool)
}
if v, ok := v["hard_delete"]; ok {
_, v := unwrapValue(v, &lt)
hdel_set = true
hdel = v.(bool)
}
if v, ok := v["limit"]; ok {
_, v := unwrapValue(v, &lt)
limit = v.(int64)
Expand Down Expand Up @@ -1189,12 +1196,26 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error
if del {
*errors = append(*errors, &configErr{tk, "CACHE does not accept allow_delete"})
}
if hdel_set {
*errors = append(*errors, &configErr{tk, "CACHE does not accept hard_delete"})
}
res, err = NewCacheDirAccResolver(dir, limit, ttl, opts...)
case "FULL":
if ttl != 0 {
*errors = append(*errors, &configErr{tk, "FULL does not accept ttl"})
}
res, err = NewDirAccResolver(dir, limit, sync, del, opts...)
if hdel_set && !del {
*errors = append(*errors, &configErr{tk, "hard_delete has no effect without delete"})
}
delete := NoDelete
if del {
if hdel {
delete = HardDelete
} else {
delete = RenameDeleted
}
}
res, err = NewDirAccResolver(dir, limit, sync, delete, opts...)
}
if err != nil {
*errors = append(*errors, &configErr{tk, err.Error()})
Expand Down

0 comments on commit 1b1610f

Please sign in to comment.