basefs

package
v0.0.0-...-24ba59d Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package basefs implements a base filesystem caching entries

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotImplemented basic Not implemented error
	ErrNotImplemented = errors.New("Not implemented")
	// ErrPermission permission denied error
	ErrPermission = errors.New("Permission denied")
)

Functions

This section is empty.

Types

type BaseFS

type BaseFS struct {
	fuseutil.NotImplementedFileSystem // Defaults

	Config *core.Config //core   *core.Core // Core Config instead?
	Root   *FileContainer

	Service Service
	// contains filtered or unexported fields
}

BaseFS data

func New

func New(core *core.Core) *BaseFS

New Creates a new BaseFS with config based on core

func (*BaseFS) CheckForChanges

func (fs *BaseFS) CheckForChanges()

CheckForChanges polling

func (*BaseFS) CreateFile

func (fs *BaseFS) CreateFile(ctx context.Context, op *fuseops.CreateFileOp) (err error)

CreateFile creates empty file in google Drive and returns its ID and attributes, only allows file creation on 'My Drive' Cloud SPECIFIC

func (*BaseFS) FlushFile

func (fs *BaseFS) FlushFile(ctx context.Context, op *fuseops.FlushFileOp) (err error)

FlushFile just returns no error, maybe upload should be handled here COMMON

func (*BaseFS) ForgetInode

func (fs *BaseFS) ForgetInode(ctx context.Context, op *fuseops.ForgetInodeOp) (err error)

ForgetInode allows to forgetInode COMMON

func (*BaseFS) GetInodeAttributes

func (fs *BaseFS) GetInodeAttributes(ctx context.Context, op *fuseops.GetInodeAttributesOp) (err error)

GetInodeAttributes return attributes COMMON

func (*BaseFS) GetXAttr

func (fs *BaseFS) GetXAttr(ctx context.Context, op *fuseops.GetXattrOp) (err error)

GetXAttr special attributes COMMON

func (*BaseFS) LookUpInode

func (fs *BaseFS) LookUpInode(ctx context.Context, op *fuseops.LookUpInodeOp) (err error)

LookUpInode based on Parent and Name we return a self cached inode Cloud be COMMON but has specific ID

func (*BaseFS) MkDir

func (fs *BaseFS) MkDir(ctx context.Context, op *fuseops.MkDirOp) (err error)

MkDir creates a directory on a parent dir

func (*BaseFS) OpenDir

func (fs *BaseFS) OpenDir(ctx context.Context, op *fuseops.OpenDirOp) (err error)

OpenDir return nil error allows open dir COMMON for drivers

func (*BaseFS) OpenFile

func (fs *BaseFS) OpenFile(ctx context.Context, op *fuseops.OpenFileOp) (err error)

OpenFile creates a temporary handle to be handled on read or write XXX: Check what to do if the tempfile exists locally

func (*BaseFS) ReadDir

func (fs *BaseFS) ReadDir(ctx context.Context, op *fuseops.ReadDirOp) (err error)

ReadDir lists files into readdirop Common for drivers

func (*BaseFS) ReadFile

func (fs *BaseFS) ReadFile(ctx context.Context, op *fuseops.ReadFileOp) (err error)

ReadFile if the first time we download the google drive file into a local temporary file COMMON but specific in cache

func (*BaseFS) Refresh

func (fs *BaseFS) Refresh()

Refresh should be renamed to Load or something

func (*BaseFS) ReleaseDirHandle

func (fs *BaseFS) ReleaseDirHandle(ctx context.Context, op *fuseops.ReleaseDirHandleOp) (err error)

ReleaseDirHandle deletes file handle entry COMMON

func (*BaseFS) ReleaseFileHandle

func (fs *BaseFS) ReleaseFileHandle(ctx context.Context, op *fuseops.ReleaseFileHandleOp) (err error)

ReleaseFileHandle closes and deletes any temporary files, upload in case if changed locally COMMON

func (*BaseFS) Rename

func (fs *BaseFS) Rename(ctx context.Context, op *fuseops.RenameOp) (err error)

Rename fuse implementation

func (*BaseFS) RmDir

func (fs *BaseFS) RmDir(ctx context.Context, op *fuseops.RmDirOp) (err error)

RmDir fuse implementation

func (*BaseFS) SetInodeAttributes

func (fs *BaseFS) SetInodeAttributes(ctx context.Context, op *fuseops.SetInodeAttributesOp) (err error)

SetInodeAttributes Not sure what attributes gdrive support we just leave this blank for now SPECIFIC code

func (*BaseFS) Start

func (fs *BaseFS) Start()

Start BaseFS service with loop for changes

func (*BaseFS) StatFS

func (fs *BaseFS) StatFS(ctx context.Context, op *fuseops.StatFSOp) (err error)

StatFS this is used by DF -- TESTING

func (fs *BaseFS) Unlink(ctx context.Context, op *fuseops.UnlinkOp) (err error)

Unlink remove file and remove from local cache entry SPECIFIC

func (*BaseFS) WriteFile

