summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org
diff options
context:
space:
mode:
authorLibravatar tsmethurst <tobi.smethurst@protonmail.com>2022-01-29 12:15:51 +0100
committerLibravatar tsmethurst <tobi.smethurst@protonmail.com>2022-01-29 12:15:51 +0100
commit4e74c84148cf3a1e19e5e957122dede5b403648a (patch)
tree5d80b9ebdfe25e706725ad3f6e8c5aa56275ebe0 /vendor/codeberg.org
parentgo mod tidy (diff)
downloadgotosocial-4e74c84148cf3a1e19e5e957122dede5b403648a.tar.xz
update go-store to latest
Diffstat (limited to 'vendor/codeberg.org')
-rw-r--r--vendor/codeberg.org/gruf/go-store/storage/block.go2
-rw-r--r--vendor/codeberg.org/gruf/go-store/storage/disk.go56
-rw-r--r--vendor/codeberg.org/gruf/go-store/storage/lock.go9
-rw-r--r--vendor/codeberg.org/gruf/go-store/util/fs.go31
-rw-r--r--vendor/codeberg.org/gruf/go-store/util/sys.go14
5 files changed, 66 insertions, 46 deletions
diff --git a/vendor/codeberg.org/gruf/go-store/storage/block.go b/vendor/codeberg.org/gruf/go-store/storage/block.go
index 5075c7d17..c50faa10b 100644
--- a/vendor/codeberg.org/gruf/go-store/storage/block.go
+++ b/vendor/codeberg.org/gruf/go-store/storage/block.go
@@ -140,7 +140,7 @@ func OpenBlock(path string, cfg *BlockConfig) (*BlockStorage, error) {
}
// Open and acquire storage lock for path
- lock, err := OpenLock(pb.Join(path, lockFile))
+ lock, err := OpenLock(pb.Join(path, LockFile))
if err != nil {
return nil, err
}
diff --git a/vendor/codeberg.org/gruf/go-store/storage/disk.go b/vendor/codeberg.org/gruf/go-store/storage/disk.go
index 2ee00ddee..287042886 100644
--- a/vendor/codeberg.org/gruf/go-store/storage/disk.go
+++ b/vendor/codeberg.org/gruf/go-store/storage/disk.go
@@ -5,6 +5,8 @@ import (
"io/fs"
"os"
"path"
+ _path "path"
+ "strings"
"syscall"
"codeberg.org/gruf/go-bytes"
@@ -31,6 +33,11 @@ type DiskConfig struct {
// Overwrite allows overwriting values of stored keys in the storage
Overwrite bool
+ // LockFile allows specifying the filesystem path to use for the lockfile,
+ // providing only a filename it will store the lockfile within provided store
+ // path and nest the store under `path/store` to prevent access to lockfile
+ LockFile string
+
// Compression is the Compressor to use when reading / writing files, default is no compression
Compression Compressor
}
@@ -57,11 +64,17 @@ func getDiskConfig(cfg *DiskConfig) DiskConfig {
cfg.WriteBufSize = DefaultDiskConfig.WriteBufSize
}
+ // Assume empty lockfile path == use default
+ if len(cfg.LockFile) < 1 {
+ cfg.LockFile = LockFile
+ }
+
// Return owned config copy
return DiskConfig{
Transform: cfg.Transform,
WriteBufSize: cfg.WriteBufSize,
Overwrite: cfg.Overwrite,
+ LockFile: cfg.LockFile,
Compression: cfg.Compression,
}
}
@@ -76,16 +89,27 @@ type DiskStorage struct {
// OpenFile opens a DiskStorage instance for given folder path and configuration
func OpenFile(path string, cfg *DiskConfig) (*DiskStorage, error) {
+ // Get checked config
+ config := getDiskConfig(cfg)
+
// Acquire path builder
pb := util.GetPathBuilder()
defer util.PutPathBuilder(pb)
- // Clean provided path, ensure ends in '/' (should
- // be dir, this helps with file path trimming later)
- storePath := pb.Join(path, "store") + "/"
+ // Clean provided store path, ensure
+ // ends in '/' to help later path trimming
+ storePath := pb.Clean(path) + "/"
- // Get checked config
- config := getDiskConfig(cfg)
+ // Clean provided lockfile path
+ lockfile := pb.Clean(config.LockFile)
+
+ // Check if lockfile is an *actual* path or just filename
+ if lockDir, _ := _path.Split(lockfile); len(lockDir) < 1 {
+ // Lockfile is a filename, store must be nested under
+ // $storePath/store to prevent access to the lockfile
+ storePath += "store/"
+ lockfile = pb.Join(path, lockfile)
+ }
// Attempt to open dir path
file, err := os.OpenFile(storePath, defaultFileROFlags, defaultDirPerms)
@@ -118,7 +142,7 @@ func OpenFile(path string, cfg *DiskConfig) (*DiskStorage, error) {
}
// Open and acquire storage lock for path
- lock, err := OpenLock(pb.Join(path, lockFile))
+ lock, err := OpenLock(lockfile)
if err != nil {
return nil, err
}
@@ -347,9 +371,27 @@ func (st *DiskStorage) filepath(key string) (string, error) {
pb.AppendString(key)
// Check for dir traversal outside of root
- if util.IsDirTraversal(st.path, pb.StringPtr()) {
+ if isDirTraversal(st.path, pb.StringPtr()) {
return "", ErrInvalidKey
}
return pb.String(), nil
}
+
+// isDirTraversal will check if rootPlusPath is a dir traversal outside of root,
+// assuming that both are cleaned and that rootPlusPath is path.Join(root, somePath)
+func isDirTraversal(root, rootPlusPath string) bool {
+ switch {
+ // Root is $PWD, check for traversal out of
+ case root == ".":
+ return strings.HasPrefix(rootPlusPath, "../")
+
+ // The path MUST be prefixed by root
+ case !strings.HasPrefix(rootPlusPath, root):
+ return true
+
+ // In all other cases, check not equal
+ default:
+ return len(root) == len(rootPlusPath)
+ }
+}
diff --git a/vendor/codeberg.org/gruf/go-store/storage/lock.go b/vendor/codeberg.org/gruf/go-store/storage/lock.go
index fae4351bf..8a6c4c5e8 100644
--- a/vendor/codeberg.org/gruf/go-store/storage/lock.go
+++ b/vendor/codeberg.org/gruf/go-store/storage/lock.go
@@ -8,13 +8,8 @@ import (
"codeberg.org/gruf/go-store/util"
)
-// lockFile is our standard lockfile name.
-var lockFile = "store.lock"
-
-// IsLockKey returns whether storage key is our lockfile.
-func IsLockKey(key string) bool {
- return key == lockFile
-}
+// LockFile is our standard lockfile name.
+const LockFile = "store.lock"
// Lock represents a filesystem lock to ensure only one storage instance open per path.
type Lock struct {
diff --git a/vendor/codeberg.org/gruf/go-store/util/fs.go b/vendor/codeberg.org/gruf/go-store/util/fs.go
index 93b37a261..53fef7750 100644
--- a/vendor/codeberg.org/gruf/go-store/util/fs.go
+++ b/vendor/codeberg.org/gruf/go-store/util/fs.go
@@ -3,30 +3,10 @@ package util
import (
"io/fs"
"os"
- "strings"
- "syscall"
"codeberg.org/gruf/go-fastpath"
)
-// IsDirTraversal will check if rootPlusPath is a dir traversal outside of root,
-// assuming that both are cleaned and that rootPlusPath is path.Join(root, somePath)
-func IsDirTraversal(root string, rootPlusPath string) bool {
- switch {
- // Root is $PWD, check for traversal out of
- case root == ".":
- return strings.HasPrefix(rootPlusPath, "../")
-
- // The path MUST be prefixed by root
- case !strings.HasPrefix(rootPlusPath, root):
- return true
-
- // In all other cases, check not equal
- default:
- return len(root) == len(rootPlusPath)
- }
-}
-
// WalkDir traverses the dir tree of the supplied path, performing the supplied walkFn on each entry
func WalkDir(pb *fastpath.Builder, path string, walkFn func(string, fs.DirEntry)) error {
// Read supplied dir path
@@ -100,14 +80,3 @@ func cleanDirs(pb *fastpath.Builder, path string) error {
}
return nil
}
-
-// RetryOnEINTR is a low-level filesystem function for retrying syscalls on O_EINTR received
-func RetryOnEINTR(do func() error) error {
- for {
- err := do()
- if err == syscall.EINTR {
- continue
- }
- return err
- }
-}
diff --git a/vendor/codeberg.org/gruf/go-store/util/sys.go b/vendor/codeberg.org/gruf/go-store/util/sys.go
new file mode 100644
index 000000000..6661029e5
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-store/util/sys.go
@@ -0,0 +1,14 @@
+package util
+
+import "syscall"
+
+// RetryOnEINTR is a low-level filesystem function for retrying syscalls on O_EINTR received
+func RetryOnEINTR(do func() error) error {
+ for {
+ err := do()
+ if err == syscall.EINTR {
+ continue
+ }
+ return err
+ }
+}