Windows: Cleanup rm- prefixed layers
Some layers might be prefixed with rm-, which will result
in an error when converting that string into an integer.
@@ -278,13 +278,23 @@ func ForceRemoveAll(path string) error {
func cleanupWCOWLayers(root string) error {
// See snapshots/windows/windows.go getSnapshotDir()
var layerNums []int
+ var rmLayerNums []int
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if path != root && info.IsDir() {
- if layerNum, err := strconv.Atoi(filepath.Base(path)); err == nil {
- layerNums = append(layerNums, layerNum)
+ name := filepath.Base(path)
+ if strings.HasPrefix(name, "rm-") {
+ layerNum, err := strconv.Atoi(strings.TrimPrefix(name, "rm-"))
+ if err != nil {
+ return err
+ }
+ rmLayerNums = append(rmLayerNums, layerNum)
} else {
+ layerNum, err := strconv.Atoi(name)
+ if err != nil {
return err
}
+ layerNums = append(layerNums, layerNum)
+ }
return filepath.SkipDir
}
@@ -293,8 +303,14 @@ func cleanupWCOWLayers(root string) error {
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 {
if err := cleanupWCOWLayer(filepath.Join(root, strconv.Itoa(layerNum))); err != nil {
return err
