fileTree

package
v0.0.0-...-18b418f Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IgnoreFilenames = []string{
	".DS_Store",
}

Functions

This section is empty.

Types

type FileAction

type FileAction struct {
	Timestamp  time.Time      `json:"timestamp" bson:"timestamp"`
	ActionType FileActionType `json:"actionType" bson:"actionType"`

	OriginPath string `json:"originPath" bson:"originPath,omitempty"`
	// OriginId        FileId `json:"originId" bson:"originId,omitempty"`
	DestinationPath string `json:"destinationPath" bson:"destinationPath,omitempty"`

	LifeId  FileId      `json:"lifeId" bson:"lifeId"`
	EventId FileEventId `json:"eventId" bson:"eventId"`

	Size     int64  `json:"size" bson:"size"`
	ParentId FileId `json:"parentId" bson:"ParentId"`
	ServerId string `json:"serverId" bson:"serverId"`

	LifeNext *FileAction `json:"-" bson:"-"`
	LifePrev *FileAction `json:"-" bson:"-"`
	// contains filtered or unexported fields
}

func (*FileAction) GetActionType

func (fa *FileAction) GetActionType() FileActionType

func (*FileAction) GetDestinationPath

func (fa *FileAction) GetDestinationPath() string

func (*FileAction) GetEventId

func (fa *FileAction) GetEventId() FileEventId

func (*FileAction) GetFile

func (fa *FileAction) GetFile() *WeblensFileImpl

func (*FileAction) GetLifetimeId

func (fa *FileAction) GetLifetimeId() FileId

func (*FileAction) GetOriginPath

func (fa *FileAction) GetOriginPath() string

func (*FileAction) GetParentId

func (fa *FileAction) GetParentId() FileId

func (*FileAction) GetSize

func (fa *FileAction) GetSize() int64

func (*FileAction) GetTimestamp

func (fa *FileAction) GetTimestamp() time.Time

func (*FileAction) MarshalJSON

func (fa *FileAction) MarshalJSON() ([]byte, error)

func (*FileAction) SetActionType

func (fa *FileAction) SetActionType(actionType FileActionType)

func (*FileAction) SetLifetimeId

func (fa *FileAction) SetLifetimeId(lId FileId)

func (*FileAction) SetSize

func (fa *FileAction) SetSize(size int64)

func (*FileAction) UnmarshalJSON

func (fa *FileAction) UnmarshalJSON(bs []byte) error

type FileActionType

type FileActionType string
const (
	FileCreate  FileActionType = "fileCreate"
	FileMove    FileActionType = "fileMove"
	FileWrite   FileActionType = "fileWrite"
	Backup      FileActionType = "backup"
	FileDelete  FileActionType = "fileDelete"
	FileRestore FileActionType = "fileRestore"
)

type FileEvent

type FileEvent struct {
	EventId    FileEventId   `bson:"_id"`
	Actions    []*FileAction `bson:"actions"`
	EventBegin time.Time     `bson:"eventBegin"`
	ServerId   string        `bson:"serverId"`

	ActionsLock sync.RWMutex `bson:"-"`
	// contains filtered or unexported fields
}

func (*FileEvent) GetActions

func (fe *FileEvent) GetActions() []*FileAction

func (*FileEvent) GetEventId

func (fe *FileEvent) GetEventId() FileEventId

func (*FileEvent) NewCreateAction

func (fe *FileEvent) NewCreateAction(file *WeblensFileImpl) *FileAction

func (*FileEvent) NewDeleteAction

func (fe *FileEvent) NewDeleteAction(lifeId FileId) *FileAction

func (*FileEvent) NewMoveAction

func (fe *FileEvent) NewMoveAction(lifeId FileId, file *WeblensFileImpl) *FileAction

type FileEventId

type FileEventId string

type FileId

type FileId = string

type FileTree

type FileTree interface {
	Get(id FileId) *WeblensFileImpl
	GetRoot() *WeblensFileImpl
	ReadDir(dir *WeblensFileImpl) ([]*WeblensFileImpl, error)
	Size() int

	GetJournal() Journal
	SetJournal(Journal)

	Add(file *WeblensFileImpl) error
	Del(id FileId, deleteEvent *FileEvent) ([]*WeblensFileImpl, error)
	Move(f, newParent *WeblensFileImpl, newFilename string, overwrite bool, event *FileEvent) ([]MoveInfo, error)
	Touch(parentFolder *WeblensFileImpl, newFileName string, event *FileEvent) (*WeblensFileImpl, error)
	MkDir(parentFolder *WeblensFileImpl, newDirName string, event *FileEvent) (*WeblensFileImpl, error)

	PortableToAbs(portable WeblensFilepath) (string, error)
	AbsToPortable(absPath string) (WeblensFilepath, error)
	GenerateFileId() FileId
}

