feat: Add the upgrade clean command to clear incremental update cache…#240
Merged
Conversation
… files. Description: Add the upgrade clean command to clear incremental update cache files. Log: Add the upgrade clean command to clear incremental update cache files. Task: https://pms.uniontech.com/task-view-382931.html Influence: Clearing of incremental update cache files
41dd2c7 to
6c91867
Compare
zhaohuiw42
approved these changes
Oct 23, 2025
deepin pr auto review我来对这段代码进行审查:
改进后的代码建议: const (
configDir = "/var/lib/lastore"
configFile = "config.json"
cleanCommand = "deepin-immutable-ctl"
cleanTimeout = 30 * time.Second
)
func main() {
// ... 其他代码 ...
// 如果是增量更新,则调用deepin-immutable-ctl upgrade cleanup命令清理immutable系统的缓存deb包和ostree包分支
configPath := path.Join(configDir, configFile)
if err := validatePath(configPath); err != nil {
logger.Errorf("Invalid config path: %v", err)
return
}
config := NewConfig(configPath)
logger.Infof("IncrementalUpdate config: %v", config.IncrementalUpdate)
if config.IncrementalUpdate {
cmdPath, err := exec.LookPath(cleanCommand)
if err != nil {
logger.Errorf("Failed to find %s command: %v", cleanCommand, err)
return
}
ctx, cancel := context.WithTimeout(context.Background(), cleanTimeout)
defer cancel()
cmd := exec.CommandContext(ctx, cmdPath, "upgrade", "clean")
if err := cmd.Run(); err != nil {
if ctx.Err() == context.DeadlineExceeded {
logger.Errorf("Cleanup command timed out after %v", cleanTimeout)
} else {
logger.Warnf("Failed to clean upgrade cache: %v", err)
}
}
}
// ... 其他代码 ...
}
func validatePath(p string) error {
cleanPath := filepath.Clean(p)
if !strings.HasPrefix(cleanPath, configDir) {
return fmt.Errorf("invalid path: %s", p)
}
return nil
}主要改进点:
这些改进可以提高代码的安全性、可靠性和可维护性。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Fire-dtx, zhaohuiw42 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: Add the upgrade clean command to clear incremental update cache files.
Description: Add the upgrade clean command to clear incremental update cache files.
Log: Add the upgrade clean command to clear incremental update cache files.
Task: https://pms.uniontech.com/task-view-382931.html
Influence: Clearing of incremental update cache files