ocfl

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package ocfl for manipulating and checking Oxford Common Filesystem Layout This Oxford Common File Layout (OCFL) specification describes an application-independent approach to the storage of digital information in a structured, transparent, and predictable manner. It is designed to promote long-term object management best practices within digital repositories. https://ocfl.io

Index

Constants

View Source
const (
	ExtensionStorageRootPathName    = "StorageRootPath"
	ExtensionObjectContentPathName  = "ObjectContentPath"
	ExtensionObjectExtractPathName  = "ObjectExtractPath"
	ExtensionObjectExternalPathName = "ObjectExternalPath"
	ExtensionContentChangeName      = "ContentChange"
	ExtensionObjectChangeName       = "ObjectChange"
	ExtensionFixityDigestName       = "FixityDigest"
	ExtensionMetadataName           = "Metadata"
	ExtensionAreaName               = "Area"
	ExtensionStreamName             = "Stream"
	ExtensionNewVersionName         = "NewVersion"
	ExtensionInitialName            = "Initial"
)
View Source
const (
	E000 = ValidationErrorCode("E000")
	E001 = ValidationErrorCode("E001")
	E002 = ValidationErrorCode("E002")
	E003 = ValidationErrorCode("E003")
	E004 = ValidationErrorCode("E004")
	E005 = ValidationErrorCode("E005")
	E006 = ValidationErrorCode("E006")
	E007 = ValidationErrorCode("E007")
	E008 = ValidationErrorCode("E008")
	E009 = ValidationErrorCode("E009")
	E010 = ValidationErrorCode("E010")
	E011 = ValidationErrorCode("E011")
	E012 = ValidationErrorCode("E012")
	E013 = ValidationErrorCode("E013")
	E014 = ValidationErrorCode("E014")
	E015 = ValidationErrorCode("E015")
	E016 = ValidationErrorCode("E016")
	E017 = ValidationErrorCode("E017")
	E018 = ValidationErrorCode("E018")
	E019 = ValidationErrorCode("E019")
	E020 = ValidationErrorCode("E020")
	E021 = ValidationErrorCode("E021")
	E022 = ValidationErrorCode("E022")
	E023 = ValidationErrorCode("E023")
	E024 = ValidationErrorCode("E024")
	E025 = ValidationErrorCode("E025")
	E026 = ValidationErrorCode("E026")
	E027 = ValidationErrorCode("E027")
	E028 = ValidationErrorCode("E028")
	E029 = ValidationErrorCode("E029")
	E030 = ValidationErrorCode("E030")
	E031 = ValidationErrorCode("E031")
	E032 = ValidationErrorCode("E032")
	E033 = ValidationErrorCode("E033")
	E034 = ValidationErrorCode("E034")
	E035 = ValidationErrorCode("E035")
	E036 = ValidationErrorCode("E036")
	E037 = ValidationErrorCode("E037")
	E038 = ValidationErrorCode("E038")
	E039 = ValidationErrorCode("E039")
	E040 = ValidationErrorCode("E040")
	E041 = ValidationErrorCode("E041")
	E042 = ValidationErrorCode("E042")
	E043 = ValidationErrorCode("E043")
	E044 = ValidationErrorCode("E044")
	E045 = ValidationErrorCode("E045")
	E046 = ValidationErrorCode("E046")
	E047 = ValidationErrorCode("E047")
	E048 = ValidationErrorCode("E048")
	E049 = ValidationErrorCode("E049")
	E050 = ValidationErrorCode("E050")
	E051 = ValidationErrorCode("E051")
	E052 = ValidationErrorCode("E052")
	E053 = ValidationErrorCode("E053")
	E054 = ValidationErrorCode("E054")
	E055 = ValidationErrorCode("E055")
	E056 = ValidationErrorCode("E056")
	E057 = ValidationErrorCode("E057")
	E058 = ValidationErrorCode("E058")
	E059 = ValidationErrorCode("E059")
	E060 = ValidationErrorCode("E060")
	E061 = ValidationErrorCode("E061")
	E062 = ValidationErrorCode("E062")
	E063 = ValidationErrorCode("E063")
	E064 = ValidationErrorCode("E064")
	E066 = ValidationErrorCode("E066")
	E067 = ValidationErrorCode("E067")
	E068 = ValidationErrorCode("E068")
	E069 = ValidationErrorCode("E069")
	E070 = ValidationErrorCode("E070")
	E071 = ValidationErrorCode("E071")
	E072 = ValidationErrorCode("E072")
	E073 = ValidationErrorCode("E073")
	E074 = ValidationErrorCode("E074")
	E075 = ValidationErrorCode("E075")
	E076 = ValidationErrorCode("E076")
	E077 = ValidationErrorCode("E077")
	E078 = ValidationErrorCode("E078")
	E079 = ValidationErrorCode("E079")
	E080 = ValidationErrorCode("E080")
	E081 = ValidationErrorCode("E081")
	E082 = ValidationErrorCode("E082")
	E083 = ValidationErrorCode("E083")
	E084 = ValidationErrorCode("E084")
	E085 = ValidationErrorCode("E085")
	E086 = ValidationErrorCode("E086")
	E087 = ValidationErrorCode("E087")
	E088 = ValidationErrorCode("E088")
	E089 = ValidationErrorCode("E089")
	E090 = ValidationErrorCode("E090")
	E091 = ValidationErrorCode("E091")
	E092 = ValidationErrorCode("E092")
	E093 = ValidationErrorCode("E093")
	E094 = ValidationErrorCode("E094")
	E095 = ValidationErrorCode("E095")
	E096 = ValidationErrorCode("E096")
	E097 = ValidationErrorCode("E097")
	E098 = ValidationErrorCode("E098")
	E099 = ValidationErrorCode("E099")
	E100 = ValidationErrorCode("E100")
	E101 = ValidationErrorCode("E101")
	E102 = ValidationErrorCode("E102")
	E103 = ValidationErrorCode("E103")
	E104 = ValidationErrorCode("E104")
	E105 = ValidationErrorCode("E105")
	E106 = ValidationErrorCode("E106")
	E107 = ValidationErrorCode("E107")
	E108 = ValidationErrorCode("E108")
	E110 = ValidationErrorCode("E110")
	E111 = ValidationErrorCode("E111")
	E112 = ValidationErrorCode("E112")
	W000 = ValidationErrorCode("W000")
	W001 = ValidationErrorCode("W001")
	W002 = ValidationErrorCode("W002")
	W003 = ValidationErrorCode("W003")
	W004 = ValidationErrorCode("W004")
	W005 = ValidationErrorCode("W005")
	W007 = ValidationErrorCode("W007")
	W008 = ValidationErrorCode("W008")
	W009 = ValidationErrorCode("W009")
	W010 = ValidationErrorCode("W010")
	W011 = ValidationErrorCode("W011")
	W012 = ValidationErrorCode("W012")
	W013 = ValidationErrorCode("W013")
	W014 = ValidationErrorCode("W014")
	W015 = ValidationErrorCode("W015")
	W016 = ValidationErrorCode("W016")
)
View Source
const (
	ContentDirectory1_0 = "content"
)
View Source
const (
	ContentDirectory1_1 = "content"
)
View Source
const DefaultExtensionInitialName = "initial"
View Source
const DefaultExtensionManagerName = "NNNN-gocfl-extension-manager"
View Source
const ObjectV11Version = "1.1"
View Source
const ObjectV20Version = "2.0"

