Skip to content

Commit

Permalink
rename some funtions that not need export out package
Browse files Browse the repository at this point in the history
  • Loading branch information
gongweibao committed Jun 7, 2017
1 parent a17e0b1 commit 8966691
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
12 changes: 5 additions & 7 deletions go/paddlecloud/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
log "github.com/golang/glog"
)

// RemoteChunkMeta get ChunkMeta of path from cloud.
func RemoteChunkMeta(path string,
func remoteChunkMeta(path string,
chunkSize int64) ([]pfsmod.ChunkMeta, error) {
cmd := pfsmod.ChunkMetaCmd{
Method: pfsmod.ChunkMetaCmdName,
Expand Down Expand Up @@ -107,9 +106,8 @@ func downloadChunks(src string,
return nil
}

// DownloadFile downloads src to dst. If dst does not exists, create it with srcFileSize.
func DownloadFile(src string, srcFileSize int64, dst string) error {
srcMeta, err := RemoteChunkMeta(src, defaultChunkSize)
func downloadFile(src string, srcFileSize int64, dst string) error {
srcMeta, err := remoteChunkMeta(src, defaultChunkSize)
if err != nil {
return err
}
Expand Down Expand Up @@ -152,7 +150,7 @@ func checkBeforeDownLoad(src []pfsmod.LsResult, dst string) (bool, error) {
}

// Download function downloads src to dst.
func Download(src, dst string) error {
func download(src, dst string) error {
log.V(1).Infof("download %s to %s\n", src, dst)
lsRet, err := RemoteLs(pfsmod.NewLsCmd(true, src))
if err != nil {
Expand All @@ -178,7 +176,7 @@ func Download(src, dst string) error {
}

fmt.Printf("download src_path:%s dst_path:%s\n", realSrc, realDst)
if err := DownloadFile(realSrc, attr.Size, realDst); err != nil {
if err := downloadFile(realSrc, attr.Size, realDst); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions go/paddlecloud/pfscp.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func RunCp(cmd *pfsmod.CpCmd) error {
if pfsmod.IsCloudPath(cmd.Dst) {
err = errors.New(pfsmod.StatusOnlySupportFiles)
} else {
err = Download(arg, cmd.Dst)
err = download(arg, cmd.Dst)
}
} else {
if pfsmod.IsCloudPath(cmd.Dst) {
err = Upload(arg, cmd.Dst)
err = upload(arg, cmd.Dst)
} else {
//can't do that
err = errors.New(pfsmod.StatusOnlySupportFiles)
Expand Down
20 changes: 8 additions & 12 deletions go/paddlecloud/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
log "github.com/golang/glog"
)

// RemoteStat gets StatCmd's result from server.
func RemoteStat(cmd *pfsmod.StatCmd) (*pfsmod.LsResult, error) {
func remoteStat(cmd *pfsmod.StatCmd) (*pfsmod.LsResult, error) {
t := fmt.Sprintf("%s/api/v1/files", config.ActiveConfig.Endpoint)
log.V(3).Infoln(t)
body, err := GetCall(t, cmd.ToURLParam())
Expand All @@ -40,8 +39,7 @@ func RemoteStat(cmd *pfsmod.StatCmd) (*pfsmod.LsResult, error) {
return &resp.Results, nil
}

// RemoteTouch touches a file on cloud.
func RemoteTouch(cmd *pfsmod.TouchCmd) error {
func remoteTouch(cmd *pfsmod.TouchCmd) error {
j, err := cmd.ToJSON()
if err != nil {
return err
Expand Down Expand Up @@ -150,8 +148,7 @@ func uploadChunks(src string,
return nil
}

// UploadFile uploads src file to dst.
func UploadFile(src, dst string, srcFileSize int64) error {
func uploadFile(src, dst string, srcFileSize int64) error {

log.V(1).Infof("touch %s size:%d\n", dst, srcFileSize)

Expand All @@ -161,11 +158,11 @@ func UploadFile(src, dst string, srcFileSize int64) error {
FileSize: srcFileSize,
}

if err := RemoteTouch(&cmd); err != nil {
if err := remoteTouch(&cmd); err != nil {
return err
}

dstMeta, err := RemoteChunkMeta(dst, defaultChunkSize)
dstMeta, err := remoteChunkMeta(dst, defaultChunkSize)
if err != nil {
return err
}
Expand All @@ -186,16 +183,15 @@ func UploadFile(src, dst string, srcFileSize int64) error {
return uploadChunks(src, dst, diffMeta)
}

// Upload uploads src to dst.
func Upload(src, dst string) error {
func upload(src, dst string) error {
lsCmd := pfsmod.NewLsCmd(true, src)
srcRet, err := lsCmd.Run()
if err != nil {
return err
}
log.V(1).Infof("ls src:%s result:%#v\n", src, srcRet)

dstMeta, err := RemoteStat(&pfsmod.StatCmd{Path: dst, Method: pfsmod.StatCmdName})
dstMeta, err := remoteStat(&pfsmod.StatCmd{Path: dst, Method: pfsmod.StatCmdName})
if err != nil && !strings.Contains(err.Error(), pfsmod.StatusFileNotFound) {
return err
}
Expand All @@ -219,7 +215,7 @@ func Upload(src, dst string) error {
log.V(1).Infof("upload src_path:%s src_file_size:%d dst_path:%s\n",
realSrc, srcMeta.Size, realDst)
fmt.Printf("uploading %s to %s", realSrc, realDst)
if err := UploadFile(realSrc, realDst, srcMeta.Size); err != nil {
if err := uploadFile(realSrc, realDst, srcMeta.Size); err != nil {
fmt.Printf(" error %v\n", err)
return err
}
Expand Down

0 comments on commit 8966691

Please sign in to comment.