func NewFileTree

func NewFileTree(rootPath, rootAlias string, hasher Hasher, journal Journal) (FileTree, error)

type FileTreeImpl

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

func (*FileTreeImpl) AbsToPortable

func (ft *FileTreeImpl) AbsToPortable(absPath string) (WeblensFilepath, error)

func (*FileTreeImpl) Add

func (ft *FileTreeImpl) Add(f *WeblensFileImpl) error

func (*FileTreeImpl) Del

func (ft *FileTreeImpl) Del(fId FileId, deleteEvent *FileEvent) ([]*WeblensFileImpl, error)

func (*FileTreeImpl) GenerateFileId

func (ft *FileTreeImpl) GenerateFileId() FileId

func (*FileTreeImpl) Get

func (ft *FileTreeImpl) Get(fileId FileId) *WeblensFileImpl

func (*FileTreeImpl) GetJournal

func (ft *FileTreeImpl) GetJournal() Journal

func (*FileTreeImpl) GetRoot

func (ft *FileTreeImpl) GetRoot() *WeblensFileImpl

func (*FileTreeImpl) MkDir

func (ft *FileTreeImpl) MkDir(
	parentFolder *WeblensFileImpl, newDirName string, event *FileEvent,
) (*WeblensFileImpl, error)

MkDir creates a new dir as a child of parentFolder named newDirName. If the dir already exists, it will be returned along with a ErrDirAlreadyExists error.

func (*FileTreeImpl) Move

func (ft *FileTreeImpl) Move(
	f, newParent *WeblensFileImpl, newFilename string, overwrite bool, event *FileEvent,
) ([]MoveInfo, error)

func (*FileTreeImpl) PortableToAbs

func (ft *FileTreeImpl) PortableToAbs(portable WeblensFilepath) (string, error)

func (*FileTreeImpl) ReadDir

func (ft *FileTreeImpl) ReadDir(dir *WeblensFileImpl) ([]*WeblensFileImpl, error)

ReadDir reads the filesystem for files it does not yet have, adds them to the tree, and returns the newly added files

func (*FileTreeImpl) SetJournal

func (ft *FileTreeImpl) SetJournal(j Journal)

func (*FileTreeImpl) Size

func (ft *FileTreeImpl) Size() int

Size gets the number of files loaded into weblens. This does not lock the file tree, and therefore cannot be trusted to be microsecond accurate, but it's quite close

func (*FileTreeImpl) Touch

func (ft *FileTreeImpl) Touch(parentFolder *WeblensFileImpl, newFileName string, event *FileEvent) (
	*WeblensFileImpl, error,
)

type HashWaiter

type HashWaiter interface {
	Hasher
	Wait()
}

type Hasher

type Hasher interface {
	Hash(file *WeblensFileImpl, event *FileEvent) error
}

type Journal

type Journal interface {
	Get(id FileId) *Lifetime
	Add(lifetime *Lifetime) error

	SetFileTree(ft *FileTreeImpl)

	NewEvent() *FileEvent
	WatchFolder(f *WeblensFileImpl) error

	LogEvent(fe *FileEvent)

	GetActionsByPath(WeblensFilepath) ([]*FileAction, error)
	GetPastFolderChildren(folder *WeblensFileImpl, time time.Time) ([]*WeblensFileImpl, error)
	GetLatestAction() (*FileAction, error)
	GetLifetimesSince(date time.Time) ([]*Lifetime, error)

	EventWorker()
	FileWatcher()
	GetActiveLifetimes() []*Lifetime
	GetAllLifetimes() []*Lifetime
}

type JournalImpl

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

func NewJournal

func NewJournal(col *mongo.Collection, serverId string) (*JournalImpl, error)

func (*JournalImpl) Add

func (j *JournalImpl) Add(lt *Lifetime) error

func (*JournalImpl) Close

func (j *JournalImpl) Close()

func (*JournalImpl) EventWorker

func (j *JournalImpl) EventWorker()

func (*JournalImpl) FileWatcher

func (j *JournalImpl) FileWatcher()

func (*JournalImpl) Get

func (j *JournalImpl) Get(lId FileId) *Lifetime

func (*JournalImpl) GetActionsByPath

func (j *JournalImpl) GetActionsByPath(path WeblensFilepath) ([]*FileAction, error)

func (*JournalImpl) GetActiveLifetimes

func (j *JournalImpl) GetActiveLifetimes() []*Lifetime

func (*JournalImpl) GetAllLifetimes

func (j *JournalImpl) GetAllLifetimes() []*Lifetime

func (*JournalImpl) GetLatestAction

func (j *JournalImpl) GetLatestAction() (*FileAction, error)

func (*JournalImpl) GetLifetimesSince

