Skip to content

Commit

Permalink
feat: p2p transfer file without copy cross device (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkaidChan authored Nov 21, 2024
1 parent a1fb5cf commit a630325
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/downloader/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ func (dl *asyncDownloader) Download(fileMeta *pbfs.FileMeta, downloadUri string,

start := time.Now()

tempDir := os.TempDir()
resp, err := dl.upstream.AsyncDownload(dl.vas, &pbfs.AsyncDownloadReq{
BizId: fileMeta.ConfigItemAttachment.BizId,
BkAgentId: dl.bkAgentID,
ClusterId: dl.clusterID,
PodId: dl.podID,
ContainerName: dl.containerName,
FileMeta: fileMeta,
FileDir: tempDir,
FileDir: filepath.Dir(toFile),
})
if err != nil {
return err
Expand All @@ -82,9 +81,9 @@ func (dl *asyncDownloader) Download(fileMeta *pbfs.FileMeta, downloadUri string,
}

// move the downloaded file from temp dir to the target path
if err := MoveFile(filepath.Join(tempDir, fileMeta.CommitSpec.Content.Signature), toFile); err != nil {
if err := MoveFile(filepath.Join(filepath.Dir(toFile), fileMeta.CommitSpec.Content.Signature), toFile); err != nil {
return fmt.Errorf("move file from %s to %s failed, err: %s",
filepath.Join(tempDir, fileMeta.CommitSpec.Content.Signature), toFile, err)
filepath.Join(filepath.Dir(toFile), fileMeta.CommitSpec.Content.Signature), toFile, err)
}

// Verify the checksum of the downloaded file
Expand Down Expand Up @@ -151,10 +150,12 @@ func MoveFile(srcPath, dstPath string) error {
if err != nil {
// cross-device link error
if linkErr, ok := err.(*os.LinkError); ok && linkErr.Err == syscall.EXDEV {
logger.Debug("cross-device move file", "src", srcPath, "dst", dstPath)
return crossDeviceMoveFile(srcPath, dstPath)
}
return err
}
logger.Debug("rename file", "src", srcPath, "dst", dstPath)
return nil
}

Expand Down

0 comments on commit a630325

Please sign in to comment.