Skip to content

Commit

Permalink
feat: unsupport transfer continuing when uploading folder or multi-files
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehunter9 committed Nov 1, 2024
1 parent 076942d commit 357b93b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/upload/app/handler4.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ func (a *appController) UploadChunks(c *fiber.Ctx) error {
for retry := 0; retry < maxRetries; retry++ {
if info.Offset == offset || offset == 0 {
if info.Offset != offset {
fileutils.RemoveTempFile4(innerIdentifier, uploadsDir)
fmt.Println("Retransfering innerIdentifier:", innerIdentifier, ", uploadsDir:", uploadsDir, ", info.Offset:", info.Offset)
fileutils.ClearTempFileContent(innerIdentifier, uploadsDir)
info.Offset = offset
}

Expand Down
20 changes: 18 additions & 2 deletions pkg/upload/fileutils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ func removeInfoFile(uid string) {
}

func RemoveTempFileAndInfoFile4(uid string, uploadsDir string) {
RemoveTempFile4(uid, uploadsDir)
removeTempFile4(uid, uploadsDir)
removeInfoFile4(uid, uploadsDir)
}

func RemoveTempFile4(uid string, uploadsDir string) {
func removeTempFile4(uid string, uploadsDir string) {
filePath := filepath.Join(uploadsDir, uid)
err := os.Remove(filePath)
if err != nil {
Expand All @@ -323,6 +323,22 @@ func RemoveTempFile4(uid string, uploadsDir string) {

}

func ClearTempFileContent(uid string, uploadsDir string) {
filePath := filepath.Join(uploadsDir, uid)

file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
klog.Warningf("failed to open file %s: %v", filePath, err)
return
}
defer file.Close()

err = file.Truncate(0)
if err != nil {
klog.Warningf("failed to truncate file %s: %v", filePath, err)
}
}

func MoveFileByInfo4(fileInfo models.FileInfo, uploadsDir string) error {
// Construct file path
filePath := filepath.Join(uploadsDir, fileInfo.ID)
Expand Down

0 comments on commit 357b93b

Please sign in to comment.