config: convert --cache-dir value to an absolute path

This commit is contained in:
albertony
2021-09-10 15:35:53 +02:00
parent 0ffdca42d5
commit f3e71f129c
11 changed files with 47 additions and 33 deletions

View File

@@ -63,11 +63,12 @@ func assertVolumeInfo(t *testing.T, v *docker.VolInfo, name, path string) {
func TestDockerPluginLogic(t *testing.T) {
ctx := context.Background()
oldCacheDir := config.CacheDir
oldCacheDir := config.GetCacheDir()
testDir, testFs := initialise(ctx, t)
config.CacheDir = testDir
err := config.SetCacheDir(testDir)
require.NoError(t, err)
defer func() {
config.CacheDir = oldCacheDir
_ = config.SetCacheDir(oldCacheDir)
if !t.Failed() {
fstest.Purge(testFs)
_ = os.RemoveAll(testDir)
@@ -304,11 +305,12 @@ func testMountAPI(t *testing.T, sockAddr string) {
}
ctx := context.Background()
oldCacheDir := config.CacheDir
oldCacheDir := config.GetCacheDir()
testDir, testFs := initialise(ctx, t)
config.CacheDir = testDir
err := config.SetCacheDir(testDir)
require.NoError(t, err)
defer func() {
config.CacheDir = oldCacheDir
_ = config.SetCacheDir(oldCacheDir)
if !t.Failed() {
fstest.Purge(testFs)
_ = os.RemoveAll(testDir)

View File

@@ -41,11 +41,8 @@ type Driver struct {
// NewDriver makes a new docker driver
func NewDriver(ctx context.Context, root string, mntOpt *mountlib.Options, vfsOpt *vfscommon.Options, dummy, forgetState bool) (*Driver, error) {
// setup directories
cacheDir, err := filepath.Abs(config.CacheDir)
if err != nil {
return nil, errors.Wrap(err, "failed to make --cache-dir absolute")
}
err = file.MkdirAll(cacheDir, 0700)
cacheDir := config.GetCacheDir()
err := file.MkdirAll(cacheDir, 0700)
if err != nil {
return nil, errors.Wrapf(err, "failed to create cache directory: %s", cacheDir)
}