fix(module): skip area version-only extract churn
This commit is contained in:
@@ -501,6 +501,9 @@ func writeManagedFile(path string, data []byte) (writeState, error) {
|
||||
if bytes.Equal(existing, data) {
|
||||
return writeSkipped, nil
|
||||
}
|
||||
if areaGFFJSONEqualIgnoringRootVersion(path, existing, data) {
|
||||
return writeSkipped, nil
|
||||
}
|
||||
if err := os.WriteFile(path, data, 0o644); err != nil {
|
||||
return writeSkipped, fmt.Errorf("overwrite %s: %w", path, err)
|
||||
}
|
||||
@@ -516,6 +519,38 @@ func writeManagedFile(path string, data []byte) (writeState, error) {
|
||||
return writeNew, nil
|
||||
}
|
||||
|
||||
func areaGFFJSONEqualIgnoringRootVersion(path string, existing, extracted []byte) bool {
|
||||
if !strings.HasSuffix(strings.ToLower(filepath.Base(path)), ".are.json") {
|
||||
return false
|
||||
}
|
||||
|
||||
var left, right gff.Document
|
||||
if err := json.Unmarshal(existing, &left); err != nil {
|
||||
return false
|
||||
}
|
||||
if err := json.Unmarshal(extracted, &right); err != nil {
|
||||
return false
|
||||
}
|
||||
removeRootField(&left.Root, "Version")
|
||||
removeRootField(&right.Root, "Version")
|
||||
|
||||
leftRaw, err := json.Marshal(left)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
rightRaw, err := json.Marshal(right)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return bytes.Equal(leftRaw, rightRaw)
|
||||
}
|
||||
|
||||
func removeRootField(s *gff.Struct, label string) {
|
||||
s.Fields = slices.DeleteFunc(s.Fields, func(field gff.Field) bool {
|
||||
return field.Label == label
|
||||
})
|
||||
}
|
||||
|
||||
func cleanupStaleFiles(p *project.Project, desired map[string]struct{}, scope extractionScope) (int, []error) {
|
||||
candidates := make([]string, 0, len(p.Inventory.SourceFiles)+len(p.Inventory.ScriptFiles)+len(p.Inventory.AssetFiles))
|
||||
if scope.Source && safeCleanupRoot(p.SourceDir(), p.Root) {
|
||||
|
||||
Reference in New Issue
Block a user