MCPcopy Create free account
hub / github.com/TruthHun/BookStack / Down2local

Method Down2local

models/store/oss.go:296–316  ·  view source on GitHub ↗

Down2local 下载文件夹下的文件到本地

(sourceDir, targetDir string)

Source from the content-addressed store, hash-verified

294
295// Down2local 下载文件夹下的文件到本地
296func (o *Oss) Down2local(sourceDir, targetDir string) (err error) {
297 var (
298 objects []string
299 bucket, _ = o.GetBucket()
300 )
301
302 sourceDir = strings.TrimLeft(sourceDir, "./")
303 targetDir = strings.TrimLeft(targetDir, "./")
304 objects, err = o.ListObjects(sourceDir)
305 if err != nil {
306 return
307 }
308 for _, obj := range objects {
309 targetFile := strings.ReplaceAll(filepath.Join(targetDir, strings.TrimPrefix(obj, sourceDir)), "\\", "/")
310 os.MkdirAll(filepath.Dir(targetFile), os.ModePerm)
311 if err = bucket.GetObjectToFile(obj, targetFile); err != nil {
312 beego.Error("download:", obj, "==>", targetFile, err.Error())
313 }
314 }
315 return
316}

Callers 1

down2localMethod · 0.80

Calls 2

GetBucketMethod · 0.95
ListObjectsMethod · 0.95

Tested by

no test coverage detected