Skip to content

Commit fee7036

Browse files
authored
Merge pull request #9 from ted-gould/fix/ci-go-version
Fix: Update Go version in CI to match toolchain
2 parents daba7af + a9c3169 commit fee7036

File tree

23 files changed

+741
-246
lines changed

23 files changed

+741
-246
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Set up Go
1515
uses: actions/setup-go@v3
1616
with:
17-
go-version: '1.22'
17+
go-version: '1.24.1'
1818
- name: Build project
1919
run: go build ./...
2020
# Add build steps here
@@ -30,7 +30,7 @@ jobs:
3030
- name: Set up Go
3131
uses: actions/setup-go@v3
3232
with:
33-
go-version: '1.22'
33+
go-version: '1.24.1'
3434
- name: Run tests
3535
run: go test ./...
3636
# Add test steps here
@@ -47,7 +47,7 @@ jobs:
4747
- name: Set up Go
4848
uses: actions/setup-go@v3
4949
with:
50-
go-version: '1.22'
50+
go-version: '1.24.1'
5151
- name: Install golangci-lint
5252
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
5353
- name: Run golangci-lint

cmd/xteve-inactive/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8-
"io"
9-
"io/ioutil"
8+
"io" // Added for io.ReadAll
109
"net/http"
1110
"os"
1211
"strconv"
@@ -49,7 +48,7 @@ func runLogic(cmdHost, cmdPort string, outWriter io.Writer, errWriter io.Writer)
4948

5049
defer resp.Body.Close()
5150

