/
state-compose.go
52 lines (43 loc) · 1.48 KB
/
state-compose.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package model;
func GetComposeState(fileState, systemState State) State {
var newState State
// Iterate through fileState applications
for _, fileApp := range fileState.Applications {
var found bool
var foundApp FlatpakApplication
// Search for matching app in systemState
for _, sysApp := range systemState.Applications {
if fileApp.Name == sysApp.Name &&
fileApp.Repo == sysApp.Repo &&
fileApp.Branch == sysApp.Branch &&
fileApp.InstallationType == sysApp.InstallationType {
found = true
foundApp = sysApp;
break
}
}
// Add the application to the newState if not found in systemState
if found {
newState.Applications = append(newState.Applications, foundApp)
}
}
// Add repositories from fileState to newState
for _, fileRepo := range fileState.Repos {
var found bool
var foundRepo FlatpakRepo
// Search for matching repo in systemState
for _, sysRepo := range systemState.Repos {
if fileRepo.Name == sysRepo.Name &&
fileRepo.InstallationType == sysRepo.InstallationType {
found = true
foundRepo = sysRepo
break
}
}
// Add the repository to newState if not found in systemState
if found {
newState.Repos = append(newState.Repos, foundRepo)
}
}
return newState
}