Variables

View Source
var ErrFilenameTooLong = errors.New("filename too long")
View Source
var ErrPathnameTooLong = errors.New("pathname too long")
View Source
var ExtensionObjectExtractPathWrongAreaError = fmt.Errorf("invalid area")
View Source
var OCFLValidationError1_0 = map[ValidationErrorCode]*ValidationError{}/* 116 elements not displayed */
View Source
var OCFLValidationError1_1 = map[ValidationErrorCode]*ValidationError{}/* 125 elements not displayed */
View Source
var OCFLValidationErrorMapping1_0 = map[ValidationErrorCode]ValidationErrorCode{
	E104: E001,
}
View Source
var OCFLValidationErrorMapping1_1 = map[ValidationErrorCode]ValidationErrorCode{}
View Source
var OCFLVersionRegexp = regexp.MustCompile("^0=ocfl_([0-9]+\\.[0-9]+)$")
View Source
var StatInfoString = map[string]StatInfo{
	"ObjectFolders":          StatObjectFolders,
	"Extension":              StatExtension,
	"ExtensionConfigs":       StatExtensionConfigs,
	"Objects":                StatObjects,
	"ObjectVersions":         StatObjectVersions,
	"ObjectVersionState":     StatObjectVersionState,
	"ObjectManifest":         StatObjectManifest,
	"ObjectExtension":        StatObjectExtension,
	"ObjectExtensionConfigs": StatObjectExtensionConfigs,
}

Functions

func CleanPath

func CleanPath(fname string, MaxFilenameLength, MaxPathnameLength int) (string, error)

func FixFilename

func FixFilename(fname string) string

FixFilename *********************************************************************

  • 1) Forbid/escape ASCII control characters (bytes 1-31 and 127) in filenames, including newline, escape, and tab.
  • I know of no user or program that actually requires this capability. As far as I can tell, this capability
  • exists only to make it hard to write correct software, to ease the job of attackers, and to create
  • interoperability problems. Chuck it.
  • 2) Forbid/escape leading “-”. This way, you can always distinguish option flags from filenames, eliminating a host
  • of stupid emperror. Nobody in their right mind writes programs that depend on having dash-prefixed files on a Unix
  • system. Even on Windows systems they’re a bad idea, because many programs use “-” instead of “/” to identify options.
  • 3) Forbid/escape filenames that aren’t a valid UTF-8 encoding. This way, filenames can always be correctly displayed.
  • Trying to use environment values like LC_ALL (or other LC_* values) or LANG is just a hack that often fails. This
  • will take time, as people slowly transition and minor tool problems get fixed, but I believe that transition is
  • already well underway.
  • 4) Forbid/escape leading/trailing space characters — at least trailing spaces. Adjacent spaces are somewhat dodgy,
  • too. These confuse users when they happen, with no utility. In particular, filenames that are only space characters
  • are nothing but trouble. Some systems may want to go further and forbid space characters outright, but I doubt that’ll
  • be acceptable everywhere, and with the other approaches these are less necessary. As noted above, an interesting
  • alternative would be quietly convert (in the API) all spaces into unbreakable spaces.
  • 5) Forbid/escape “problematic” characters that get specially interpreted by shells, other interpreters (such as perl),
  • and HTML/XML. This is less important, and I would expect this to happen (at most) on specific systems. With the steps
  • above, a lot of programs and statements like “cat *” just work correctly. But funny characters cause troubles for shell
  • scripts and perl, because they need to quote them when typing in commands.. and they often forget to do so. They can
  • also be a cause for trouble when they’re passed down to other programs, especially if they run “exec” and so on. They’re
  • also helpful for web applications, again, because the characters that should be escapes are sometimes not escaped. A short
  • list would be “*”, “?”, and “[”; by eliminating those three characters and control characters from filenames, and removing
  • the space character from IFS, you can process filenames in shells without quoting variable references — eliminating a
  • common source of emperror. Forbidding/escaping “<” and “>” would eliminate a source of nasty errors for perl programs, web
  • applications, and anyone using HTML or XML. A more stringent list would be “*?:[]"<>|(){}&'!\;” (this is Glindra’s “safe”
  • list with ampersand, single-quote, bang, backslash, and semicolon added). This list is probably a little extreme, but let’s
  • try and see. As noted earlier, I’d need to go through a complete analysis of all characters for a final list; for security,
  • you want to identify everything that is permissible, and disallow everything else, but its manifestation can be either way
  • as long as you’ve considered all possible cases. But if this set can be determined locally, based on local requirements,
  • there’s less need to get complete agreement on a list.
  • 6) Forbid/escape leading “~” (tilde). Shells specially interpret such filenames. This is definitely low priority. *
  • https://www.dwheeler.com/essays/fixing-unix-linux-filenames.html

