11// +build linux
22
3+ /*
4+ Copyright The containerd Authors.
5+
6+ Licensed under the Apache License, Version 2.0 (the "License");
7+ you may not use this file except in compliance with the License.
8+ You may obtain a copy of the License at
9+
10+ http://www.apache.org/licenses/LICENSE-2.0
11+
12+ Unless required by applicable law or agreed to in writing, software
13+ distributed under the License is distributed on an "AS IS" BASIS,
14+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ See the License for the specific language governing permissions and
16+ limitations under the License.
17+ */
18+
319package testutil
420
521import (
@@ -21,6 +37,8 @@ func NewLoopback(size int64) (string, func() error, error) {
2137 }
2238
2339 if err := file .Truncate (size ); err != nil {
40+ file .Close ()
41+ os .Remove (file .Name ())
2442 return "" , nil , errors .Wrap (err , "failed to resize temp file" )
2543 }
2644 file .Close ()
@@ -29,6 +47,7 @@ func NewLoopback(size int64) (string, func() error, error) {
2947 losetup := exec .Command ("losetup" , "--find" , "--show" , file .Name ())
3048 p , err := losetup .Output ()
3149 if err != nil {
50+ os .Remove (file .Name ())
3251 return "" , nil , errors .Wrap (err , "loopback setup failed" )
3352 }
3453
0 commit comments