Skip to content

Commit

Permalink
Merge pull request #227 from will2z/releases
Browse files Browse the repository at this point in the history
fix:  import failed with the incomplete CAR file
  • Loading branch information
Normalnoise authored May 9, 2023
2 parents a668465 + a56b7a5 commit 46ea9ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions service/aria2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package service

import (
"fmt"
"github.com/google/uuid"
"net/url"
"os"
"path/filepath"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/filswan/go-swan-lib/logs"
libmodel "github.com/filswan/go-swan-lib/model"
"github.com/filswan/go-swan-lib/utils"
"github.com/google/uuid"
)

type Aria2Service struct {
Expand Down Expand Up @@ -255,15 +255,15 @@ func (aria2Service *Aria2Service) StartDownload4Deal(deal *libmodel.OfflineDeal,
for _, dir := range aria2Service.CandidateDirs {
outDir = strings.TrimSuffix(dir, "/")
filePath = outDir + "/" + outFilename
if IsExist(filePath) {
if IsDownloadFinish(filePath) {
UpdateDealInfoAndLog(deal, DEAL_STATUS_IMPORT_READY, &filePath, outFilename+", the car file already exists, skip downloading it")
return
}
}

outDir = strings.TrimSuffix(aria2Service.DownloadDir, "/")
filePath = outDir + "/" + outFilename
if IsExist(filePath) {
if IsDownloadFinish(filePath) {
UpdateDealInfoAndLog(deal, DEAL_STATUS_IMPORT_READY, &filePath, outFilename+", the car file already exists, skip downloading it")
return
}
Expand Down
10 changes: 7 additions & 3 deletions service/lotus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package service
import (
"context"
"fmt"
"github.com/filswan/go-swan-lib/client/boost"
"github.com/filswan/go-swan-lib/model"
"github.com/google/uuid"
"os"
"path/filepath"
"strconv"
Expand All @@ -16,10 +13,13 @@ import (
"sync"
"time"

"github.com/filswan/go-swan-lib/client/boost"
"github.com/filswan/go-swan-lib/client/lotus"
"github.com/filswan/go-swan-lib/client/swan"
"github.com/filswan/go-swan-lib/logs"
"github.com/filswan/go-swan-lib/model"
"github.com/filswan/go-swan-lib/utils"
"github.com/google/uuid"
)

type LotusService struct {
Expand Down Expand Up @@ -225,6 +225,10 @@ func IsExist(filePath string) bool {
return err == nil || os.IsExist(err)
}

func IsDownloadFinish(filePath string) bool {
return IsExist(filePath) && !IsExist(filePath+".aria2")
}

func DeleteDownloadedFiles(filePath string) {
aria2AutoDeleteCarFile := config.GetConfig().Aria2.Aria2AutoDeleteCarFile
if aria2AutoDeleteCarFile {
Expand Down

0 comments on commit 46ea9ab

Please sign in to comment.