This repository was archived by the owner on Aug 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Improve dir subtraction #804
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "slices" | ||
| "sort" | ||
| "strconv" | ||
| "strings" | ||
|
|
@@ -755,22 +756,60 @@ func (m *Manifest) addManifestFiles(ui UpdateInfo, c config) error { | |
| } | ||
| } else { | ||
| // Add files to manifest that do not exist in included bundles. | ||
| chrootDir := filepath.Join(c.imageBase, fmt.Sprint(ui.version), "full") | ||
| includes := m.GetRecursiveIncludes() | ||
| usedDirs := make(map[string]struct{}) | ||
| bundleDirs := []string{} | ||
| bundleFiles := []string{} | ||
| for f := range m.BundleInfo.Files { | ||
| fullPath := filepath.Join(chrootDir, f) | ||
| if fi, err := os.Lstat(fullPath); err == nil { | ||
| if !fi.IsDir() { | ||
| usedDirs[filepath.Dir(f)] = struct{}{} | ||
| bundleFiles = append(bundleFiles, f) | ||
| } else { | ||
| bundleDirs = append(bundleDirs, f) | ||
| } | ||
| } | ||
| } | ||
| for _, f := range bundleFiles { | ||
| isIncluded := false | ||
| for _, inc := range includes { | ||
| // Handle cycles | ||
| if inc.Name == m.Name { | ||
| continue | ||
| } | ||
| chrootDir := filepath.Join(c.imageBase, fmt.Sprint(ui.version), "full") | ||
| fullPath := filepath.Join(chrootDir, f) | ||
| if fi, err := os.Lstat(fullPath); err == nil { | ||
| if !fi.IsDir() { | ||
| if _, ok := inc.BundleInfo.Files[f]; ok { | ||
| isIncluded = true | ||
| break | ||
| } | ||
| if _, ok := inc.BundleInfo.Files[f]; ok { | ||
| isIncluded = true | ||
| break | ||
| } | ||
| } | ||
| if !isIncluded { | ||
| if err := m.addFile(f, c, ui.version); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
| // Directories are sorted into reverse order to allow usedDirs | ||
| // to populate correctly (/a/b/c will be seen before /a/b which | ||
| // will allow /a to be set when /a/b is seen) | ||
| slices.Sort(bundleDirs) | ||
| slices.Reverse(bundleDirs) | ||
| for _, f := range bundleDirs { | ||
| if _, ok := usedDirs[f]; ok { | ||
| usedDirs[filepath.Dir(f)] = struct{}{} | ||
| } | ||
| } | ||
| for _, f := range bundleDirs { | ||
| isIncluded := false | ||
| for _, inc := range includes { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to fudge
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Manifest files I believe os-core is already the first element but mixer shouldn't be impacted by include order. The subtraction should happen regardless if something is in os-core no matter if os-core is looked at first or last from that logic. |
||
| if _, ok := inc.BundleInfo.Files[f]; ok { | ||
| if inc.Name == "os-core" { | ||
| isIncluded = true | ||
| break | ||
| } else if _, ok := usedDirs[f]; !ok { | ||
| isIncluded = true | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need any special handling for a file
fin the root dir, e.g./foo? I assume Dir would return./in that case, but the only non-dirs in root should be the symlinkslib,lib64,bin, andsbin, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Dir("/file")will return"/"which is correct in my mind though won't come up as mixer doesn't put/in the manifests so it wouldn't be checked for removal.