MCPcopy Index your code
hub / github.com/TruthHun/BookStack / MoveToStore

Method MoveToStore

models/store/local.go:28–46  ·  view source on GitHub ↗

文件存储[如果是图片文件,不要使用gzip压缩,否则在使用阿里云OSS自带的图片处理功能无法处理图片] @param tmpfile 临时文件 @param save 存储文件,不建议与临时文件相同,特别是IsDel参数值为true的时候 @param IsDel 文件上传后,是否删除临时文件

(tmpfile, save string)

Source from the content-addressed store, hash-verified

26//@param save 存储文件,不建议与临时文件相同,特别是IsDel参数值为true的时候
27//@param IsDel 文件上传后,是否删除临时文件
28func (this *Local) MoveToStore(tmpfile, save string) (err error) {
29 save = strings.TrimLeft(save, "/")
30 //"./a.png"与"a.png"是相同路径
31 if strings.HasPrefix(tmpfile, "./") || strings.HasPrefix(save, "./") {
32 tmpfile = strings.TrimPrefix(tmpfile, "./")
33 save = strings.TrimPrefix(save, "./")
34 }
35 if strings.ToLower(tmpfile) != strings.ToLower(save) { //不是相同文件路径
36
37 os.MkdirAll(filepath.Dir(save), os.ModePerm)
38 // 不使用rename,因为在docker中会挂载外部卷,导致错误
39 // 见https://gocn.vip/article/178
40 if b, err := ioutil.ReadFile(tmpfile); err == nil {
41 ioutil.WriteFile(save, b, os.ModePerm)
42 }
43 os.Remove(tmpfile)
44 }
45 return
46}
47
48//从OSS中删除文件
49//@param object 文件对象

Callers 13

QrcodeMethod · 0.80
UploadMethod · 0.80
UploadCoverMethod · 0.80
unzipToDataMethod · 0.80
loadByFolderMethod · 0.80
ChangeAvatarMethod · 0.80
CrawlHtml2MarkdownFunction · 0.80
HandleSVGFunction · 0.80
UploadFileFunction · 0.80
ReleaseContentMethod · 0.80
GenerateBookMethod · 0.80
callbackMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected