feat: Support relative root directories without BasePathFs
This commit is contained in:
Vendored
+13
@@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/pojntfx/stfs/internal/pathext"
|
||||
"github.com/pojntfx/stfs/pkg/config"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
@@ -17,14 +18,26 @@ func Cache(
|
||||
) (afero.Fs, error) {
|
||||
switch cacheType {
|
||||
case CacheTypeMemory:
|
||||
if pathext.IsRoot(root) {
|
||||
return afero.NewCacheOnReadFs(base, afero.NewMemMapFs(), ttl), nil
|
||||
}
|
||||
|
||||
return afero.NewCacheOnReadFs(afero.NewBasePathFs(base, root), afero.NewMemMapFs(), ttl), nil
|
||||
case CacheTypeDir:
|
||||
if err := os.MkdirAll(cacheDir, os.ModePerm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if pathext.IsRoot(root) {
|
||||
return afero.NewCacheOnReadFs(base, afero.NewBasePathFs(afero.NewOsFs(), cacheDir), ttl), nil
|
||||
}
|
||||
|
||||
return afero.NewCacheOnReadFs(afero.NewBasePathFs(base, root), afero.NewBasePathFs(afero.NewOsFs(), cacheDir), ttl), nil
|
||||
case config.NoneKey:
|
||||
if pathext.IsRoot(root) {
|
||||
return base, nil
|
||||
}
|
||||
|
||||
return afero.NewBasePathFs(base, root), nil
|
||||
default:
|
||||
return nil, ErrCacheTypeUnsupported
|
||||
|
||||
Reference in New Issue
Block a user