@@ -34,6 +34,7 @@ import (
34
34
"github.com/containers/storage/pkg/mount"
35
35
"github.com/containers/storage/pkg/parsers"
36
36
"github.com/containers/storage/pkg/system"
37
+ "github.com/containers/storage/pkg/tempdir"
37
38
"github.com/containers/storage/pkg/unshare"
38
39
units "github.com/docker/go-units"
39
40
digest "github.com/opencontainers/go-digest"
@@ -82,6 +83,7 @@ const (
82
83
const (
83
84
linkDir = "l"
84
85
stagingDir = "staging"
86
+ tempDir = "tmp"
85
87
lowerFile = "lower"
86
88
maxDepth = 500
87
89
@@ -136,6 +138,9 @@ type Driver struct {
136
138
stagingDirsLocks map [string ]* lockfile.LockFile
137
139
138
140
supportsIDMappedMounts * bool
141
+
142
+ // This fled is read-only. Should be save to access without any locking.
143
+ tempDirectory * tempdir.TempDir
139
144
}
140
145
141
146
type additionalLayerStore struct {
@@ -458,6 +463,12 @@ func Init(home string, options graphdriver.Options) (graphdriver.Driver, error)
458
463
return nil , fmt .Errorf ("storage option overlay.size and overlay.inodes only supported for backingFS XFS. Found %v" , backingFs )
459
464
}
460
465
466
+ t , err := tempdir .NewTempDir (filepath .Join (d .home , tempDir ))
467
+ if err != nil {
468
+ return nil , err
469
+ }
470
+ d .tempDirectory = t
471
+
461
472
logrus .Debugf ("backingFs=%s, projectQuotaSupported=%v, useNativeDiff=%v, usingMetacopy=%v" , backingFs , projectQuotaSupported , ! d .useNaiveDiff (), d .usingMetacopy )
462
473
463
474
return d , nil
@@ -862,6 +873,9 @@ func (d *Driver) Metadata(id string) (map[string]string, error) {
862
873
// the storage is being shutdown. The only state created by the driver
863
874
// is the bind mount on the home directory.
864
875
func (d * Driver ) Cleanup () error {
876
+ if err := d .tempDirectory .Cleanup (); err != nil {
877
+ return err
878
+ }
865
879
anyPresent := d .pruneStagingDirectories ()
866
880
if anyPresent {
867
881
return nil
@@ -1313,16 +1327,17 @@ func (d *Driver) Remove(id string) error {
1313
1327
dir := d .dir (id )
1314
1328
lid , err := os .ReadFile (path .Join (dir , "link" ))
1315
1329
if err == nil {
1316
- if err := os . RemoveAll (path .Join (d .home , linkDir , string (lid ))); err != nil {
1317
- logrus .Debugf ("Failed to remove link: %v" , err )
1330
+ if err := d . tempDirectory . Add (path .Join (d .home , linkDir , string (lid ))); err != nil {
1331
+ logrus .Debugf ("Failed to Add to stage Directory link: %v" , err )
1318
1332
}
1319
1333
}
1320
1334
1321
1335
d .releaseAdditionalLayerByID (id )
1322
1336
1323
- if err := system . EnsureRemoveAll (dir ); err != nil && ! os . IsNotExist ( err ) {
1324
- return err
1337
+ if err := d . tempDirectory . Add (dir ); err != nil {
1338
+ return fmt . Errorf ( "failed to add to stage directory: %w" , err )
1325
1339
}
1340
+
1326
1341
if d .quotaCtl != nil {
1327
1342
d .quotaCtl .ClearQuota (dir )
1328
1343
if d .imageStore != "" {
@@ -1358,8 +1373,8 @@ func (d *Driver) recreateSymlinks() error {
1358
1373
// Check that for each layer, there's a link in "l" with the name in
1359
1374
// the layer's "link" file that points to the layer's "diff" directory.
1360
1375
for _ , dir := range dirs {
1361
- // Skip over the linkDir and anything that is not a directory
1362
- if dir .Name () == linkDir || ! dir .IsDir () {
1376
+ // Skip over the linkDir and anything that is not a directory or tempDir
1377
+ if dir .Name () == linkDir || ! dir .IsDir () || dir . Name () == tempDir {
1363
1378
continue
1364
1379
}
1365
1380
// Read the "link" file under each layer to get the name of the symlink
@@ -2027,7 +2042,7 @@ func (d *Driver) ListLayers() ([]string, error) {
2027
2042
for _ , entry := range entries {
2028
2043
id := entry .Name ()
2029
2044
switch id {
2030
- case linkDir , stagingDir , quota .BackingFsBlockDeviceLink , mountProgramFlagFile :
2045
+ case linkDir , stagingDir , tempDir , quota .BackingFsBlockDeviceLink , mountProgramFlagFile :
2031
2046
// expected, but not a layer. skip it
2032
2047
continue
2033
2048
default :
0 commit comments