func (fs *BaseFS) WriteFile(ctx context.Context, op *fuseops.WriteFileOp) (err error)

WriteFile as ReadFile it creates a temporary file on first read Maybe the ReadFile should be called here aswell to cache current contents since we are using writeAt CLOUD SPECIFIC

type Change

type Change struct {
	ID     string
	File   *File
	Remove bool
}

Change information retrieved by API deltas

type File

type File struct {
	ID           string
	Name         string
	Size         uint64
	CreatedTime  time.Time
	ModifiedTime time.Time
	AccessedTime time.Time
	Mode         os.FileMode
	Parents      []string
	Data         interface{} // Any thing
}

File entry structure all basefs based services must use these

func (*File) HasParent

func (f *File) HasParent(parent *File) bool

HasParent check file parenting

type FileContainer

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

FileContainer will hold file entries

func NewFileContainer

func NewFileContainer(fs *BaseFS) *FileContainer

NewFileContainer creates and initialize a FileContainer

func (*FileContainer) Count

func (fc *FileContainer) Count() int

Count the total number of fileentries

func (*FileContainer) CreateFile

func (fc *FileContainer) CreateFile(parentFile *FileEntry, name string, isDir bool) (*FileEntry, error)

CreateFile tell service to create a file

func (*FileContainer) DeleteFile

func (fc *FileContainer) DeleteFile(entry *FileEntry) error

DeleteFile tell service to delete a file

func (*FileContainer) FileEntry

func (fc *FileContainer) FileEntry(file *File, inodeOps ...fuseops.InodeID) *FileEntry

FileEntry Create or Update a FileEntry by inode, inode is an optional argument

func (*FileContainer) FindByID

func (fc *FileContainer) FindByID(id string) *FileEntry

FindByID retrives by ID

func (*FileContainer) FindByInode

func (fc *FileContainer) FindByInode(inode fuseops.InodeID) *FileEntry

FindByInode retrieves a file entry by inode

func (*FileContainer) ListByParent

func (fc *FileContainer) ListByParent(parent *FileEntry) []*FileEntry

ListByParent entries from parent

func (*FileContainer) Lookup

func (fc *FileContainer) Lookup(parent *FileEntry, name string) *FileEntry

Lookup retrives a FileEntry from a parent(folder) with name

func (*FileContainer) LookupByID

func (fc *FileContainer) LookupByID(parentID string, name string) *FileEntry

LookupByID lookup by remote ID

func (*FileContainer) RemoveEntry

func (fc *FileContainer) RemoveEntry(entry *FileEntry)

RemoveEntry remove file entry

func (*FileContainer) SetEntry

func (fc *FileContainer) SetEntry(inode fuseops.InodeID, entry *FileEntry)

SetEntry Adds an entry to file container based on inode

type FileEntry

type FileEntry struct {
	sync.Mutex
	Inode fuseops.InodeID         // Inode
	File  *File                   // Remote file information
	Name  string                  // local name
	Attr  fuseops.InodeAttributes // Cached attributes
	// contains filtered or unexported fields
}

FileEntry entry to handle files

func (*FileEntry) Cache

func (fe *FileEntry) Cache(fc *FileContainer) *FileWrapper

Cache download cloud file to a temporary local file or return already created file

func (*FileEntry) ClearCache

func (fe *FileEntry) ClearCache() (err error)

ClearCache remove local file XXX: move this to FileEntry

func (*FileEntry) HasParent

func (fe *FileEntry) HasParent(parent *FileEntry) bool

HasParent check Parent by entry

func (*FileEntry) HasParentID

func (fe *FileEntry) HasParentID(parentID string) bool

HasParentID check parent by cloud ID

func (*FileEntry) IsDir

func (fe *FileEntry) IsDir() bool

IsDir returns true if entry is a directory:w

func (*FileEntry) SetFile

func (fe *FileEntry) SetFile(file *File, uid, gid uint32)

SetFile update attributes and set drive.File

func (*FileEntry) Sync

func (fe *FileEntry) Sync(fc *FileContainer) (err error)

Sync will flush, upload file and update local entry

func (*FileEntry) Truncate

func (fe *FileEntry) Truncate() (err error)

Truncate truncates localFile to 0 bytes

type FileWrapper

type FileWrapper struct {
	*os.File
}

FileWrapper helper to prevent http.Post to close my files

func (*FileWrapper) Close

func (f *FileWrapper) Close() error

Close ignore close

func (*FileWrapper) RealClose

func (f *FileWrapper) RealClose() error

RealClose to be called internally to close the file

type Service

type Service interface {
	Changes() ([]*Change, error)
	ListAll() ([]*File, error)
	Create(parent *File, name string, isDir bool) (*File, error)
	//Truncate(file *File) (*File, error)
	Upload(reader io.Reader, file *File) (*File, error)
	DownloadTo(w io.Writer, file *File) error
	Move(file *File, newParent *File, name string) (*File, error)
	Delete(file *File) error
	//-- implementing
	StatFS(*fuseops.StatFSOp) error
}

Service interface

Jump to

Keyboard shortcuts

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