Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide local artifacts for software installation #36

Merged
merged 7 commits into from
Sep 12, 2022
4 changes: 2 additions & 2 deletions internal/feature_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ Installing:
var installScriptExtLocation string
for _, sa := range module.Artifacts {
if runtime.GOOS == "windows" {
gboyvalenkov-bosch marked this conversation as resolved.
Show resolved Hide resolved
if sa.FileName == "install.bat" && sa.Local && !sa.Copy {
if sa.FileName == "install.bat" && storage.IsFileLink(sa.Link) && !sa.Copy {
installScriptExtLocation = sa.Link
break
}
} else if sa.FileName == "install.sh" && sa.Local && !sa.Copy {
} else if sa.FileName == "install.sh" && storage.IsFileLink(sa.Link) && !sa.Copy {
installScriptExtLocation = sa.Link
break
}
Expand Down
2 changes: 1 addition & 1 deletion internal/feature_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func setLastOS(su *hawkbit.SoftwareUpdatable, os *hawkbit.OperationStatus) {
func (f *ScriptBasedSoftwareUpdatable) validateLocalArtifacts(module *storage.Module) error {
gboyvalenkov-bosch marked this conversation as resolved.
Show resolved Hide resolved
logger.Debugf("validating local artifacts of module - %v", module)
for _, sa := range module.Artifacts {
if !sa.Local {
if !storage.IsFileLink(sa.Link) {
continue
}
location := f.locateArtifact(sa.Link)
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func openResource(artifact *Artifact, offset int64, serverCert string, retryCoun
}

func getInput(artifact *Artifact, offset int64, serverCert string) (io.ReadCloser, bool, error) {
if artifact.Local { // a file
if IsFileLink(artifact.Link) { // a file
return getFileInput(artifact.Link, offset)
}

Expand Down
5 changes: 2 additions & 3 deletions internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type Artifact struct {
HashType string `json:"hashType"`
HashValue string `json:"hashValue"`
Link string `json:"link"`
Local bool `json:"local"`
Copy bool `json:"copy"`
}

Expand Down Expand Up @@ -238,7 +237,7 @@ func (st *Storage) DownloadModule(toDir string, module *Module, progress Progres
if progress != nil {
var totalSize int64
for _, sa := range module.Artifacts {
if !sa.Local || sa.Copy {
if !IsFileLink(sa.Link) || sa.Copy {
totalSize += int64(sa.Size)
}
}
Expand All @@ -261,7 +260,7 @@ func (st *Storage) DownloadModule(toDir string, module *Module, progress Progres

onlyLocalNoCopyArtifacts := true
for _, sa := range module.Artifacts {
if sa.Local && !sa.Copy {
if IsFileLink(sa.Link) && !sa.Copy {
logger.Infof("read-only local artifact - [%s]", sa.Link)
continue
}
Expand Down
12 changes: 11 additions & 1 deletion internal/storage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import (
"github.com/eclipse-kanto/software-update/internal/logger"
)

var (
prefHTTP = strings.ToLower(string(hawkbit.HTTP)) + "://"
prefHTTPS = strings.ToLower(string(hawkbit.HTTPS)) + "://"
)

// ReadLn reads reads first line from a file.
func ReadLn(fn string) (string, error) {
file, err := os.Open(fn)
Expand Down Expand Up @@ -121,6 +126,12 @@ func SplitArtifacts(r rune) bool {
return r == ',' || r == os.PathListSeparator
}

// IsFileLink is a helper function, checking whether an artifact link is a local file
func IsFileLink(link string) bool {
l := strings.ToLower(link)
return !strings.HasPrefix(l, prefHTTP) && !strings.HasPrefix(l, prefHTTPS)
gboyvalenkov-bosch marked this conversation as resolved.
Show resolved Hide resolved
}

func loadInstalledDep(dep string) (*hawkbit.DependencyDescription, error) {
logger.Debugf("Load installed dependency: %s", dep)
file, err := os.Open(dep)
Expand Down Expand Up @@ -219,7 +230,6 @@ func toArtifact(sa *hawkbit.SoftwareArtifactAction, copy bool) (*Artifact, error
artifact.Link = sa.Download[hawkbit.HTTP].URL
} else if sa.Download[ProtocolFile] != nil {
artifact.Link = sa.Download[ProtocolFile].URL
artifact.Local = true
} else {
return nil, fmt.Errorf("unknown or missing link for artifact %s", sa.Filename)
}
Expand Down