52-
respStr, err := ioutil.ReadAll(resp.Body)
51+
respStr, err := io.ReadAll(resp.Body)
5352
if err != nil {
5453
fmt.Fprintf(errWriter, "Unable read response: %v\n", err)
5554
return -1

cmd/xteve-status/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"flag"
77
"fmt"
8-
"io/ioutil"
8+
"io" // For io.ReadAll
99
"net/http"
1010
"os"
1111
"strconv"
@@ -50,7 +50,7 @@ func main() {
5050

5151
defer resp.Body.Close()
5252

53-
respStr, err := ioutil.ReadAll(resp.Body)
53+
respStr, err := io.ReadAll(resp.Body)
5454
if err != nil {
5555
fmt.Fprintf(os.Stderr, "Unable read response: %v\n", err)
5656
os.Exit(-1)

src/authentication.go

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ func activatedSystemAuthentication() (err error) {
2121
defaults["authentication.xml"] = false
2222
defaults["authentication.api"] = false
2323
err = authentication.SetDefaultUserData(defaults)
24-
24+
// Propagate error from SetDefaultUserData
2525
return
2626
}
2727

2828
func createFirstUserForAuthentication(username, password string) (token string, err error) {
29-
var authenticationErr = func(err error) {
30-
if err != nil {
31-
return
32-
}
33-
}
34-
3529
err = authentication.CreateDefaultUser(username, password)
36-
authenticationErr(err)
30+
if err != nil {
31+
return "", err
32+
}
3733

3834
token, err = authentication.UserAuthentication(username, password)
39-
authenticationErr(err)
35+
if err != nil {
36+
return "", err
37+
}
4038

4139
token, err = authentication.CheckTheValidityOfTheToken(token)
42-
authenticationErr(err)
40+
if err != nil {
41+
return "", err
42+
}
4343

4444
var userData = make(map[string]any)
4545
userData["username"] = username
@@ -51,10 +51,14 @@ func createFirstUserForAuthentication(username, password string) (token string,
5151
userData["defaultUser"] = true
5252

5353
userID, err := authentication.GetUserID(token)
54-
authenticationErr(err)
54+
if err != nil {
55+
return "", err
56+
}
5557

5658
err = authentication.WriteUserData(userID, userData)
57-
authenticationErr(err)
59+
if err != nil {
60+
return "", err
61+
}
5862

5963
return
6064
}
@@ -78,9 +82,19 @@ func basicAuth(r *http.Request, level string) (username string, err error) {
7882
return
7983
}
8084

81-
payload, _ := base64.StdEncoding.DecodeString(auth[1])
85+
payload, errDecode := base64.StdEncoding.DecodeString(auth[1])
86+
if errDecode != nil {
87+
// If decoding fails, it's an invalid Authorization header.
88+
// The original err (user authentication failed) is appropriate.
89+
return "", err // Return the original error
90+
}
8291
pair := strings.SplitN(string(payload), ":", 2)
8392

93+
if len(pair) != 2 {
94+
// If not two parts, it's an invalid format.
95+
return "", err // Return the original error
96+
}
97+
8498
username = pair[0]
8599
var password = pair[1]
86100

@@ -145,13 +159,22 @@ func checkAuthorizationLevel(token, level string) (err error) {
145159
err = errors.New("no authorization")
146160
}
147161
} else {
162+
// Level not found, set to false and try to save.
163+
// The user does not have authorization regardless of save success.
148164
userData[level] = false
149-
authentication.WriteUserData(userID, userData)
150-
//err = errors.New("No authorization")
165+
if writeErr := authentication.WriteUserData(userID, userData); writeErr != nil {
166+
// Log the error, but the primary error (no authorization) stands.
167+
// log.Printf("Failed to write default authorization level for user %s, level %s: %v", userID, level, writeErr)
168+
}
169+
err = errors.New("no authorization") // Ensure error is set if level was not found
151170
}
152171
} else {
153-
authentication.WriteUserData(userID, userData)
154-
//err = errors.New("No authorization")
172+
// UserData is empty, this is an unusual case.
173+
// Attempt to write, but the user definitely doesn't have authorization.
174+
if writeErr := authentication.WriteUserData(userID, userData); writeErr != nil {
175+
// log.Printf("Failed to write empty userData for user %s, level %s: %v", userID, level, writeErr)
176+
}
177+
err = errors.New("no authorization") // Ensure error is set if userData was empty
155178
}
156179

157180
return

src/backup.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ func xTeVeAutoBackup() (err error) {
4848
end = Settings.BackupKeep - 1
4949
}
5050

51-
for i := range len(oldBackupFiles) - end {
52-
os.RemoveAll(System.Folder.Backup + oldBackupFiles[i])
51+
for i := 0; i < len(oldBackupFiles)-end; i++ { // Corrected loop condition
52+
backupFileToDelete := System.Folder.Backup + oldBackupFiles[i]
53+
if errRemove := os.RemoveAll(backupFileToDelete); errRemove != nil {
54+
// Log the error, but continue trying to delete other old backups
55+
// log.Printf("Error deleting old backup file %s: %v", backupFileToDelete, errRemove)
56+
// Potentially, update 'err' to return a generic error indicating some cleanup failed
57+
}
5358
debug = fmt.Sprintf("Delete backup file:%s", oldBackupFiles[i])
5459
showDebug(debug, 1)
5560
}
@@ -148,6 +153,7 @@ func xteveRestore(archive string) (newWebURL string, err error) {
148153

149154
if err = removeChildItems(getPlatformPath(System.Folder.Config)); err != nil {
150155
ShowError(err, 1073)
156+
return // Propagate the error
151157
}
152158

153159
// Extract the ZIP Archive into the Config Folder
@@ -169,11 +175,21 @@ func xteveRestore(archive string) (newWebURL string, err error) {
169175
if newPort == oldPort {
170176
if err != nil {
171177
ShowError(err, 0)
178+
// Even if newPort == oldPort, err might have been set by a previous operation.
179+
// We should return it if it's not nil.
180+
if err != nil {
181+
return "", err
182+
}
172183
}
173184

174-
loadSettings()
185+
// loadSettings likely returns (SettingsStruct, error)
186+
// We only care about the error here as Settings is a global variable modified by loadSettings.
187+
if _, err = loadSettings(); err != nil {
188+
ShowError(err, 0) // Or choose to propagate it
189+
return "", err // Propagating seems more appropriate for a restore failure
190+
}
175191

176-
err := Init()
192+
err = Init()
177193
if err != nil {
178194
ShowError(err, 0)
179195
return "", err
@@ -229,7 +245,10 @@ func XteveRestoreFromCLI(archive string) (err error) {
229245

230246
fmt.Print("All data will be replaced with those from the backup. Should the files be restored? [yes|no]:")
231247

232-
fmt.Scanln(&confirm)
248+
if _, errScan := fmt.Scanln(&confirm); errScan != nil {
249+
fmt.Println("Error reading input:", errScan)
250+
return errScan // Propagate the error
251+
}
233252

234253
switch strings.ToLower(confirm) {
235254
case "yes":

0 commit comments

Comments
 (0)