func Fullpath added in v2.0.3

func Fullpath(path string) (string, error)

func GetErrorStacktrace

func GetErrorStacktrace(err error) errors.StackTrace

func InventoryIsEqual

func InventoryIsEqual(i1, i2 Inventory) bool

func NewContextValidation

func NewContextValidation(parent context.Context) context.Context

func ReadFile

func ReadFile(object Object, name, version, storageType, storageName string, fsys fs.FS) ([]byte, error)

func ReadJsonL

func ReadJsonL(object Object, name, version, compress, storageType, storageName string, fsys fs.FS) ([]byte, error)

func SpecIsLessOrEqual

func SpecIsLessOrEqual(s1, s2 InventorySpec) bool

return true if Specification s1 < s2

func ValidVersion

func ValidVersion(version OCFLVersion) bool

func WriteJsonL

func WriteJsonL(object Object, name string, brotliData []byte, compress, storageType, storageName string, fsys fs.FS) error

Types

type Extension

type Extension interface {
	GetName() string
	SetFS(fsys fs.FS)
	GetFS() fs.FS
	SetParams(params map[string]string) error
	WriteConfig() error
	//GetConfigString() string
	GetConfig() any
	IsRegistered() bool
}

func NewInitialDummyFS

func NewInitialDummyFS(fsys fs.FS) (Extension, error)

type ExtensionArea

type ExtensionArea interface {
	Extension
	GetAreaPath(object Object, area string) (string, error)
}

type ExtensionConfig

type ExtensionConfig struct {
	ExtensionName string `json:"extensionName"`
}

type ExtensionContentChange

type ExtensionContentChange interface {
	Extension
	AddFileBefore(object Object, sourceFS fs.FS, source string, dest string, area string, isDir bool) error
	UpdateFileBefore(object Object, sourceFS fs.FS, source, dest, area string, isDir bool) error
	DeleteFileBefore(object Object, dest string, area string) error
	AddFileAfter(object Object, sourceFS fs.FS, source []string, internalPath, digest, area string, isDir bool) error
	UpdateFileAfter(object Object, sourceFS fs.FS, source, dest, area string, isDir bool) error
	DeleteFileAfter(object Object, dest string, area string) error
}

type ExtensionExternalParam

type ExtensionExternalParam struct {
	ExtensionName string
	Functions     []string
	Param         string
	//	File          string
	Description string
	Default     string
}

func (*ExtensionExternalParam) GetCobraName

func (eep *ExtensionExternalParam) GetCobraName() string

func (*ExtensionExternalParam) GetParam

func (eep *ExtensionExternalParam) GetParam(cmd *cobra.Command, conf *config.GOCFLConfig) (name, value string)

func (*ExtensionExternalParam) SetParam

func (eep *ExtensionExternalParam) SetParam(cmd *cobra.Command)

type ExtensionFactory

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

func NewExtensionFactory

func NewExtensionFactory(params map[string]string, logger zLogger.ZWrapper) (*ExtensionFactory, error)

func (*ExtensionFactory) AddCreator

func (f *ExtensionFactory) AddCreator(name string, creator creatorFunc)

func (*ExtensionFactory) AddObjectDefaultExtension

func (f *ExtensionFactory) AddObjectDefaultExtension(ext Extension)

func (*ExtensionFactory) AddStorageRootDefaultExtension

func (f *ExtensionFactory) AddStorageRootDefaultExtension(ext Extension)

func (*ExtensionFactory) Create

func (f *ExtensionFactory) Create(fsys fs.FS) (Extension, error)

func (*ExtensionFactory) CreateExtensions

func (f *ExtensionFactory) CreateExtensions(fsys fs.FS, validation Validation) (ExtensionManager, error)

func (*ExtensionFactory) LoadExtensions

func (f *ExtensionFactory) LoadExtensions(fsys fs.FS, validation Validation) (ExtensionManager, error)

type ExtensionFixityDigest

type ExtensionFixityDigest interface {
	Extension
	GetFixityDigests() []checksum.DigestAlgorithm
}

type ExtensionInitial added in v2.0.3

type ExtensionInitial interface {
	Extension
	GetExtension() string
	SetExtension(ext string)
}

type ExtensionManagerConfig

type ExtensionManagerConfig struct {
	*ExtensionConfig
	Sort      map[string][]string   `json:"sort"`
	Exclusion map[string][][]string `json:"exclusion"`
}

