mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 20:38:08 +08:00
storage: different subpaths can point to same root directory
currently different subpaths can only point to same root directory only when one or both of the storage config does not enable dedupe different subpath should be able to point to same root directory and in that case their storage config should be same i.e GC,Dedupe, GC delay and GC interval Signed-off-by: Shivam Mishra <shimish2@cisco.com>
This commit is contained in:
committed by
Ramkumar Chinchani
parent
3bccea7aa2
commit
6c293719e3
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/getlantern/deepcopy"
|
||||
@@ -144,6 +145,27 @@ func New() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
func (expConfig StorageConfig) ParamsEqual(actConfig StorageConfig) bool {
|
||||
return expConfig.GC == actConfig.GC && expConfig.Dedupe == actConfig.Dedupe &&
|
||||
expConfig.GCDelay == actConfig.GCDelay && expConfig.GCInterval == actConfig.GCInterval
|
||||
}
|
||||
|
||||
// SameFile compare two files.
|
||||
// This method will first do the stat of two file and compare using os.SameFile method.
|
||||
func SameFile(str1, str2 string) (bool, error) {
|
||||
sFile, err := os.Stat(str1)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
tFile, err := os.Stat(str2)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return os.SameFile(sFile, tFile), nil
|
||||
}
|
||||
|
||||
// Sanitize makes a sanitized copy of the config removing any secrets.
|
||||
func (c *Config) Sanitize() *Config {
|
||||
sanitizedConfig := &Config{}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//go:build needprivileges
|
||||
// +build needprivileges
|
||||
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
)
|
||||
|
||||
func TestMountConfig(t *testing.T) {
|
||||
Convey("Test config utils mounting same directory", t, func() {
|
||||
// If two dirs are mounting to same location SameFile should be same
|
||||
dir1 := t.TempDir()
|
||||
dir2 := t.TempDir()
|
||||
dir3 := t.TempDir()
|
||||
|
||||
err := syscall.Mount(dir3, dir1, "", syscall.MS_BIND, "")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = syscall.Mount(dir3, dir2, "", syscall.MS_BIND, "")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
isSame, err := config.SameFile(dir1, dir2)
|
||||
So(err, ShouldBeNil)
|
||||
So(isSame, ShouldBeTrue)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
Convey("Test config utils", t, func() {
|
||||
firstStorageConfig := config.StorageConfig{
|
||||
GC: true, Dedupe: true,
|
||||
GCDelay: 1 * time.Minute, GCInterval: 1 * time.Hour,
|
||||
}
|
||||
secondStorageConfig := config.StorageConfig{
|
||||
GC: true, Dedupe: true,
|
||||
GCDelay: 1 * time.Minute, GCInterval: 1 * time.Hour,
|
||||
}
|
||||
|
||||
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeTrue)
|
||||
|
||||
firstStorageConfig.GC = false
|
||||
|
||||
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
||||
|
||||
firstStorageConfig.GC = true
|
||||
firstStorageConfig.Dedupe = false
|
||||
|
||||
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
||||
|
||||
firstStorageConfig.Dedupe = true
|
||||
firstStorageConfig.GCDelay = 2 * time.Minute
|
||||
|
||||
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
||||
|
||||
firstStorageConfig.GCDelay = 1 * time.Minute
|
||||
firstStorageConfig.GCInterval = 2 * time.Hour
|
||||
|
||||
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeFalse)
|
||||
|
||||
firstStorageConfig.GCInterval = 1 * time.Hour
|
||||
|
||||
So(firstStorageConfig.ParamsEqual(secondStorageConfig), ShouldBeTrue)
|
||||
|
||||
isSame, err := config.SameFile("test-config", "test")
|
||||
So(err, ShouldNotBeNil)
|
||||
So(isSame, ShouldBeFalse)
|
||||
|
||||
dir1 := t.TempDir()
|
||||
|
||||
isSame, err = config.SameFile(dir1, "test")
|
||||
So(err, ShouldNotBeNil)
|
||||
So(isSame, ShouldBeFalse)
|
||||
|
||||
dir2 := t.TempDir()
|
||||
|
||||
isSame, err = config.SameFile(dir1, dir2)
|
||||
So(err, ShouldBeNil)
|
||||
So(isSame, ShouldBeFalse)
|
||||
|
||||
isSame, err = config.SameFile(dir1, dir1)
|
||||
So(err, ShouldBeNil)
|
||||
So(isSame, ShouldBeTrue)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user