MCPcopy Create free account
hub / github.com/52funny/pikpakcli / cacheOpenFile

Function cacheOpenFile

internal/shell/open.go:77–102  ·  view source on GitHub ↗
(file *api.File)

Source from the content-addressed store, hash-verified

75}
76
77func cacheOpenFile(file *api.File) (string, error) {
78 cacheRoot, err := openCacheRoot()
79 if err != nil {
80 return "", err
81 }
82
83 cacheDir := filepath.Join(cacheRoot, file.ID)
84 if err := utils.CreateDirIfNotExist(cacheDir); err != nil {
85 return "", err
86 }
87
88 localPath := filepath.Join(cacheDir, file.Name)
89 matched, err := localFileMatchesRemoteSize(localPath, file.Size)
90 if err != nil {
91 return "", err
92 }
93 if matched {
94 return localPath, nil
95 }
96
97 if err := file.Download(localPath, nil); err != nil {
98 return "", err
99 }
100
101 return localPath, nil
102}
103
104func openCacheRoot() (string, error) {
105 if strings.TrimSpace(conf.Config.Open.DownloadDir) != "" {

Callers 1

resolveOpenTargetFunction · 0.85

Calls 4

CreateDirIfNotExistFunction · 0.92
openCacheRootFunction · 0.85
DownloadMethod · 0.80

Tested by

no test coverage detected