61 lines
2.5 KiB
Go
61 lines
2.5 KiB
Go
package archtest
|
|
|
|
import (
|
|
"go/ast"
|
|
"testing"
|
|
)
|
|
|
|
// renameOwners move something atomicfile cannot write: a directory, an image or
|
|
// download too large for memory, a rotated log, the running executable, or
|
|
// several files that must change together.
|
|
var renameOwners = map[string]bool{
|
|
"internal/app/guesttools_flow.go": true, // file copied into the shared folder
|
|
"internal/app/ui_health.go": true, // log rotation
|
|
"internal/atomicfile/atomicfile.go": true,
|
|
"internal/fetch/fetch.go": true, // download
|
|
"internal/macos/installer/accelerated.go": true, // download
|
|
"internal/macos/installer/hfs_image.go": true, // disk image
|
|
"internal/macos/installer/oc_cache.go": true, // download
|
|
"internal/macos/installer/recovery.go": true, // download
|
|
"internal/macos/installguide/progress.go": true, // macOS may not import atomicfile, see macosHostImports
|
|
"internal/macos/reims/network_record.go": true, // same
|
|
"internal/macos/opencore/image.go": true, // disk image with rollback
|
|
"internal/macos/reims/disk_import.go": true, // disk image with rollback
|
|
"internal/macos/reims/suspend_fileops_other.go": true, // state and metadata commit together
|
|
"internal/macos/reims/suspend_fileops_windows.go": true, // state and metadata commit together
|
|
"internal/plugin/broker.go": true, // log rotation
|
|
"internal/plugin/market/pack.go": true, // archive
|
|
"internal/plugin/package_rename_other.go": true, // plugin directory
|
|
"internal/plugin/package_rename_windows.go": true, // plugin directory
|
|
"internal/runtime/runtime.go": true, // runtime directory
|
|
"internal/selfupdate/selfupdate.go": true, // running executable
|
|
}
|
|
|
|
func TestSmallFilesAreReplacedThroughAtomicfile(t *testing.T) {
|
|
seen := map[string]bool{}
|
|
for _, s := range sources(t) {
|
|
if s.isTest() {
|
|
continue
|
|
}
|
|
ast.Inspect(s.file, func(n ast.Node) bool {
|
|
sel, ok := n.(*ast.SelectorExpr)
|
|
if !ok || sel.Sel.Name != "Rename" {
|
|
return true
|
|
}
|
|
if pkg, ok := sel.X.(*ast.Ident); !ok || pkg.Name != "os" {
|
|
return true
|
|
}
|
|
seen[s.rel] = true
|
|
if !renameOwners[s.rel] {
|
|
t.Errorf("%s calls os.Rename: write small files with atomicfile.Write or atomicfile.WriteJSON", s.rel)
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
for rel := range renameOwners {
|
|
if !seen[rel] {
|
|
t.Errorf("%s no longer calls os.Rename: remove it from renameOwners", rel)
|
|
}
|
|
}
|
|
}
|