Skip to content

Commit

Permalink
Fix/fix not clean rauc office (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Oct 11, 2023
1 parent 8aa7556 commit fdc3cb1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions service/rauc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
FlagUpgradeFile = "/var/lib/casaos/upgradInfo.txt"
FlagUpgradeFile = "/var/lib/casaos/upgradeInfo.txt"
)

func ExtractRAUCRelease(packageFilepath string, release codegen.Release) error {
Expand Down Expand Up @@ -46,7 +46,7 @@ func InstallRAUC(release codegen.Release, sysRoot string, InstallRAUCHandler fun

func InstallRAUCImp(raucFilePath string) error {
// install rauc
fmt.Println("rauc路径为:", raucFilePath)
fmt.Println("rauc path: ", raucFilePath)

raucInstaller, err := rauc.InstallerNew()
if err != nil {
Expand All @@ -71,7 +71,7 @@ func InstallRAUCImp(raucFilePath string) error {

func MockInstallRAUC(raucFilePath string) error {
// to check file exist
fmt.Println("文件名为", raucFilePath)
fmt.Println("filename: ", raucFilePath)
if _, err := os.Stat(raucFilePath); os.IsNotExist(err) {
return fmt.Errorf("not found rauc install package")
}
Expand Down
4 changes: 4 additions & 0 deletions service/rauc_offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (r *RAUCOfflineService) VerifyRelease(release codegen.Release) (string, err
return r.CheckSumHandler(release)
}

func CleanupOfflineRAUCTemp(sysRoot string) error {
return os.RemoveAll(filepath.Join(sysRoot, config.OFFLINE_RAUC_TEMP_PATH))
}

func (r *RAUCOfflineService) DownloadRelease(ctx context.Context, release codegen.Release, force bool) (string, error) {
releasePath, err := r.VerifyRelease(release)
if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion service/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/Masterminds/semver/v3"
"go.uber.org/zap"
"gopkg.in/yaml.v3"

"github.com/samber/lo"
)

var (
Expand Down Expand Up @@ -229,7 +231,16 @@ func CheckOfflineTarExist(sysRoot string) bool {
// if the file have "*.tar" return true
files := internal.GetAllFile(filepath.Join(sysRoot, config.RAUC_OFFLINE_PATH))
println("files : ", files)
if len(files) == 1 {

// only allow one tar file
tar_files := lo.FilterMap(files, func(filename string, _ int) (string, bool) {
if strings.HasSuffix(filename, ".tar") {
return filename, true
}
return "", false
})

if len(tar_files) == 1 {
file_name := files[0]
if strings.HasSuffix(file_name, ".tar") {
println("find offline rauc file: ", file_name)
Expand Down
2 changes: 2 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ func NewService(RuntimePath string) Services {
}

func NewInstallerService(sysRoot string) UpdaterServiceInterface {

CleanupOfflineRAUCTemp(sysRoot)
installMethod, err := GetInstallMethod(sysRoot)
if err != nil {
panic(err)
Expand Down
3 changes: 1 addition & 2 deletions types/installer_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const (
type TriggerType string

const (
HTTP_CHECK TriggerType = "http-request-check"

HTTP_CHECK TriggerType = "http-request-check"
HTTP_REQUEST TriggerType = "http-request-trigger"
CRON_JOB TriggerType = "cron-job-trigger"
INSTALL TriggerType = "install-trigger"
Expand Down

0 comments on commit fdc3cb1

Please sign in to comment.