vrctFs

package
v0.0.0-...-17ed7cf Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const VirtualFilePostfix = ".prototype.bson"
View Source
const VirtualFsPathPrefix = "/tmp/spito-vrct/fs"

Variables

This section is empty.

Functions

func CompareConfigs

func CompareConfigs(received, desired []byte, configType FileType) error

func GetBsonMap

func GetBsonMap(pathToFile string) (map[string]interface{}, error)

func GetMapFromBytes

func GetMapFromBytes(content []byte, configType FileType) (map[string]interface{}, error)

func GetSerializedRevertStepsDir

func GetSerializedRevertStepsDir() (string, error)

func MoveFile

func MoveFile(source string, destination string) error

func SaveBsonMap

func SaveBsonMap(toSave map[string]interface{}, pathToFile string) error

Types

type DirEntry

type DirEntry struct {
	StatFn func() (fs.FileInfo, error)
	// contains filtered or unexported fields
}

func (DirEntry) Info

func (d DirEntry) Info() (fs.FileInfo, error)

func (DirEntry) IsDir

func (d DirEntry) IsDir() bool

func (DirEntry) Name

func (d DirEntry) Name() string

func (DirEntry) Type

func (d DirEntry) Type() fs.FileMode

type FileInfo

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

func (FileInfo) IsDir

func (f FileInfo) IsDir() bool

func (FileInfo) ModTime

func (f FileInfo) ModTime() time.Time

func (FileInfo) Mode

func (f FileInfo) Mode() fs.FileMode

func (FileInfo) Name

func (f FileInfo) Name() string

func (FileInfo) Size

func (f FileInfo) Size() int64

func (FileInfo) Sys

func (f FileInfo) Sys() any

type FilePrototype

type FilePrototype struct {
	Layers               []PrototypeLayer
	RealFileExists       bool
	FileType             FileType
	OriginalFileIncluded bool
	Path                 string `bson:"-"`
	Name                 string `bson:"-"`
}

func (*FilePrototype) AddNewLayer

func (p *FilePrototype) AddNewLayer(layer PrototypeLayer, isOriginal bool) error

func (*FilePrototype) CreateLayer

func (p *FilePrototype) CreateLayer(content []byte, options []byte, isOptional bool) (PrototypeLayer, error)

func (*FilePrototype) Read

func (p *FilePrototype) Read(vrctPrefix string, realPath string) error

func (*FilePrototype) Save

func (p *FilePrototype) Save() error

func (*FilePrototype) SimulateFile

func (p *FilePrototype) SimulateFile() ([]byte, error)

type FileType

type FileType int
const (
	TextFile FileType = iota
	JsonConfig
	YamlConfig
	TomlConfig
)

type PrototypeLayer

type PrototypeLayer struct {
	// If ContentPath is specified and file exists in real fs, real file will be later overridden by this content
	// (We don't store content as string in order to make bson lightweight and fast accessible)
	ContentPath string `bson:",omitempty"`
	OptionsPath string `bson:",omitempty"`
	IsOptional  bool
}

func (*PrototypeLayer) GetContent

func (layer *PrototypeLayer) GetContent() ([]byte, error)

func (*PrototypeLayer) SetContent

func (layer *PrototypeLayer) SetContent(content []byte) error

type RevertStep

type RevertStep struct {
	Path   string `bson:"Path"`
	Action int    `bson:"Action"`
	// OldContentPath field is optional
	OldContentPath string `bson:"OldContentPath"`
}

func (*RevertStep) Apply

func (r *RevertStep) Apply() error

type RevertSteps

type RevertSteps struct {
	Steps         []RevertStep `bson:"Steps"`
	RulesToRevert []Rule       `bson:"RulesToRevert"`
	RevertTempDir string       `bson:"-"`
}

func NewRevertSteps

func NewRevertSteps() (RevertSteps, error)

func (*RevertSteps) Apply

func (r *RevertSteps) Apply(revertFn func(rule Rule) error) error

func (*RevertSteps) BackupOldContent

func (r *RevertSteps) BackupOldContent(path string) error

func (*RevertSteps) DeleteRuntimeTemp

func (r *RevertSteps) DeleteRuntimeTemp() error

func (*RevertSteps) Deserialize

func (r *RevertSteps) Deserialize(revertNum int) error

func (*RevertSteps) RemoveDirAll

func (r *RevertSteps) RemoveDirAll(path string)

func (*RevertSteps) RemoveFile

func (r *RevertSteps) RemoveFile(path string)

func (*RevertSteps) Serialize

func (r *RevertSteps) Serialize(rulesToRevert []Rule) (int, error)

Serialize first return value is number which should be provided to deserialize propert RevertSteps

type Rule

type Rule struct {
	Url          string `json:"url" bson:"url"`
	NameOrScript string `json:"nameOrScript" bson:"nameOrScript"`
	IsScript     bool   `json:"isScript" bson:"isScript"`
}

type VRCTFs

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

func NewFsVRCT

func NewFsVRCT() (VRCTFs, error)

func (*VRCTFs) Apply

func (v *VRCTFs) Apply(rulesHistory []Rule, serializeRevertSteps bool) (int, error)

Apply first parameter takes array of identifiers returns revertNumber if serializeRevertSteps is true

func (*VRCTFs) Copy

func (v *VRCTFs) Copy(from, to string) error

Copy TODO: it doesn't handle situation when destination is not empty

func (*VRCTFs) CreateConfig

func (v *VRCTFs) CreateConfig(filePath string, content []byte, optionalKeys []byte, isOptional bool, fileType FileType) error

CreateConfig function creating or updating configuration file

Arguments:

filePath - Path to file
content - content of file
optionalKeys - json or yaml document describing which key in config is optional
isOptional - default option in configs / is able to merge in text files
fileType - given 0 - text file, otherwise config specified in file_type.go

func (*VRCTFs) CreateFile

func (v *VRCTFs) CreateFile(filePath string, content []byte, isOptional bool) error

CreateFile function creating file

Arguments:

filePath - Path to file
content - content of file
isOptional - default option in configs / is able to merge in text files

func (*VRCTFs) DeleteRuntimeTemp

func (v *VRCTFs) DeleteRuntimeTemp() error

func (*VRCTFs) ReadDir

func (v *VRCTFs) ReadDir(dirPath string) ([]os.DirEntry, error)

func (*VRCTFs) ReadFile

func (v *VRCTFs) ReadFile(filePath string) ([]byte, error)

func (*VRCTFs) Revert

func (v *VRCTFs) Revert(fn func(rule Rule) error) error

func (*VRCTFs) Stat

func (v *VRCTFs) Stat(filePath string) (os.FileInfo, error)

func (*VRCTFs) UpdateConfig

func (v *VRCTFs) UpdateConfig(filePath string, content []byte, optionalKeys []byte, isOptional bool, fileType FileType) error

Jump to

Keyboard shortcuts

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