Finish the method of COPY for webdav.

This commit is contained in:
zicla
2019-04-24 02:02:25 +08:00
parent 35b16ff3e1
commit 8ff928d9d6
3 changed files with 137 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package rest
import (
"fmt"
"go/build"
"io"
"io/ioutil"
"os"
"os/user"
@ -229,3 +230,42 @@ func GetUserCacheRootDir(username string) (rootDirPath string) {
return rootDirPath
}
//复制文件
func CopyFile(srcPath string, destPath string) (nBytes int64) {
srcFileStat, err := os.Stat(srcPath)
if err != nil {
panic(err)
}
if !srcFileStat.Mode().IsRegular() {
panic(fmt.Errorf("%s is not a regular file", srcPath))
}
srcFile, err := os.Open(srcPath)
if err != nil {
panic(err)
}
defer func() {
err = srcFile.Close()
if err != nil {
panic(err)
}
}()
destFile, err := os.Create(destPath)
if err != nil {
panic(err)
}
defer func() {
err = destFile.Close()
if err != nil {
panic(err)
}
}()
nBytes, err = io.Copy(destFile, srcFile)
return nBytes
}