X Tutup
Skip to content

Commit ca35f4e

Browse files
committed
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. Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
1 parent 64291df commit ca35f4e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

sys/filesys_windows.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,22 @@ func ForceRemoveAll(path string) error {
278278
func cleanupWCOWLayers(root string) error {
279279
// See snapshots/windows/windows.go getSnapshotDir()
280280
var layerNums []int
281+
var rmLayerNums []int
281282
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
282283
if path != root && info.IsDir() {
283-
if layerNum, err := strconv.Atoi(filepath.Base(path)); err == nil {
284-
layerNums = append(layerNums, layerNum)
284+
name := filepath.Base(path)
285+
if strings.HasPrefix(name, "rm-") {
286+
layerNum, err := strconv.Atoi(strings.TrimPrefix(name, "rm-"))
287+
if err != nil {
288+
return err
289+
}
290+
rmLayerNums = append(rmLayerNums, layerNum)
285291
} else {
286-
return err
292+
layerNum, err := strconv.Atoi(name)
293+
if err != nil {
294+
return err
295+
}
296+
layerNums = append(layerNums, layerNum)
287297
}
288298
return filepath.SkipDir
289299
}
@@ -293,8 +303,14 @@ func cleanupWCOWLayers(root string) error {
293303
return err
294304
}
295305

296-
sort.Sort(sort.Reverse(sort.IntSlice(layerNums)))
306+
sort.Sort(sort.Reverse(sort.IntSlice(rmLayerNums)))
307+
for _, rmLayerNum := range rmLayerNums {
308+
if err := cleanupWCOWLayer(filepath.Join(root, "rm-"+strconv.Itoa(rmLayerNum))); err != nil {
309+
return err
310+
}
311+
}
297312

313+
sort.Sort(sort.Reverse(sort.IntSlice(layerNums)))
298314
for _, layerNum := range layerNums {
299315
if err := cleanupWCOWLayer(filepath.Join(root, strconv.Itoa(layerNum))); err != nil {
300316
return err

0 commit comments

Comments
 (0)
X Tutup