(file *api.File)
| 75 | } |
| 76 | |
| 77 | func 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 | |
| 104 | func openCacheRoot() (string, error) { |
| 105 | if strings.TrimSpace(conf.Config.Open.DownloadDir) != "" { |
no test coverage detected