type ExtensionMetadata

type ExtensionMetadata interface {
	Extension
	GetMetadata(object Object) (map[string]any, error)
}

type ExtensionNewVersion

type ExtensionNewVersion interface {
	Extension
	NeedNewVersion(object Object) (bool, error)
	DoNewVersion(object Object) error
}

type ExtensionObjectChange

type ExtensionObjectChange interface {
	Extension
	UpdateObjectBefore(object Object) error
	UpdateObjectAfter(object Object) error
}

type ExtensionObjectContentPath

type ExtensionObjectContentPath interface {
	Extension
	BuildObjectManifestPath(object Object, originalPath string, area string) (string, error)
}

type ExtensionObjectExtractPath

type ExtensionObjectExtractPath interface {
	Extension
	BuildObjectExtractPath(object Object, originalPath string, area string) (string, error)
}

type ExtensionObjectStatePath

type ExtensionObjectStatePath interface {
	Extension
	BuildObjectStatePath(object Object, originalPath string, area string) (string, error)
}

type ExtensionStorageRootPath

type ExtensionStorageRootPath interface {
	Extension
	WriteLayout(fsys fs.FS) error
	BuildStorageRootPath(storageRoot StorageRoot, id string) (string, error)
}

type ExtensionStream

type ExtensionStream interface {
	Extension
	StreamObject(object Object, reader io.Reader, stateFiles []string, dest string) error
}

type FileMetadata

type FileMetadata struct {
	Checksums    map[checksum.DigestAlgorithm]string
	InternalName []string
	VersionName  map[string][]string
	Extension    map[string]any
}

type Fixity

type Fixity map[checksum.DigestAlgorithm]map[string][]string

func (Fixity) Checksums

func (f Fixity) Checksums(filename string) map[checksum.DigestAlgorithm]string

type InitialDummy

type InitialDummy struct {
	*ExtensionManagerConfig
}

func NewInitialDummy

func NewInitialDummy(config *ExtensionManagerConfig) (*InitialDummy, error)

func (*InitialDummy) GetConfig

func (dummy *InitialDummy) GetConfig() any

func (*InitialDummy) GetConfigString

func (dummy *InitialDummy) GetConfigString() string

func (*InitialDummy) GetFS

func (dummy *InitialDummy) GetFS() fs.FS

func (*InitialDummy) GetName

func (dummy *InitialDummy) GetName() string

func (*InitialDummy) IsRegistered

func (dummy *InitialDummy) IsRegistered() bool

func (*InitialDummy) SetFS

func (dummy *InitialDummy) SetFS(fsys fs.FS)

func (*InitialDummy) SetParams

func (dummy *InitialDummy) SetParams(params map[string]string) error

func (*InitialDummy) WriteConfig

func (dummy *InitialDummy) WriteConfig() error

type Inventory

type Inventory interface {
	Finalize(inCreation bool) error
	IsEqual(i2 Inventory) bool
	Init(id string, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm) error
	GetID() string
	GetContentDir() string
	GetRealContentDir() string
	GetHead() string
	GetSpec() InventorySpec
	CheckFiles(fileManifest map[checksum.DigestAlgorithm]map[string][]string) error

	DeleteFile(stateFilename string) error
	RenameFile(stateSource, stateDest string) error
	//Rename(oldVirtualFilename, newVirtualFilename string) error
	AddFile(stateFilenames []string, manifestFilename string, checksums map[checksum.DigestAlgorithm]string) error
	CopyFile(dest string, digest string) error

	IterateStateFiles(version string, fn StateFileCallback) error
	GetStateFiles(version string, cs string) ([]string, error)

	//GetContentDirectory() string
	GetVersionStrings() []string
	GetVersions() map[string]*Version
	GetFiles() map[string][]string
	GetManifest() map[string][]string
	GetFixity() Fixity
	GetFilesFlat() []string
	GetDigestAlgorithm() checksum.DigestAlgorithm
	GetFixityDigestAlgorithm() []checksum.DigestAlgorithm
	IsWriteable() bool
	IsModified() bool
	BuildManifestName(stateFilename string) string
	BuildManifestNameVersion(stateFilename string, version string) string
	NewVersion(msg, UserName, UserAddress string) error
	GetDuplicates(checksum string) []string
	AlreadyExists(stateFilename, checksum string) (bool, error)
	//	IsUpdate(virtualFilename, checksum string) (bool, error)
	Clean() error

	VersionLessOrEqual(v1, v2 string) bool
	// contains filtered or unexported methods
}

type InventoryBase

type InventoryBase struct {
	Id               string                                           `json:"id"`
	Type             InventorySpec                                    `json:"type"`
	DigestAlgorithm  checksum.DigestAlgorithm                         `json:"digestAlgorithm"`
	Head             *OCFLString                                      `json:"head"`
	ContentDirectory string                                           `json:"contentDirectory,omitempty"`
	Manifest         *OCFLManifest                                    `json:"manifest,omitempty"`
	Versions         *OCFLVersions                                    `json:"versions"`
	Fixity           map[checksum.DigestAlgorithm]map[string][]string `json:"fixity,omitempty"`
	// contains filtered or unexported fields
}

func (*InventoryBase) AddFile

func (i *InventoryBase) AddFile(stateFilenames []string, manifestFilename string, checksums map[checksum.DigestAlgorithm]string) error

func (*InventoryBase) AlreadyExists

func (i *InventoryBase) AlreadyExists(stateFilename, checksum string) (bool, error)

