roghfs

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 17 Imported by: 5

README

roghfs

Roghfs stands for Read-Only GitHub File System. This is an afero.Fs implementation allowing efficient reads for file content of remote Github repositories. The provided Github auth token may allow for accessing private repositories too. The original use case for this package came from Kayron, our release operator.

Roghfs Overview

Usage

afero.Walk takes a standard filepath.WalkFunc, so that you can traverse any Github repository as if it were located on your host machine. Note that this file system implementation has been built with concurrency in mind, and basic synchronization primitives are in place, though real concurrency under load has not been tested at the time of writing. If you ever encounter any problems, please create an issue or reach out otherwise.

// https://github.com/0xSplits/kayron/commit/d2f2a18b998172039c6f2a325d4c83de20819e3e

gfs := roghfs.New(roghfs.Config{
	Bas: afero.NewMemMapFs(),
	Git: github.NewClient(nil).WithAuthToken("..."),
	Own: "0xSplits",
	Rep: "kayron",
	Ref: "d2f2a18b998172039c6f2a325d4c83de20819e3e",
})

err := afero.Walk(gfs, ".", func(pat string, fil fs.FileInfo, err error) error {
  return nil
})
Development

All changes made need to comply with the afero.Fs interface first and foremost. There is an integration test configured to run in CI, which provides a pretty good indicator for whether the package works as expected. It should be straight forward to abstract the current implementation further in order to inject remote clients other than the current tightly coupled Github client, e.g. Gitlab or Bitbucket etc.

type Fs interface {
	// Create creates a file in the filesystem, returning the file and an
	// error, if any happens.
	Create(name string) (File, error)

	// Mkdir creates a directory in the filesystem, return an error if any
	// happens.
	Mkdir(name string, perm os.FileMode) error

	// MkdirAll creates a directory path and all parents that does not exist
	// yet.
	MkdirAll(path string, perm os.FileMode) error

	// Open opens a file, returning it or an error, if any happens.
	Open(name string) (File, error)

	// OpenFile opens a file using the given flags and the given mode.
	OpenFile(name string, flag int, perm os.FileMode) (File, error)

	// Remove removes a file identified by name, returning an error, if any
	// happens.
	Remove(name string) error

	// RemoveAll removes a directory path and any children it contains. It
	// does not fail if the path does not exist (return nil).
	RemoveAll(path string) error

	// Rename renames a file.
	Rename(oldname, newname string) error

	// Stat returns a FileInfo describing the named file, or an error, if any
	// happens.
	Stat(name string) (os.FileInfo, error)

	// The name of this FileSystem
	Name() string

	// Chmod changes the mode of the named file to mode.
	Chmod(name string, mode os.FileMode) error

	// Chown changes the uid and gid of the named file.
	Chown(name string, uid, gid int) error

	// Chtimes changes the access and modification times of the named file
	Chtimes(name string, atime time.Time, mtime time.Time) error
}

Documentation

Overview

Package roghfs implements a read-only afero.Fs for remote Github repositories. If you do not trust the read-only guarantees of this implementation, then you can wrap it in afero's own read-only interface via afero.NewReadOnlyFs(). Roghfs fetches the remote source files from the configured remote Github repository on first file system read, and delegates all further I/O operations to the injected base file system, e.g. afero.NewMemMapFs().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsFileAlreadyCached

func IsFileAlreadyCached(err error) bool

func IsInvalidRepositoryUrl

func IsInvalidRepositoryUrl(err error) bool

func Parse

func Parse(str string) (string, string, error)

Parse tries to return the repository owner and the repository name for a standard GitHub repository URL.

https://github.com/owner/repo

Types

type Config

type Config struct {
	// Bas is the interface for the base file system that all repository source
	// files are written to.
	Bas afero.Fs

	// Git is the authenticated Github client used to access the configured
	// repository source files.
	Git *github.Client

	// Own is the name of the Github organization that owns the repository to read
	// from.
	Own string

	// Rep is the name of the Github repository to read from.
	Rep string

	// Ref is the Git specific release tag or commit sha, in order to guarantee
	// consistent file system reads across time. Branch names are invalid, and the
	// reserved value "HEAD" must not be provided either, because those transitive
	// references may point to changing tree states eventually.
	Ref string
}

type Roghfs

type Roghfs struct {
	// contains filtered or unexported fields
}

func New

func New(c Config) *Roghfs

func (*Roghfs) Chmod

func (r *Roghfs) Chmod(_ string, _ os.FileMode) error

Chmod does nothing but returning the error syscall.EPERM.

func (*Roghfs) Chown

func (r *Roghfs) Chown(_ string, _ int, _ int) error

Chown does nothing but returning the error syscall.EPERM.

func (*Roghfs) Chtimes

func (r *Roghfs) Chtimes(n string, _ time.Time, _ time.Time) error

Chtimes does nothing but returning the error syscall.EPERM.

func (*Roghfs) Create

func (r *Roghfs) Create(_ string) (afero.File, error)

Create does nothing but returning the error syscall.EPERM.

func (*Roghfs) Mkdir

func (r *Roghfs) Mkdir(_ string, _ os.FileMode) error

Mkdir does nothing but returning the error syscall.EPERM.

func (*Roghfs) MkdirAll

func (r *Roghfs) MkdirAll(_ string, _ os.FileMode) error

MkdirAll does nothing but returning the error syscall.EPERM.

func (*Roghfs) Name

func (r *Roghfs) Name() string

func (*Roghfs) Open

func (r *Roghfs) Open(pat string) (afero.File, error)

Open tries to open the given file. Note that Open() is called after every walk function loop for directories when using afero.Walk().

func (*Roghfs) OpenFile

func (r *Roghfs) OpenFile(pat string, flg int, prm os.FileMode) (afero.File, error)

OpenFile opens a file using the given flags and the given permissions. The error syscall.EPERM is returned if the provided flags request any form of write access.

func (*Roghfs) Remove

func (r *Roghfs) Remove(_ string) error

Remove does nothing but returning the error syscall.EPERM.

func (*Roghfs) RemoveAll

func (r *Roghfs) RemoveAll(_ string) error

RemoveAll does nothing but returning the error syscall.EPERM.

func (*Roghfs) Rename

func (r *Roghfs) Rename(_ string, _ string) error

Rename does nothing but returning the error syscall.EPERM.

func (*Roghfs) Stat

func (r *Roghfs) Stat(pat string) (os.FileInfo, error)

Stat tries to return an instance of os.FileInfo for the given file path. Note that Stat is called before every loop of the walk function of afero.Walk, because Stat provides the fs.FileInfo instance for every walk function call. The first call of Stat will also setup the entire file and folder structure within the underlying base file system. If the given file does not exist after all, an os.PathError is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL