fix: return empty arrays instead of null in listPartitions, listVolumes, handleDiskVolumes
This commit is contained in:
+2
-2
@@ -82,7 +82,7 @@ func listPartitions(isoPath string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(`^\s+([A-Z])\s+`)
|
re := regexp.MustCompile(`^\s+([A-Z])\s+`)
|
||||||
var parts []string
|
parts := []string{}
|
||||||
for _, line := range strings.Split(out, "\n") {
|
for _, line := range strings.Split(out, "\n") {
|
||||||
if m := re.FindStringSubmatch(line); m != nil {
|
if m := re.FindStringSubmatch(line); m != nil {
|
||||||
parts = append(parts, m[1])
|
parts = append(parts, m[1])
|
||||||
@@ -110,7 +110,7 @@ func listVolumes(isoPath string, partitions []string) ([]volInfo, error) {
|
|||||||
rePrompt := regexp.MustCompile(`/disk0/([A-Z])\s*>`)
|
rePrompt := regexp.MustCompile(`/disk0/([A-Z])\s*>`)
|
||||||
reEntry := regexp.MustCompile(`^\s+\d+\s+(.+?)\s+-\s+`)
|
reEntry := regexp.MustCompile(`^\s+\d+\s+(.+?)\s+-\s+`)
|
||||||
|
|
||||||
var vols []volInfo
|
vols := []volInfo{}
|
||||||
currentPart := ""
|
currentPart := ""
|
||||||
|
|
||||||
for _, line := range strings.Split(out, "\n") {
|
for _, line := range strings.Split(out, "\n") {
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ func handleDiskVolumes(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, map[string]any{"error": err.Error()})
|
writeJSON(w, map[string]any{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var filtered []volInfo
|
filtered := []volInfo{}
|
||||||
for _, v := range vols {
|
for _, v := range vols {
|
||||||
if v.Part == part {
|
if v.Part == part {
|
||||||
filtered = append(filtered, v)
|
filtered = append(filtered, v)
|
||||||
|
|||||||
Reference in New Issue
Block a user