func (*InventoryBase) BuildManifestName

func (i *InventoryBase) BuildManifestName(stateFilename string) string

func (*InventoryBase) BuildManifestNameVersion

func (i *InventoryBase) BuildManifestNameVersion(stateFilename string, version string) string

func (*InventoryBase) CheckFiles

func (i *InventoryBase) CheckFiles(fileManifest map[checksum.DigestAlgorithm]map[string][]string) error

func (*InventoryBase) Clean

func (i *InventoryBase) Clean() error

clear unmodified version

func (*InventoryBase) CopyFile

func (i *InventoryBase) CopyFile(dest string, digest string) error

func (*InventoryBase) DeleteFile

func (i *InventoryBase) DeleteFile(stateFilename string) error

func (*InventoryBase) Finalize

func (i *InventoryBase) Finalize(inCreation bool) (err error)

func (*InventoryBase) GetContentDir

func (i *InventoryBase) GetContentDir() string

func (*InventoryBase) GetDigestAlgorithm

func (i *InventoryBase) GetDigestAlgorithm() checksum.DigestAlgorithm

func (*InventoryBase) GetDuplicates

func (i *InventoryBase) GetDuplicates(checksum string) []string

func (*InventoryBase) GetFiles

func (i *InventoryBase) GetFiles() map[string][]string

func (*InventoryBase) GetFilesFlat

func (i *InventoryBase) GetFilesFlat() []string

func (*InventoryBase) GetFixity

func (i *InventoryBase) GetFixity() Fixity

func (*InventoryBase) GetFixityDigestAlgorithm

func (i *InventoryBase) GetFixityDigestAlgorithm() []checksum.DigestAlgorithm

func (*InventoryBase) GetHead

func (i *InventoryBase) GetHead() string

func (*InventoryBase) GetID

func (i *InventoryBase) GetID() string

func (*InventoryBase) GetManifest

func (i *InventoryBase) GetManifest() map[string][]string

func (*InventoryBase) GetRealContentDir

func (i *InventoryBase) GetRealContentDir() string

func (*InventoryBase) GetSpec

func (i *InventoryBase) GetSpec() InventorySpec

func (*InventoryBase) GetStateFiles

func (i *InventoryBase) GetStateFiles(version string, cs string) ([]string, error)

func (*InventoryBase) GetVersionStrings

func (i *InventoryBase) GetVersionStrings() []string

func (*InventoryBase) GetVersions

func (i *InventoryBase) GetVersions() map[string]*Version

func (*InventoryBase) Init

func (i *InventoryBase) Init(id string, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm) (err error)

func (*InventoryBase) IsModified

func (i *InventoryBase) IsModified() bool

func (*InventoryBase) IsUpdate

func (i *InventoryBase) IsUpdate(virtualFilename, checksum string) (bool, error)

func (*InventoryBase) IsWriteable

func (i *InventoryBase) IsWriteable() bool

func (*InventoryBase) IterateStateFiles

func (i *InventoryBase) IterateStateFiles(version string, fn StateFileCallback) error

func (*InventoryBase) NewVersion

func (i *InventoryBase) NewVersion(msg, UserName, UserAddress string) error

func (*InventoryBase) RenameFile

func (i *InventoryBase) RenameFile(stateSource, stateDest string) error

func (*InventoryBase) VersionLessOrEqual

func (i *InventoryBase) VersionLessOrEqual(v1, v2 string) bool

type InventorySpec

type InventorySpec string
const (
	InventorySpec1_0 InventorySpec = "https://ocfl.io/1.0/spec/#inventory"
	InventorySpec1_1 InventorySpec = "https://ocfl.io/1.1/spec/#inventory"
)

type InventoryV1_0

type InventoryV1_0 struct {
	*InventoryBase
}

func (*InventoryV1_0) IsEqual

func (i *InventoryV1_0) IsEqual(i2 Inventory) bool

type InventoryV1_1

type InventoryV1_1 struct {
	*InventoryBase
}

func (*InventoryV1_1) IsEqual

func (i *InventoryV1_1) IsEqual(i2 Inventory) bool

type NamesStruct

type NamesStruct struct {
	ExternalPaths []string
	InternalPath  string
	ManifestPath  string
}

type OCFLManifest

type OCFLManifest struct {
	Manifest map[string][]string
	// contains filtered or unexported fields
}

func (*OCFLManifest) MarshalJSON

func (m *OCFLManifest) MarshalJSON() ([]byte, error)

func (*OCFLManifest) UnmarshalJSON

func (m *OCFLManifest) UnmarshalJSON(data []byte) error

type OCFLState

type OCFLState struct {
	State map[string][]string
	// contains filtered or unexported fields
}

func (*OCFLState) MarshalJSON

func (s *OCFLState) MarshalJSON() ([]byte, error)

func (*OCFLState) UnmarshalJSON

func (s *OCFLState) UnmarshalJSON(data []byte) error

type OCFLString

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

func NewOCFLString

func NewOCFLString(str string) *OCFLString

func (*OCFLString) MarshalJSON

func (s *OCFLString) MarshalJSON() ([]byte, error)

func (*OCFLString) String

func (s *OCFLString) String() string

func (*OCFLString) UnmarshalJSON

func (s *OCFLString) UnmarshalJSON(data []byte) error

type OCFLTime

type OCFLTime struct {
	time.Time
	// contains filtered or unexported fields
}

func (*OCFLTime) MarshalJSON

func (t *OCFLTime) MarshalJSON() ([]byte, error)

func (*OCFLTime) UnmarshalJSON

func (t *OCFLTime) UnmarshalJSON(data []byte) error

type OCFLUser

type OCFLUser struct {
	User
	// contains filtered or unexported fields
}

func NewOCFLUser

func NewOCFLUser(name, address string) *OCFLUser

func (*OCFLUser) Finalize

func (u *OCFLUser) Finalize()

func (*OCFLUser) UnmarshalJSON

func (u *OCFLUser) UnmarshalJSON(data []byte) error

type OCFLVersion

type OCFLVersion string
const Version1_0 OCFLVersion = "1.0"
const Version1_1 OCFLVersion = "1.1"
const Version2_0 OCFLVersion = "2.0"

func GetObjectVersion

func GetObjectVersion(ctx context.Context, ofs fs.FS) (version OCFLVersion, err error)

type OCFLVersions

type OCFLVersions struct {
	Versions map[string]*Version
	// contains filtered or unexported fields
}

func (*OCFLVersions) GetVersion

func (v *OCFLVersions) GetVersion(version string) (*Version, error)

func (*OCFLVersions) MarshalJSON

func (v *OCFLVersions) MarshalJSON() ([]byte, error)

func (*OCFLVersions) UnmarshalJSON

func (v *OCFLVersions) UnmarshalJSON(data []byte) error

type Object

type Object interface {
	LoadInventory(folder string) (Inventory, error)
	CreateInventory(id string, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm) (Inventory, error)
	StoreInventory(version bool, objectRoot bool) error
	GetInventory() Inventory
	StoreExtensions() error
	Init(id string, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm, manager ExtensionManager) error
	Load() error
	StartUpdate(sourceFS fs.FS, msg string, UserName string, UserAddress string, echo bool) (fs.FS, error)
	EndUpdate() error
	BeginArea(area string)
	EndArea() error
	AddFolder(fsys fs.FS, versionFS fs.FS, checkDuplicate bool, area string) error
	AddFile(fsys fs.FS, versionFS fs.FS, path string, checkDuplicate bool, area string, noExtensionHook bool, isDir bool) error
	AddData(data []byte, path string, checkDuplicate bool, area string, noExtensionHook bool, isDir bool) error
	AddReader(r io.ReadCloser, files []string, area string, noExtensionHook bool, isDir bool) (string, error)
	DeleteFile(virtualFilename string, digest string) error
	RenameFile(virtualFilenameSource, virtualFilenameDest string, digest string) error
	GetID() string
	GetVersion() OCFLVersion
	Check() error
	Close() error
	GetFS() fs.FS
	IsModified() bool
	Stat(w io.Writer, statInfo []StatInfo) error
	Extract(fsys fs.FS, version string, withManifest bool, area string) error
	GetMetadata() (*ObjectMetadata, error)
	GetAreaPath(area string) (string, error)
	GetExtensionManager() ExtensionManager
	BuildNames(files []string, area string) (*NamesStruct, error)
}

type ObjectBase

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

func (*ObjectBase) AddData

func (object *ObjectBase) AddData(data []byte, path string, checkDuplicate bool, area string, noExtensionHook bool, isDir bool) error

func (*ObjectBase) AddFile

func (object *ObjectBase) AddFile(fsys fs.FS, versionFS fs.FS, path string, checkDuplicate bool, area string, noExtensionHook bool, isDir bool) error

func (*ObjectBase) AddFolder

func (object *ObjectBase) AddFolder(fsys fs.FS, versionFS fs.FS, checkDuplicate bool, area string) error

func (*ObjectBase) AddReader

func (object *ObjectBase) AddReader(r io.ReadCloser, files []string, area string, noExtensionHook bool, isDir bool) (string, error)

func (*ObjectBase) BeginArea

func (object *ObjectBase) BeginArea(area string)

func (*ObjectBase) BuildNames

func (object *ObjectBase) BuildNames(files []string, area string) (*NamesStruct, error)

func (*ObjectBase) Check

func (object *ObjectBase) Check() error

func (*ObjectBase) Close

func (object *ObjectBase) Close() error

func (*ObjectBase) CreateInventory

func (object *ObjectBase) CreateInventory(id string, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm) (Inventory, error)

func (*ObjectBase) DeleteFile

func (object *ObjectBase) DeleteFile(virtualFilename string, digest string) error

func (*ObjectBase) EndArea

func (object *ObjectBase) EndArea() error

func (*ObjectBase) EndUpdate

func (object *ObjectBase) EndUpdate() error

func (*ObjectBase) Extract

func (object *ObjectBase) Extract(fsys fs.FS, version string, withManifest bool, area string) error

func (*ObjectBase) GetAreaPath

func (object *ObjectBase) GetAreaPath(area string) (string, error)

func (*ObjectBase) GetDigestAlgorithm

func (object *ObjectBase) GetDigestAlgorithm() checksum.DigestAlgorithm

func (*ObjectBase) GetExtensionManager

func (object *ObjectBase) GetExtensionManager() ExtensionManager

func (*ObjectBase) GetFS

func (object *ObjectBase) GetFS() fs.FS

func (*ObjectBase) GetID

func (object *ObjectBase) GetID() string

func (*ObjectBase) GetInventory

func (object *ObjectBase) GetInventory() Inventory

func (*ObjectBase) GetMetadata

func (object *ObjectBase) GetMetadata() (*ObjectMetadata, error)

func (*ObjectBase) GetVersion

func (object *ObjectBase) GetVersion() OCFLVersion

