|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package cache
-
- import (
- "os"
- "path/filepath"
-
- cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
- "gitlink.org.cn/cloudream/storage/client2/internal/mount/fuse"
- )
-
- type CacheEntry interface {
- fuse.FsEntry
- // 在虚拟文件系统中的路径,即不包含缓存目录的路径
- PathComps() []string
- // 不再使用本缓存条目
- Release()
- }
-
- type Cache struct {
- cacheDataDir string
- cacheMetaDir string
- }
-
- func (c *Cache) GetCacheDataPath(comps ...string) string {
- comps2 := make([]string, len(comps)+1)
- comps2[0] = c.cacheDataDir
- copy(comps2[1:], comps)
- return filepath.Join(comps2...)
- }
-
- func (c *Cache) GetCacheDataPathComps(comps ...string) []string {
- comps2 := make([]string, len(comps)+1)
- comps2[0] = c.cacheDataDir
- copy(comps2[1:], comps)
- return comps2
- }
-
- func (c *Cache) GetCacheMetaPath(comps ...string) string {
- comps2 := make([]string, len(comps)+1)
- comps2[0] = c.cacheMetaDir
- copy(comps2[1:], comps)
- return filepath.Join(comps2...)
- }
-
- func (c *Cache) GetCacheMetaPathComps(comps ...string) []string {
- comps2 := make([]string, len(comps)+1)
- comps2[0] = c.cacheMetaDir
- copy(comps2[1:], comps)
- return comps2
- }
-
- // 加载指定路径的缓存文件或者目录,如果路径不存在,则返回nil。
- func (c *Cache) LoadAny(pathComps []string) CacheEntry {
- pat := c.GetCacheMetaPath(pathComps...)
- info, err := os.Stat(pat)
- if err != nil {
- // TODO 日志记录
- return nil
- }
-
- if info.IsDir() {
- return newCacheDir(pathComps, info)
- }
-
- file, err := loadCacheFile(pathComps, pat)
- if err != nil {
- // TODO 日志记录
- return nil
- }
- return file
- }
-
- // 加载指定缓存文件,如果文件不存在,则根据create参数决定是否创建文件。
- //
- // 如果create为false,且文件不存在,则返回nil。如果目标位置是一个目录,则也会返回nil。
- func (c *Cache) LoadFile(pathComps []string, create bool) *CacheFile {
-
- }
-
- // 加载指定缓存文件,如果文件不存在,则根据obj参数创建缓存文件。
- func (c *Cache) LoadOrCreateFile(pathComps []string, obj cdssdk.Object) *CacheFile {
-
- }
-
- // 加载指定缓存目录,如果目录不存在,则根据create参数决定是否创建目录。
- //
- // 如果create为false,且目录不存在,则返回nil。如果目标位置是一个文件,则也会返回nil。
- func (c *Cache) LoadDir(pathComps []string, create bool) *CacheDir {
-
- }
-
- // 加载指定路径下所有的缓存文件或者目录,如果路径不存在,则返回nil。
- func (c *Cache) LoadMany(pathComps []string) []CacheEntry {
-
- }
-
- // 删除指定路径的缓存文件或目录。删除目录时如果目录不为空,则会报错。
- func (c *Cache) Remove(pathComps []string) error {
-
- }
-
- // 移动指定路径的缓存文件或目录到新的路径。如果目标路径已经存在,则会报错。
- //
- // 如果移动成功,则返回移动后的缓存文件或目录。如果文件或目录不存在,则返回nil。
- func (c *Cache) Move(pathComps []string, newPathComps []string) (CacheEntry, error) {
-
- }
|