Skip to content

Commit

Permalink
api: fix source dest removal (#1097)
Browse files Browse the repository at this point in the history
Co-authored-by: ook37 <[email protected]>
  • Loading branch information
oklopfer and ook37 authored Nov 27, 2024
1 parent 24ef1c5 commit ccd6cc1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion server/types/pac/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func FromSrcInfo(info srcinfo.Srcinfo) *Script {
Compatible: orEmptyArray(info.Compatible),
Incompatible: orEmptyArray(info.Incompatible),
Maintainers: info.Maintainer,
Source: toArchDistroStrings(info.Source),
Source: toSourceStrings(info.Source),
NoExtract: orEmptyArray(info.NoExtract),
NoSubmodules: orEmptyArray(info.NoSubmodules),
Md5Sums: toArchDistroStrings(info.MD5Sums),
Expand Down Expand Up @@ -161,10 +161,28 @@ func toArchDistroString(ads srcinfo.ArchDistroString) ArchDistroString {
}
}

func toSourceStrings(ads []srcinfo.ArchDistroString) []ArchDistroString {
return array.SwitchMap(ads, func(it *array.Iterator[srcinfo.ArchDistroString]) ArchDistroString {
return ArchDistroString{
Arch: it.Value.Arch,
Distro: it.Value.Distro,
Value: extractSourceUrl(it.Value.Value),
}
})
}

func orEmptyArray[T interface{}](items []T) []T {
if items == nil {
return []T{}
}

return items
}

func extractSourceUrl(source string) string {
parts := strings.Split(source, "::")
if len(parts) > 1 {
return parts[1]
}
return parts[0]
}

0 comments on commit ccd6cc1

Please sign in to comment.