mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
durable: red test, a regular file as the lock directory is accepted
The new helper treats any existing lock path as the directory; the old constructor refused a non-directory. Controls: an existing parent and an existing lock directory keep their modes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4c36f1f861
commit
5c84520d48
2 files changed
+67
No files matched your search
@@ -98,6 +98,25 @@ func TestHostVolumeLockDirectoryCreatedOrRefused(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A lock path that exists but is not a directory refuses, as before the
|
||||
// lock directory was laid out by the provider.
|
||||
func TestHostVolumeLockRefusesNonDirectoryLockPath(t *testing.T) {
|
||||
locks := filepath.Join(t.TempDir(), "locks")
|
||||
if err := os.WriteFile(locks, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{
|
||||
Impl: durable.ImplWALStore, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: pcBlocks,
|
||||
HostVolumeLock: true, VolumeLockDirTestOnly: locks,
|
||||
}, v1View())
|
||||
if err == nil {
|
||||
_ = p.Close()
|
||||
}
|
||||
if !errors.Is(err, durable.ErrVolumeLockDirUnavailable) {
|
||||
t.Fatalf("a regular file as the lock directory was accepted: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A lock file this process cannot write (one another user created, as the
|
||||
// root ublk unit does) is still taken: the lock opens it read-only.
|
||||
func TestHostVolumeLockTakesReadOnlyLockFile(t *testing.T) {
|
||||
|
||||
@@ -38,3 +38,51 @@ func TestHostVolumeLockCreatesParent0755AndLocks0700(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// newLockProvider opens a provider whose host lock directory is locks.
|
||||
func newLockProvider(t *testing.T, locks string) {
|
||||
t.Helper()
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{
|
||||
Impl: durable.ImplWALStore, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: pcBlocks,
|
||||
HostVolumeLock: true, VolumeLockDirTestOnly: locks,
|
||||
}, v1View())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = p.Close()
|
||||
}
|
||||
|
||||
func wantPerm(t *testing.T, path string, want os.FileMode) {
|
||||
t.Helper()
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := fi.Mode().Perm(); got != want {
|
||||
t.Fatalf("%s is %v, want %v", path, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// Directories the provider did not create keep their modes: an existing
|
||||
// parent with a missing lock directory, and both existing.
|
||||
func TestHostVolumeLockKeepsExistingDirectoryModes(t *testing.T) {
|
||||
parent := filepath.Join(t.TempDir(), "sw-block")
|
||||
if err := os.Mkdir(parent, 0o711); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Chmod(parent, 0o711); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
locks := filepath.Join(parent, "locks")
|
||||
newLockProvider(t, locks)
|
||||
wantPerm(t, parent, 0o711)
|
||||
wantPerm(t, locks, 0o700)
|
||||
|
||||
if err := os.Chmod(locks, 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newLockProvider(t, locks)
|
||||
wantPerm(t, parent, 0o711)
|
||||
wantPerm(t, locks, 0o750)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user