Skip to content

Commit

Permalink
added existance check
Browse files Browse the repository at this point in the history
  • Loading branch information
rotarur committed Jul 10, 2024
1 parent a65c6ca commit 5f98587
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -161,6 +162,17 @@ func AsyncCall(src string, dst string, cidID string, counter *int, length int, f

utils.PrintLogMessage(*counter, length, cidID, "Syncing")

exist, err := checkIfExist(dst, cidID)
if err != nil {
log.Printf("error: %s", err)
return
}

if exist {
utils.PrintLogMessage(*counter, length, cidID, "Already exists on destination")
return
}

// Get CID from source
resG, err := utils.GetCID(srcGet, nil)
if err != nil {
Expand Down Expand Up @@ -327,3 +339,19 @@ func syncDirContent(src, dst, parentCID string, data utils.Object, s bool) error

return nil
}

func checkIfExist(url string, cid string) (bool, error) {
srcGet := fmt.Sprintf("%s%s%s", url, utils.CAT_ENDPOINT, cid)

// Get CID from source
resG, err := utils.GetCID(srcGet, nil)
if err != nil {
return false, err
}

if resG.StatusCode == http.StatusOK {
return true, nil
}

return false, nil
}

0 comments on commit 5f98587

Please sign in to comment.