Merge pull request #6126 from claudiubelu/cleanup-wcow-layers

Windows: Cleanup rm- prefixed layers
This commit is contained in:
Phil Estes 2021-10-18 06:43:17 -07:00 committed by GitHub
commit 4da5d94da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -278,13 +278,23 @@ func ForceRemoveAll(path string) error {
func cleanupWCOWLayers(root string) error { func cleanupWCOWLayers(root string) error {
// See snapshots/windows/windows.go getSnapshotDir() // See snapshots/windows/windows.go getSnapshotDir()
var layerNums []int var layerNums []int
var rmLayerNums []int
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if path != root && info.IsDir() { if path != root && info.IsDir() {
if layerNum, err := strconv.Atoi(filepath.Base(path)); err == nil { name := filepath.Base(path)
layerNums = append(layerNums, layerNum) if strings.HasPrefix(name, "rm-") {
} else { layerNum, err := strconv.Atoi(strings.TrimPrefix(name, "rm-"))
if err != nil {
return err return err
} }
rmLayerNums = append(rmLayerNums, layerNum)
} else {
layerNum, err := strconv.Atoi(name)
if err != nil {
return err
}
layerNums = append(layerNums, layerNum)
}
return filepath.SkipDir return filepath.SkipDir
} }
@ -293,8 +303,14 @@ func cleanupWCOWLayers(root string) error {
return err return err
} }
sort.Sort(sort.Reverse(sort.IntSlice(layerNums))) sort.Sort(sort.Reverse(sort.IntSlice(rmLayerNums)))
for _, rmLayerNum := range rmLayerNums {
if err := cleanupWCOWLayer(filepath.Join(root, "rm-"+strconv.Itoa(rmLayerNum))); err != nil {
return err
}
}
sort.Sort(sort.Reverse(sort.IntSlice(layerNums)))
for _, layerNum := range layerNums { for _, layerNum := range layerNums {
if err := cleanupWCOWLayer(filepath.Join(root, strconv.Itoa(layerNum))); err != nil { if err := cleanupWCOWLayer(filepath.Join(root, strconv.Itoa(layerNum))); err != nil {
return err return err