func (*ObjectBase) Init

func (object *ObjectBase) Init(id string, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm, extensionManager ExtensionManager) error

func (*ObjectBase) IsModified

func (object *ObjectBase) IsModified() bool

func (*ObjectBase) Load

func (object *ObjectBase) Load() (err error)

func (*ObjectBase) LoadInventory

func (object *ObjectBase) LoadInventory(folder string) (Inventory, error)

loadInventory loads inventory from existing Object

func (*ObjectBase) RenameFile

func (object *ObjectBase) RenameFile(virtualFilenameSource, virtualFilenameDest string, digest string) error

func (*ObjectBase) StartUpdate

func (object *ObjectBase) StartUpdate(sourceFS fs.FS, msg string, UserName string, UserAddress string, echo bool) (fs.FS, error)

func (*ObjectBase) Stat

func (object *ObjectBase) Stat(w io.Writer, statInfo []StatInfo) error

func (*ObjectBase) StoreExtensions

func (object *ObjectBase) StoreExtensions() error

func (*ObjectBase) StoreInventory

func (object *ObjectBase) StoreInventory(version bool, objectRoot bool) error

type ObjectMetadata

type ObjectMetadata struct {
	ID              string
	DigestAlgorithm checksum.DigestAlgorithm
	Head            string
	Versions        map[string]*VersionMetadata
	Files           map[string]*FileMetadata
	Extension       any
}

type ObjectV1_0

type ObjectV1_0 struct {
	*ObjectBase
}

type ObjectV1_1

type ObjectV1_1 struct {
	*ObjectBase
}

type ObjectV2_0 added in v2.0.3

type ObjectV2_0 struct {
	*ObjectBase
}

type StatInfo

type StatInfo int64
const (
	StatObjectFolders StatInfo = iota
	StatExtension
	StatExtensionConfigs
	StatObjects
	StatObjectVersions
	StatObjectVersionState
	StatObjectManifest
	StatObjectExtension
	StatObjectExtensionConfigs
)

type StateFileCallback

type StateFileCallback func(internal []string, external []string, digest string) error

type StorageRoot

type StorageRoot interface {
	fmt.Stringer
	GetDigest() checksum.DigestAlgorithm
	SetDigest(digest checksum.DigestAlgorithm)
	GetFiles() ([]string, error)
	GetFolders() ([]string, error)
	GetObjectFolders() ([]string, error)
	ObjectExists(id string) (bool, error)
	LoadObjectByFolder(folder string) (Object, error)
	LoadObjectByID(id string) (Object, error)
	CreateObject(id string, version OCFLVersion, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm, manager ExtensionManager) (Object, error)
	CreateExtension(fsys fs.FS) (Extension, error)
	CreateExtensions(fsys fs.FS, validation Validation) (ExtensionManager, error)
	Check() error
	CheckObjectByFolder(objectFolder string) error
	CheckObjectByID(objectID string) error
	Init(version OCFLVersion, digest checksum.DigestAlgorithm, manager ExtensionManager) error
	Load() error
	IsModified() bool

	GetVersion() OCFLVersion
	Stat(w io.Writer, path string, id string, statInfo []StatInfo) error
	Extract(fsys fs.FS, path, id, version string, withManifest bool, area string) error
	ExtractMeta(path, id string) (*StorageRootMetadata, error)
	// contains filtered or unexported methods
}

func CreateStorageRoot

func CreateStorageRoot(ctx context.Context, fsys fs.FS, version OCFLVersion, extensionFactory *ExtensionFactory, extensionManager ExtensionManager, digest checksum.DigestAlgorithm, logger zLogger.ZWrapper) (StorageRoot, error)

func LoadStorageRoot

func LoadStorageRoot(ctx context.Context, fsys fs.FS, extensionFactory *ExtensionFactory, logger zLogger.ZWrapper) (StorageRoot, error)

func LoadStorageRootRO

func LoadStorageRootRO(ctx context.Context, fsys fs.FS, extensionFactory *ExtensionFactory, logger zLogger.ZWrapper) (StorageRoot, error)

type StorageRootBase

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

func NewStorageRootBase

func NewStorageRootBase(ctx context.Context, fsys fs.FS, defaultVersion OCFLVersion, extensionFactory *ExtensionFactory, extensionManager ExtensionManager, logger zLogger.ZWrapper) (*StorageRootBase, error)

NewOCFL creates an empty OCFL structure

func (*StorageRootBase) Check

func (osr *StorageRootBase) Check() error

func (*StorageRootBase) CheckDirectory

func (osr *StorageRootBase) CheckDirectory() (err error)

func (*StorageRootBase) CheckObjectByFolder

func (osr *StorageRootBase) CheckObjectByFolder(objectFolder string) error

func (*StorageRootBase) CheckObjectByID

func (osr *StorageRootBase) CheckObjectByID(objectID string) error

func (*StorageRootBase) CheckObjects

func (osr *StorageRootBase) CheckObjects() error

func (*StorageRootBase) Context

func (osr *StorageRootBase) Context() context.Context

func (*StorageRootBase) CreateExtension

func (osr *StorageRootBase) CreateExtension(fsys fs.FS) (Extension, error)

func (*StorageRootBase) CreateExtensions added in v2.0.3

func (osr *StorageRootBase) CreateExtensions(fsys fs.FS, validation Validation) (ExtensionManager, error)

func (*StorageRootBase) CreateObject

func (osr *StorageRootBase) CreateObject(id string, version OCFLVersion, digest checksum.DigestAlgorithm, fixity []checksum.DigestAlgorithm, manager ExtensionManager) (Object, error)

