Git backed by object storage because you can't stop me
git object-storage kefka
0

Configure Feed

Select the types of activity you want to include in your feed.

objgit / internal / s3fs / chroot.go
1.6 kB 46 lines
1// chroot.go implements the interface billy.Chroot 2 3package s3fs 4 5import "github.com/go-git/go-billy/v6" 6 7// Chroot returns a new filesystem from the same type where the new root is 8// the given path. Files outside of the designated directory tree cannot be 9// accessed. 10func (fs3 *S3FS) Chroot(path string) (billy.Filesystem, error) { 11 // TODO: Check that path is a valid subdirectory of the current root 12 // ... 13 14 // Calculate the new root 15 p := fs3.Join(fs3.root, path) 16 17 // Create the new S3FS with the new root directory. The separator must be 18 // carried over; without it ListObjectsV2 runs with an empty delimiter and 19 // ReadDir flattens the tree, breaking directory-structured reads (e.g. git 20 // ref enumeration under refs/). 21 nfs := &S3FS{ 22 client: fs3.client, 23 bucket: fs3.bucket, 24 root: p, 25 separator: fs3.separator, 26 unixMeta: fs3.unixMeta, 27 cache: fs3.cache, 28 packCache: fs3.packCache, 29 temps: make(map[string]*tempBuffer), 30 } 31 32 // A chroot is one repository. Register its root as a recursive subtree prefix 33 // so the whole repo is answered from one delimiter-less scan: this is what 34 // makes subtree caching actually engage for the canonical "<repo>/refs/...", 35 // "<repo>/objects/..." keys (a bucket-root prefix like "refs/" never matches 36 // them), collapsing git's per-object and per-folder listings into one. 37 if fs3.cache != nil && p != "" && p != "." { 38 fs3.cache.registerRoot(p) 39 } 40 return nfs, nil 41} 42 43// Root returns the root path of the filesystem. 44func (fs3 *S3FS) Root() string { 45 return fs3.root 46}