Skip to content

Commit e3c8f99

Browse files
committed
Fix the problem of the empty directory for breakpoint resume
1 parent 25a7611 commit e3c8f99

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

oss/upload.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ func (bucket Bucket) UploadFile(objectKey, filePath string, partSize int64, opti
4242
}
4343

4444
func getUploadCpFilePath(cpConf *cpConfig, srcFile, destBucket, destObject string) string {
45-
if cpConf.FilePath == "" && cpConf.DirPath != "" {
45+
if cpConf.FilePath == "" {
4646
dest := fmt.Sprintf("oss://%v/%v", destBucket, destObject)
4747
absPath, _ := filepath.Abs(srcFile)
4848
cpFileName := getCpFileName(absPath, dest, "")
49-
cpConf.FilePath = cpConf.DirPath + string(os.PathSeparator) + cpFileName
49+
if cpConf.DirPath != "" {
50+
cpConf.FilePath = cpConf.DirPath + string(os.PathSeparator) + cpFileName
51+
}else{
52+
cpConf.FilePath = cpFileName
53+
}
5054
}
5155
return cpConf.FilePath
5256
}

oss/upload_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,54 @@ func (s *OssUploadSuite) TestUploadRoutineWithRecovery(c *C) {
417417
c.Assert(err, IsNil)
418418
}
419419

420+
// TestUploadRoutineWithEmptyCheckPoint is multi-routine upload with empty check point
421+
func (s *OssUploadSuite) TestUploadRoutineWithEmptyCheckPoint(c *C) {
422+
objectName := objectNamePrefix + RandStr(8)
423+
fileName := "../sample/BingWallpaper-2015-11-07.jpg"
424+
newFile := "upload-new-file-2.jpg"
425+
426+
// Use default routines and default CP file path
427+
// First upload for 4 parts
428+
uploadPartHooker = ErrorHooker
429+
err := s.bucket.UploadFile(objectName, fileName, 100*1024, Checkpoint(true, ""))
430+
c.Assert(err, NotNil)
431+
c.Assert(err.Error(), Equals, "ErrorHooker")
432+
uploadPartHooker = defaultUploadPart
433+
// Check CP
434+
ucp := uploadCheckpoint{}
435+
cpConf := cpConfig{IsEnable: true, FilePath: ""}
436+
cpFilePath := getUploadCpFilePath(&cpConf, fileName, s.bucket.BucketName, objectName)
437+
err = ucp.load(cpFilePath)
438+
c.Assert(err, IsNil)
439+
c.Assert(ucp.Magic, Equals, uploadCpMagic)
440+
c.Assert(len(ucp.MD5), Equals, len("LC34jZU5xK4hlxi3Qn3XGQ=="))
441+
c.Assert(ucp.FilePath, Equals, fileName)
442+
c.Assert(ucp.FileStat.Size, Equals, int64(482048))
443+
c.Assert(len(ucp.FileStat.LastModified.String()) > 0, Equals, true)
444+
c.Assert(ucp.FileStat.MD5, Equals, "")
445+
c.Assert(ucp.ObjectKey, Equals, objectName)
446+
c.Assert(len(ucp.UploadID), Equals, len("3F79722737D1469980DACEDCA325BB52"))
447+
c.Assert(len(ucp.Parts), Equals, 5)
448+
c.Assert(len(ucp.todoParts()), Equals, 1)
449+
c.Assert(len(ucp.allParts()), Equals, 5)
450+
451+
// Second upload, finish the remaining part
452+
err = s.bucket.UploadFile(objectName, fileName, 100*1024, Checkpoint(true, ""))
453+
c.Assert(err, IsNil)
454+
455+
os.Remove(newFile)
456+
os.Remove(cpFilePath)
457+
err = s.bucket.GetObjectToFile(objectName, newFile)
458+
c.Assert(err, IsNil)
459+
460+
eq, err := compareFiles(fileName, newFile)
461+
c.Assert(err, IsNil)
462+
c.Assert(eq, Equals, true)
463+
464+
err = s.bucket.DeleteObject(objectName)
465+
c.Assert(err, IsNil)
466+
}
467+
420468
// TestUploadRoutineWithRecoveryNegative is multiroutineed upload without checkpoint
421469
func (s *OssUploadSuite) TestUploadRoutineWithRecoveryNegative(c *C) {
422470
objectName := objectNamePrefix + RandStr(8)

0 commit comments

Comments
 (0)