func (*StorageRootBase) Extract

func (osr *StorageRootBase) Extract(fsys fs.FS, path, id, version string, withManifest bool, area string) error

func (*StorageRootBase) ExtractMeta

func (osr *StorageRootBase) ExtractMeta(path, id string) (*StorageRootMetadata, error)

func (*StorageRootBase) GetDigest

func (osr *StorageRootBase) GetDigest() checksum.DigestAlgorithm

func (*StorageRootBase) GetFiles

func (osr *StorageRootBase) GetFiles() ([]string, error)

func (*StorageRootBase) GetFolders

func (osr *StorageRootBase) GetFolders() ([]string, error)

func (*StorageRootBase) GetObjectFolders

func (osr *StorageRootBase) GetObjectFolders() ([]string, error)

all folder trees, which end in a folder containing a file

func (*StorageRootBase) GetVersion

func (osr *StorageRootBase) GetVersion() OCFLVersion

func (*StorageRootBase) Init

func (osr *StorageRootBase) Init(version OCFLVersion, digest checksum.DigestAlgorithm, extensionManager ExtensionManager) error

func (*StorageRootBase) IsModified

func (osr *StorageRootBase) IsModified() bool

func (*StorageRootBase) Load

func (osr *StorageRootBase) Load() error

func (*StorageRootBase) LoadObjectByFolder

func (osr *StorageRootBase) LoadObjectByFolder(folder string) (Object, error)

func (*StorageRootBase) LoadObjectByID

func (osr *StorageRootBase) LoadObjectByID(id string) (object Object, err error)

func (*StorageRootBase) ObjectExists

func (osr *StorageRootBase) ObjectExists(id string) (bool, error)

func (*StorageRootBase) SetDigest

func (osr *StorageRootBase) SetDigest(digest checksum.DigestAlgorithm)

func (*StorageRootBase) Stat

func (osr *StorageRootBase) Stat(w io.Writer, path string, id string, statInfo []StatInfo) error

func (*StorageRootBase) StoreExtensionConfig

func (osr *StorageRootBase) StoreExtensionConfig(name string, config any) error

func (*StorageRootBase) String

func (osr *StorageRootBase) String() string

type StorageRootMetadata

type StorageRootMetadata struct {
	Objects map[string]*ObjectMetadata
}

type StorageRootV1_0

type StorageRootV1_0 struct {
	*StorageRootBase
}

func NewStorageRootV1_0

func NewStorageRootV1_0(ctx context.Context, fsys fs.FS, extensionFactory *ExtensionFactory, manager ExtensionManager, logger zLogger.ZWrapper) (*StorageRootV1_0, error)

type StorageRootV1_1

type StorageRootV1_1 struct {
	*StorageRootBase
}

func NewStorageRootV1_1

func NewStorageRootV1_1(ctx context.Context, fsys fs.FS, extensionFactory *ExtensionFactory, extensionManager ExtensionManager, logger zLogger.ZWrapper) (*StorageRootV1_1, error)

func (*StorageRootV1_1) Init

func (osr *StorageRootV1_1) Init(version OCFLVersion, digest checksum.DigestAlgorithm, manager ExtensionManager) error

type StorageRootV2_0 added in v2.0.3

type StorageRootV2_0 struct {
	*StorageRootBase
}

func NewStorageRootV2_0 added in v2.0.3

func NewStorageRootV2_0(ctx context.Context, fsys fs.FS, extensionFactory *ExtensionFactory, extensionManager ExtensionManager, logger zLogger.ZWrapper) (*StorageRootV2_0, error)

func (*StorageRootV2_0) Init added in v2.0.3

func (osr *StorageRootV2_0) Init(version OCFLVersion, digest checksum.DigestAlgorithm, manager ExtensionManager) error

type User

type User struct {
	Address *OCFLString `json:"address,omitempty"`
	Name    *OCFLString `json:"name"`
}

type Validation added in v2.0.3

type Validation interface {
	// contains filtered or unexported methods
}

type ValidationError

type ValidationError struct {
	Code         ValidationErrorCode
	Description  string
	Ref          string
	Description2 string
	Context      string
}

func GetValidationError

func GetValidationError(version OCFLVersion, errno ValidationErrorCode) *ValidationError

func (*ValidationError) AppendContext

func (ve *ValidationError) AppendContext(format string, a ...any) *ValidationError

func (*ValidationError) AppendDescription

func (ve *ValidationError) AppendDescription(format string, a ...any) *ValidationError

func (*ValidationError) Error

func (verr *ValidationError) Error() string

type ValidationErrorCode

type ValidationErrorCode string

type ValidationStatus

type ValidationStatus struct {
	Errors []*ValidationError
}

func GetValidationStatus

func GetValidationStatus(ctx context.Context) (*ValidationStatus, error)

func (*ValidationStatus) Compact

func (status *ValidationStatus) Compact()

removes duplicate errors

type Version

type Version struct {
	Created *OCFLTime   `json:"created"`
	Message *OCFLString `json:"message"`
	State   *OCFLState  `json:"state"`
	User    *OCFLUser   `json:"user"`
}

func (*Version) EqualMeta

func (v *Version) EqualMeta(v2 *Version) bool

func (*Version) EqualState

func (v *Version) EqualState(v2 *Version) bool

type VersionMetadata

type VersionMetadata struct {
	Created time.Time
	Message string
	Name    string
	Address string
}

Jump to

Keyboard shortcuts

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