[FIX] fix creat dst tgz file error

This commit is contained in:
goodrain 2018-03-05 14:48:03 +08:00
parent 56732d3d1d
commit f9fe2115d0
3 changed files with 14 additions and 3 deletions

View File

@ -22,6 +22,9 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"github.com/goodrain/rainbond/pkg/util"
"github.com/goodrain/rainbond/pkg/event"
)
@ -43,6 +46,14 @@ func CopyFileWithProgress(src, dst string, logger event.Logger) error {
}
return err
}
// 验证并创建目标目录
dir := filepath.Dir(dst)
if err := util.CheckAndCreateDir(dir); err != nil {
if logger != nil {
logger.Error("检测并创建目标文件目录失败", map[string]string{"step": "share"})
}
return err
}
// 先删除文件如果存在
os.RemoveAll(dst)
dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)

View File

@ -31,7 +31,7 @@ func init() {
}
func TestCopyFileWithProgress(t *testing.T) {
logger := event.GetManager().GetLogger("system")
if err := CopyFileWithProgress("/tmp/src.tgz", "/tmp/desc1.tgz", logger); err != nil {
if err := CopyFileWithProgress("/tmp/src.tgz", "/tmp/abc/desc1.tgz", logger); err != nil {
t.Fatal(err)
}
}

View File

@ -26,7 +26,7 @@ import (
func TestFTPUp(t *testing.T) {
logger := event.GetManager().GetLogger("system")
ftp := NewFTPConnManager(logger, "goodrain-admin", "goodrain123465", "139.196.88.57", 10021)
ftp := NewFTPConnManager(logger, "goodrain-admin", "goodrain123465", "139.196.88.57", "10021")
defer ftp.FTP.Close()
upfile := "/Users/pujielan/Downloads/http.conf"
if err := ftp.FTPLogin(logger); err != nil {