mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Relax file permissions check on existing directories (#13274)
This commit is contained in:
parent
f40b8583f7
commit
b84b795f23
@ -2,7 +2,6 @@ package filesystem
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
@ -206,10 +205,4 @@ func TestBlobStorageDelete(t *testing.T) {
|
||||
func TestNewBlobStorage(t *testing.T) {
|
||||
_, err := NewBlobStorage(path.Join(t.TempDir(), "good"))
|
||||
require.NoError(t, err)
|
||||
|
||||
// If directory already exists with improper permissions, expect a wrapped err message.
|
||||
fp := path.Join(t.TempDir(), "bad")
|
||||
require.NoError(t, os.Mkdir(fp, 0777))
|
||||
_, err = NewBlobStorage(fp)
|
||||
require.ErrorContains(t, "failed to create blob storage", err)
|
||||
}
|
||||
|
@ -59,10 +59,9 @@ func HandleBackupDir(dirPath string, permissionOverride bool) error {
|
||||
return os.MkdirAll(expanded, params.BeaconIoConfig().ReadWriteExecutePermissions)
|
||||
}
|
||||
|
||||
// MkdirAll takes in a path, expands it if necessary, and looks through the
|
||||
// permissions of every directory along the path, ensuring we are not attempting
|
||||
// to overwrite any existing permissions. Finally, creates the directory accordingly
|
||||
// with standardized, Prysm project permissions. This is the static-analysis enforced
|
||||
// MkdirAll takes in a path, expands it if necessary, and creates the directory accordingly
|
||||
// with standardized, Prysm project permissions. If a directory already exists as this path,
|
||||
// then the method returns without making any changes. This is the static-analysis enforced
|
||||
// method for creating a directory programmatically in Prysm.
|
||||
func MkdirAll(dirPath string) error {
|
||||
expanded, err := ExpandPath(dirPath)
|
||||
@ -74,13 +73,7 @@ func MkdirAll(dirPath string) error {
|
||||
return err
|
||||
}
|
||||
if exists {
|
||||
info, err := os.Stat(expanded)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.Mode().Perm() != params.BeaconIoConfig().ReadWriteExecutePermissions {
|
||||
return errors.New("dir already exists without proper 0700 permissions")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return os.MkdirAll(expanded, params.BeaconIoConfig().ReadWriteExecutePermissions)
|
||||
}
|
||||
|
@ -49,14 +49,6 @@ func TestPathExpansion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMkdirAll_AlreadyExists_WrongPermissions(t *testing.T) {
|
||||
dirName := t.TempDir() + "somedir"
|
||||
err := os.MkdirAll(dirName, os.ModePerm)
|
||||
require.NoError(t, err)
|
||||
err = file.MkdirAll(dirName)
|
||||
assert.ErrorContains(t, "already exists without proper 0700 permissions", err)
|
||||
}
|
||||
|
||||
func TestMkdirAll_AlreadyExists_Override(t *testing.T) {
|
||||
dirName := t.TempDir() + "somedir"
|
||||
err := os.MkdirAll(dirName, params.BeaconIoConfig().ReadWriteExecutePermissions)
|
||||
|
Loading…
Reference in New Issue
Block a user