Skip to content

Commit

Permalink
removed unused variables and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rotarur committed Jul 16, 2024
1 parent 5f98587 commit 0cd9930
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions internal/sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -162,16 +161,14 @@ 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
}
// exist, _ := checkIfExist(dst, cidID)
//
// // test first the exist bool and skip error if it doesn't exist because
// // in this case the error is not nil
// if exist {
// utils.PrintLogMessage(*counter, length, cidID, "Already exists on destination")
// return
// }

// Get CID from source
resG, err := utils.GetCID(srcGet, nil)
Expand Down Expand Up @@ -292,14 +289,14 @@ func syncDir(src, dst, file, parentCid string) error {

// Create the structure with the CID directory
var data utils.Data
err = utils.UnmarshalToStruct[utils.Data](lsD.Body, &data)
err = utils.UnmarshalToStruct(lsD.Body, &data)
if err != nil {
return err
}

// Recursive function to sync all directory content
for _, v := range data.Objects {
err = syncDirContent(src, dst, parentCid, v, true)
err = syncDirContent(src, dst, parentCid, v)
if err != nil {
return err
}
Expand All @@ -308,7 +305,7 @@ func syncDir(src, dst, file, parentCid string) error {
return nil
}

func syncDirContent(src, dst, parentCID string, data utils.Object, s bool) error {
func syncDirContent(src, dst, parentCID string, data utils.Object) error {
for _, v := range data.Links {
// Syntax: https://ipfs.com/ipfs/api/v0/cat?arg=QmcoBTSpxyBx2AuUqhuy5X1UrasbLoz76QFGLgqUqhXLK6/foo.txt
filePath := fmt.Sprintf("%s/%s", data.Hash, v.Name)
Expand Down Expand Up @@ -340,18 +337,23 @@ 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
}
// 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 {
// // If it's a directory then the CID exists, otherwise return the error
// if strings.Contains(fmt.Sprintf("%s", err), utils.DIR_ERROR) {
// return true, nil
// } else {
// return false, err
// }
// }

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

// return false, nil
// }

0 comments on commit 0cd9930

Please sign in to comment.