Skip to content

Commit 2aafdd3

Browse files
authored
Merge pull request #174 from HyperloopUPV-H8/backend/adj-download-fix
[backend][1] ADJ alpha.1 - Download logic fix
2 parents f47c01e + 9086566 commit 2aafdd3

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

backend/internal/adj/adj.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
)
99

1010
const (
11-
RepoUrl = "https://github.com/HyperloopUPV-H8/JSON_ADE.git" // URL of the ADJ repository
11+
RepoUrl = "https://github.com/HyperloopUPV-H8/JSON_ADE.git" // URL of the ADJ repository
12+
RepoPath = "./JSON_ADE/" // Path where the ADJ repository is cloned
1213
)
1314

1415
func NewADJ() (*ADJ, error) {
@@ -40,27 +41,37 @@ func NewADJ() (*ADJ, error) {
4041
}
4142

4243
func downloadADJ() (json.RawMessage, json.RawMessage, error) {
43-
_, err := git.PlainClone("", false, &git.CloneOptions{
44-
URL: RepoUrl,
45-
})
46-
if err != nil {
47-
return nil, nil, err
44+
if !checkRepo() {
45+
_, err := git.PlainClone(RepoPath, true, &git.CloneOptions{
46+
URL: RepoUrl,
47+
})
48+
if err != nil {
49+
return nil, nil, err
50+
}
4851
}
4952

5053
// The BoardIds are applied in the NewADJ function by the getBoardIds function
51-
info, err := os.ReadFile("general_info.json")
54+
info, err := os.ReadFile(RepoPath + "general_info.json")
5255
if err != nil {
5356
return nil, nil, err
5457
}
5558

56-
boardsList, err := os.ReadFile("boards.json")
59+
boardsList, err := os.ReadFile(RepoPath + "boards.json")
5760
if err != nil {
5861
return nil, nil, err
5962
}
6063

6164
return info, boardsList, nil
6265
}
6366

67+
func checkRepo() bool {
68+
if _, err := os.Stat(RepoPath); os.IsNotExist(err) {
69+
return false
70+
}
71+
72+
return true
73+
}
74+
6475
func getBoards(info Info, boardsList map[string]string) (map[string]Board, error) {
6576
var boards map[string]Board
6677
for boardName, boardPath := range boardsList {

0 commit comments

Comments
 (0)