func (j *JournalImpl) GetLifetimesSince(date time.Time) ([]*Lifetime, error)

func (*JournalImpl) GetPastFolderChildren

func (j *JournalImpl) GetPastFolderChildren(folder *WeblensFileImpl, time time.Time) (
	[]*WeblensFileImpl, error,
)

func (*JournalImpl) LogEvent

func (j *JournalImpl) LogEvent(fe *FileEvent)

func (*JournalImpl) NewEvent

func (j *JournalImpl) NewEvent() *FileEvent

func (*JournalImpl) SetFileTree

func (j *JournalImpl) SetFileTree(ft *FileTreeImpl)

func (*JournalImpl) WatchFolder

func (j *JournalImpl) WatchFolder(f *WeblensFileImpl) error

type Lifetime

type Lifetime struct {
	Id FileId `bson:"_id" json:"id"`
	// LiveFileId   FileId        `bson:"liveFileId" json:"liveFileId"`
	LiveFilePath string        `bson:"liveFilePath" json:"liveFilePath"`
	ContentId    string        `bson:"contentId,omitempty" json:"contentId,omitempty"`
	Actions      []*FileAction `bson:"actions" json:"actions"`
	ServerId     string        `bson:"serverId" json:"serverId"`
	// contains filtered or unexported fields
}

func NewLifetime

func NewLifetime(createAction *FileAction) (*Lifetime, error)

func (*Lifetime) Add

func (l *Lifetime) Add(action *FileAction)

func (*Lifetime) GetActions

func (l *Lifetime) GetActions() []*FileAction

func (*Lifetime) GetContentId

func (l *Lifetime) GetContentId() string

func (*Lifetime) GetLatestAction

func (l *Lifetime) GetLatestAction() *FileAction

func (*Lifetime) GetLatestFilePath

func (l *Lifetime) GetLatestFilePath() string

func (*Lifetime) ID

func (l *Lifetime) ID() FileId

func (*Lifetime) IsLive

func (l *Lifetime) IsLive() bool

IsLive returns a boolean representing if this Lifetime shows a file currently on the real filesystem, and has not been deleted.

func (*Lifetime) SetContentId

func (l *Lifetime) SetContentId(cId string)

type MoveInfo

type MoveInfo struct {
	From *WeblensFileImpl
	To   *WeblensFileImpl
}

type WeblensFile

type WeblensFile interface {
	ID() FileId
	Write(data []byte) (int, error)
	ReadAll() ([]byte, error)
}

type WeblensFileImpl

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

func NewWeblensFile

func NewWeblensFile(id FileId, filename string, parent *WeblensFileImpl, isDir bool) *WeblensFileImpl

func (*WeblensFileImpl) AddChild

func (f *WeblensFileImpl) AddChild(child *WeblensFileImpl) error

func (*WeblensFileImpl) Append

func (f *WeblensFileImpl) Append(data []byte) error

func (*WeblensFileImpl) BubbleMap

func (f *WeblensFileImpl) BubbleMap(fn func(*WeblensFileImpl) error) error

BubbleMap Performs fn on f and all parents of f, ignoring the mediaService root or other static directories.

Files are acted on in the order of their index number below, starting with the caller, children are never accessed

f3 <- Parent of f2
|
f2 <- Parent of f1
|
f1 <- Root caller

func (*WeblensFileImpl) Close

func (f *WeblensFileImpl) Close() error

func (*WeblensFileImpl) CreateSelf

func (f *WeblensFileImpl) CreateSelf() error

func (*WeblensFileImpl) Exists

func (f *WeblensFileImpl) Exists() bool

Exists check if the file exists on the real filesystem below

func (*WeblensFileImpl) Filename

func (f *WeblensFileImpl) Filename() string

Filename returns the filename of the file

func (*WeblensFileImpl) Freeze

func (f *WeblensFileImpl) Freeze() *WeblensFileImpl

Freeze returns a "deep-enough" copy of the file descriptor. All only-locally-relevant fields are copied, however references, except for locks, are the same as the original version

func (*WeblensFileImpl) GetAbsPath

func (f *WeblensFileImpl) GetAbsPath() string

GetAbsPath returns string of the absolute path to file

func (*WeblensFileImpl) GetChild

func (f *WeblensFileImpl) GetChild(childName string) (*WeblensFileImpl, error)

func (*WeblensFileImpl) GetChildren

func (f *WeblensFileImpl) GetChildren() []*WeblensFileImpl

func (*WeblensFileImpl) GetContentId

func (f *WeblensFileImpl) GetContentId() string

func (*WeblensFileImpl) GetParent

func (f *WeblensFileImpl) GetParent() *WeblensFileImpl

func (*WeblensFileImpl) GetParentId

func (f *WeblensFileImpl) GetParentId() FileId

func (*WeblensFileImpl) GetPortablePath

func (f *WeblensFileImpl) GetPortablePath() WeblensFilepath

func (*WeblensFileImpl) ID

func (f *WeblensFileImpl) ID() FileId

ID returns the unique identifier the file, and will compute it on the fly if it is not already initialized in the struct.

This function will intentionally panic if trying to get the ID of a nil file.

func (*WeblensFileImpl) IsDir

func (f *WeblensFileImpl) IsDir() bool

func (*WeblensFileImpl) IsParentOf

func (f *WeblensFileImpl) IsParentOf(child *WeblensFileImpl) bool

func (*WeblensFileImpl) IsReadOnly

func (f *WeblensFileImpl) IsReadOnly() bool

func (*WeblensFileImpl) LeafMap

func (f *WeblensFileImpl) LeafMap(fn func(*WeblensFileImpl) error) error

LeafMap recursively perform fn on leaves, first, and work back up the tree. This will not call fn on the root file. This takes an inverted "Depth first" approach. Note this behaves very differently than RecursiveMap. See below.

Files are acted on in the order of their index number here, starting with the leftmost leaf

	fx.LeafMap(fn) <- fn not called on root caller
	|
	f5
   /  \
  f3  f4
 /  \
f1  f2

func (*WeblensFileImpl) LoadStat

func (f *WeblensFileImpl) LoadStat() (newSize int64, err error)

LoadStat will recompute the size and modify date of the file using os.Stat. If the size of the file changes, LoadStat will return the newSize. If the size does not change, LoadStat will return -1 for the newSize.

func (*WeblensFileImpl) MarshalJSON

func (f *WeblensFileImpl) MarshalJSON() ([]byte, error)

func (*WeblensFileImpl) ModTime

func (f *WeblensFileImpl) ModTime() (t time.Time)

func (*WeblensFileImpl) Mode

func (f *WeblensFileImpl) Mode() os.FileMode

func (*WeblensFileImpl) Name

func (f *WeblensFileImpl) Name() string

func (*WeblensFileImpl) Read

func (f *WeblensFileImpl) Read(p []byte) (n int, err error)

func (*WeblensFileImpl) ReadAll

func (f *WeblensFileImpl) ReadAll() ([]byte, error)

func (*WeblensFileImpl) Readable

func (f *WeblensFileImpl) Readable() (io.Reader, error)

func (*WeblensFileImpl) Readdir

func (f *WeblensFileImpl) Readdir(count int) ([]fs.FileInfo, error)

func (*WeblensFileImpl) RecursiveMap

func (f *WeblensFileImpl) RecursiveMap(fn func(*WeblensFileImpl) error) error

RecursiveMap applies function fn to every file recursively

func (*WeblensFileImpl) Seek

func (f *WeblensFileImpl) Seek(offset int64, whence int) (int64, error)

func (*WeblensFileImpl) SetContentId

func (f *WeblensFileImpl) SetContentId(newContentId string)

func (*WeblensFileImpl) SetMemOnly

func (f *WeblensFileImpl) SetMemOnly(memOnly bool)

func (*WeblensFileImpl) SetWatching

func (f *WeblensFileImpl) SetWatching() error

func (*WeblensFileImpl) Size

func (f *WeblensFileImpl) Size() int64

func (*WeblensFileImpl) Stat

func (f *WeblensFileImpl) Stat() (fs.FileInfo, error)

func (*WeblensFileImpl) Sys

func (f *WeblensFileImpl) Sys() any

func (*WeblensFileImpl) UnmarshalJSON

func (f *WeblensFileImpl) UnmarshalJSON(bs []byte) error

func (*WeblensFileImpl) Write

func (f *WeblensFileImpl) Write(data []byte) (int, error)

func (*WeblensFileImpl) WriteAt

func (f *WeblensFileImpl) WriteAt(data []byte, seekLoc int64) error

func (*WeblensFileImpl) Writeable

func (f *WeblensFileImpl) Writeable() (*os.File, error)

type WeblensFilepath

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

func NewFilePath

func NewFilePath(root, rootAlias, absolutePath string) WeblensFilepath

func ParsePortable

func ParsePortable(portablePath string) WeblensFilepath

func (WeblensFilepath) Child

func (wf WeblensFilepath) Child(childName string) WeblensFilepath

func (WeblensFilepath) RelativePath

func (wf WeblensFilepath) RelativePath() string

func (WeblensFilepath) RootName

func (wf WeblensFilepath) RootName() string

func (WeblensFilepath) String

func (wf WeblensFilepath) String() string

func (WeblensFilepath) ToPortable

func (wf WeblensFilepath) ToPortable() string

Jump to

Keyboard shortcuts

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