fs

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Octal

func Octal(i uint32) string

Octal converts a number to its octal representation in string form.

func UnmountHandler

func UnmountHandler(signal <-chan os.Signal, server *fuse.Server)

UnmountHandler should be used as goroutine that will handle sigint then exit gracefully

Types

type FileSystemInfo

type FileSystemInfo struct {
	LastModifiedDateTime time.Time `json:"lastModifiedDateTime,omitempty"`
}

FileSystemInfo carries the filesystem metadata like Mtime/Atime

type Filesystem added in v0.12.0

type Filesystem struct {
	fuse.RawFileSystem

	sync.RWMutex
	// contains filtered or unexported fields
}

Filesystem is the actual FUSE filesystem and uses the go analogy of the "low-level" FUSE API here: https://github.com/libfuse/libfuse/blob/master/include/fuse_lowlevel.h

func NewFilesystem added in v0.12.0

func NewFilesystem(auth *graph.Auth, cacheDir string) *Filesystem

NewFilesystem creates a new filesystem

func (*Filesystem) Create added in v0.12.0

func (f *Filesystem) Create(cancel <-chan struct{}, in *fuse.CreateIn, name string, out *fuse.CreateOut) fuse.Status

Create creates a regular file and opens it. The server doesn't have this yet.

func (*Filesystem) DeleteID added in v0.12.0

func (f *Filesystem) DeleteID(id string)

DeleteID deletes an item from the cache, and removes it from its parent. Must be called before InsertID if being used to rename/move an item.

func (*Filesystem) DeletePath added in v0.12.0

func (f *Filesystem) DeletePath(key string)

DeletePath an item from the cache by path. Must be called before Insert if being used to move/rename an item.

func (*Filesystem) DeltaLoop added in v0.12.0

func (f *Filesystem) DeltaLoop(interval time.Duration)

DeltaLoop creates a new thread to poll the server for changes and should be called as a goroutine

func (*Filesystem) Flush added in v0.12.0

func (f *Filesystem) Flush(cancel <-chan struct{}, in *fuse.FlushIn) fuse.Status

Flush is called when a file descriptor is closed. Uses Fsync() to perform file uploads. (Release not implemented because all cleanup is already done here).

func (*Filesystem) Fsync added in v0.12.0

func (f *Filesystem) Fsync(cancel <-chan struct{}, in *fuse.FsyncIn) fuse.Status

Fsync is a signal to ensure writes to the Inode are flushed to stable storage. This method is used to trigger uploads of file content.

func (*Filesystem) GetAttr added in v0.12.0

func (f *Filesystem) GetAttr(cancel <-chan struct{}, in *fuse.GetAttrIn, out *fuse.AttrOut) fuse.Status

Getattr returns a the Inode as a UNIX stat. Holds the read mutex for all of the "metadata fetch" operations.

func (*Filesystem) GetChild added in v0.12.0

func (f *Filesystem) GetChild(id string, name string, auth *graph.Auth) (*Inode, error)

GetChild fetches a named child of an item. Wraps GetChildrenID.

func (*Filesystem) GetChildrenID added in v0.12.0

func (f *Filesystem) GetChildrenID(id string, auth *graph.Auth) (map[string]*Inode, error)

GetChildrenID grabs all DriveItems that are the children of the given ID. If items are not found, they are fetched.

func (*Filesystem) GetChildrenPath added in v0.12.0

func (f *Filesystem) GetChildrenPath(path string, auth *graph.Auth) (map[string]*Inode, error)

GetChildrenPath grabs all DriveItems that are the children of the resource at the path. If items are not found, they are fetched.

func (*Filesystem) GetID added in v0.12.0

func (f *Filesystem) GetID(id string) *Inode

GetID gets an inode from the cache by ID. No API fetching is performed. Result is nil if no inode is found.

func (*Filesystem) GetNodeID added in v0.12.0

func (f *Filesystem) GetNodeID(nodeID uint64) *Inode

GetNodeID fetches the inode for a particular inode ID.

func (*Filesystem) GetPath added in v0.12.0

func (f *Filesystem) GetPath(path string, auth *graph.Auth) (*Inode, error)

GetPath fetches a given DriveItem in the cache, if any items along the way are not found, they are fetched.

func (*Filesystem) InsertChild added in v0.12.0

func (f *Filesystem) InsertChild(parentID string, child *Inode) uint64

InsertChild adds an item as a child of a specified parent ID.

func (*Filesystem) InsertID added in v0.12.0

func (f *Filesystem) InsertID(id string, inode *Inode) uint64

InsertID inserts a single item into the filesystem by ID and sets its parent using the Inode.Parent.ID, if set. Must be called after DeleteID, if being used to rename/move an item. This is the main way new Inodes are added to the filesystem. Returns the Inode's numeric NodeID.

func (*Filesystem) InsertNodeID added in v0.12.0

func (f *Filesystem) InsertNodeID(inode *Inode) uint64

InsertNodeID assigns a numeric inode ID used by the kernel if one is not already assigned.

func (*Filesystem) InsertPath added in v0.12.0

func (f *Filesystem) InsertPath(key string, auth *graph.Auth, inode *Inode) (uint64, error)

InsertPath lets us manually insert an item to the cache (like if it was created locally). Overwrites a cached item if present. Must be called after delete if being used to move/rename an item.

func (*Filesystem) IsOffline added in v0.12.0

func (f *Filesystem) IsOffline() bool

IsOffline returns whether or not the cache thinks its offline.

func (*Filesystem) Lookup added in v0.12.0

func (f *Filesystem) Lookup(cancel <-chan struct{}, in *fuse.InHeader, name string, out *fuse.EntryOut) fuse.Status

Lookup is called by the kernel when the VFS wants to know about a file inside a directory.

func (*Filesystem) Mkdir added in v0.12.0

func (f *Filesystem) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out *fuse.EntryOut) fuse.Status

Mkdir creates a directory.

func (*Filesystem) Mknod added in v0.12.0

func (f *Filesystem) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out *fuse.EntryOut) fuse.Status

Mknod creates a regular file. The server doesn't have this yet.

func (*Filesystem) MoveID added in v0.12.0

func (f *Filesystem) MoveID(oldID string, newID string) error

MoveID moves an item to a new ID name. Also responsible for handling the actual overwrite of the item's IDInternal field

func (*Filesystem) MovePath added in v0.12.0

func (f *Filesystem) MovePath(oldParent, newParent, oldName, newName string, auth *graph.Auth) error

MovePath moves an item to a new position.

func (*Filesystem) Open added in v0.12.0

func (f *Filesystem) Open(cancel <-chan struct{}, in *fuse.OpenIn, out *fuse.OpenOut) fuse.Status

Open fetches a Inodes's content and initializes the .Data field with actual data from the server.

func (*Filesystem) OpenDir added in v0.12.0

func (f *Filesystem) OpenDir(cancel <-chan struct{}, in *fuse.OpenIn, out *fuse.OpenOut) fuse.Status

ReadDir provides a list of all the entries in the directory

func (*Filesystem) Read added in v0.12.0

func (f *Filesystem) Read(cancel <-chan struct{}, in *fuse.ReadIn, buf []byte) (fuse.ReadResult, fuse.Status)

Read an inode's data like a file.

func (*Filesystem) ReadDir added in v0.12.0

func (f *Filesystem) ReadDir(cancel <-chan struct{}, in *fuse.ReadIn, out *fuse.DirEntryList) fuse.Status

ReadDir reads a directory entry. Usually doesn't get called (ReadDirPlus is typically used).

func (*Filesystem) ReadDirPlus added in v0.12.0

func (f *Filesystem) ReadDirPlus(cancel <-chan struct{}, in *fuse.ReadIn, out *fuse.DirEntryList) fuse.Status

ReadDirPlus reads an individual directory entry AND does a lookup.

func (*Filesystem) ReleaseDir added in v0.12.0

func (f *Filesystem) ReleaseDir(in *fuse.ReleaseIn)

ReleaseDir closes a directory and purges it from memory

func (*Filesystem) Rename added in v0.12.0

func (f *Filesystem) Rename(cancel <-chan struct{}, in *fuse.RenameIn, name string, newName string) fuse.Status

Rename renames and/or moves an inode.

func (*Filesystem) Rmdir added in v0.12.0

func (f *Filesystem) Rmdir(cancel <-chan struct{}, in *fuse.InHeader, name string) fuse.Status

Rmdir removes a directory if it's empty.

func (*Filesystem) SerializeAll added in v0.12.0

func (f *Filesystem) SerializeAll()

SerializeAll dumps all inode metadata currently in the cache to disk. This metadata is only used later if an item could not be found in memory AND the cache is offline. Old metadata is not removed, only overwritten (to avoid an offline session from wiping all metadata on a subsequent serialization).

func (*Filesystem) SetAttr added in v0.12.0

func (f *Filesystem) SetAttr(cancel <-chan struct{}, in *fuse.SetAttrIn, out *fuse.AttrOut) fuse.Status

Setattr is the workhorse for setting filesystem attributes. Does the work of operations like utimens, chmod, chown (not implemented, FUSE is single-user), and truncate.

func (*Filesystem) StatFs added in v0.12.0

func (f *Filesystem) StatFs(cancel <-chan struct{}, in *fuse.InHeader, out *fuse.StatfsOut) fuse.Status

Statfs returns information about the filesystem. Mainly useful for checking quotas and storage limits.

func (*Filesystem) TranslateID added in v0.12.0

func (f *Filesystem) TranslateID(nodeID uint64) string

TranslateID returns the DriveItemID for a given NodeID

func (f *Filesystem) Unlink(cancel <-chan struct{}, in *fuse.InHeader, name string) fuse.Status

Unlink deletes a child file.

func (*Filesystem) Write added in v0.12.0

func (f *Filesystem) Write(cancel <-chan struct{}, in *fuse.WriteIn, data []byte) (uint32, fuse.Status)

Write to an Inode like a file. Note that changes are 100% local until Flush() is called. Returns the number of bytes written and the status of the op.

type Inode

type Inode struct {
	sync.RWMutex
	graph.DriveItem
	// contains filtered or unexported fields
}

Inode represents a file or folder fetched from the Graph API. All struct fields are pointers so as to avoid including them when marshaling to JSON if not present. The embedded DriveItem's fields should never be accessed, they are there for JSON umarshaling/marshaling only. (They are not safe to access concurrently.) This struct's methods are thread-safe and can be called concurrently. Reads/writes are done directly to DriveItems instead of implementing something like the fs.FileHandle to minimize the complexity of operations like Flush.

func NewInode

func NewInode(name string, mode uint32, parent *Inode) *Inode

NewInode initializes a new Inode

func NewInodeDriveItem

func NewInodeDriveItem(item *graph.DriveItem) *Inode

NewInodeDriveItem creates a new Inode from a DriveItem

func NewInodeJSON

func NewInodeJSON(data []byte) (*Inode, error)

NewInodeJSON converts JSON to a *DriveItem when loading from local storage. Not used with the API. FIXME: If implemented as UnmarshalJSON, this will break delta syncs for business accounts. Don't ask me why.

func (*Inode) AsJSON

func (i *Inode) AsJSON() []byte

AsJSON converts a DriveItem to JSON for use with local storage. Not used with the API. FIXME: If implemented as MarshalJSON, this will break delta syncs for business accounts. Don't ask me why.

func (*Inode) HasChanges

func (i *Inode) HasChanges() bool

HasChanges returns true if the file has local changes that haven't been uploaded yet.

func (*Inode) HasChildren added in v0.9.0

func (i *Inode) HasChildren() bool

HasChildren returns true if the item has more than 0 children

func (*Inode) ID

func (i *Inode) ID() string

ID returns the internal ID of the item

func (*Inode) IsDir

func (i *Inode) IsDir() bool

IsDir returns if it is a directory (true) or file (false).

func (*Inode) ModTime

func (i *Inode) ModTime() uint64

ModTime returns the Unix timestamp of last modification (to get a time.Time struct, use time.Unix(int64(d.ModTime()), 0))

func (*Inode) Mode

func (i *Inode) Mode() uint32

Mode returns the permissions/mode of the file.

func (i *Inode) NLink() uint32

NLink gives the number of hard links to an inode (or child count if a directory)

func (*Inode) Name

func (i *Inode) Name() string

Name is used to ensure thread-safe access to the NameInternal field.

func (*Inode) NodeID added in v0.12.0

func (i *Inode) NodeID() uint64

NodeID returns the inodes ID in the filesystem

func (*Inode) ParentID

func (i *Inode) ParentID() string

ParentID returns the ID of this item's parent.

func (*Inode) Path

func (i *Inode) Path() string

Path returns an inode's full Path

func (*Inode) SetName

func (i *Inode) SetName(name string)

SetName sets the name of the item in a thread-safe manner.

func (*Inode) SetNodeID added in v0.12.0

func (i *Inode) SetNodeID(id uint64) uint64

SetNodeID sets the inode ID for an inode if not already set. Does nothing if the Inode already has an ID.

func (*Inode) Size

func (i *Inode) Size() uint64

Size pretends that folders are 4096 bytes, even though they're 0 (since they actually don't exist).

func (*Inode) String

func (i *Inode) String() string

String is only used for debugging by go-fuse

type LoopbackCache added in v0.14.0

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

LoopbackCache stores the content for files under a folder as regular files

func NewLoopbackCache added in v0.14.0

func NewLoopbackCache(directory string) *LoopbackCache

func (*LoopbackCache) Close added in v0.14.0

func (l *LoopbackCache) Close(id string)

Close closes the currently open fd

func (*LoopbackCache) Delete added in v0.14.0

func (l *LoopbackCache) Delete(id string) error

Delete closes the fd AND deletes content from disk.

func (*LoopbackCache) Get added in v0.14.0

func (l *LoopbackCache) Get(id string) []byte

Get reads a file's content from disk.

func (*LoopbackCache) HasContent added in v0.14.0

func (l *LoopbackCache) HasContent(id string) bool

HasContent is used to find if we have a file or not in cache (in any state)

func (*LoopbackCache) Insert added in v0.14.0

func (l *LoopbackCache) Insert(id string, content []byte) error

InsertContent writes file content to disk in a single bulk insert.

func (*LoopbackCache) InsertStream added in v0.14.0

func (l *LoopbackCache) InsertStream(id string, reader io.Reader) (int64, error)

InsertStream inserts a stream of data

func (*LoopbackCache) IsOpen added in v0.14.0

func (l *LoopbackCache) IsOpen(id string) bool

IsOpen returns true if the file is already opened somewhere

func (*LoopbackCache) Move added in v0.14.0

func (l *LoopbackCache) Move(oldID string, newID string) error

Move moves content from one ID to another

func (*LoopbackCache) Open added in v0.14.0

func (l *LoopbackCache) Open(id string) (*os.File, error)

Open returns a filehandle for subsequent access

type SerializeableInode

type SerializeableInode struct {
	graph.DriveItem
	Children []string
	Subdir   uint32
	Mode     uint32
}

SerializeableInode is like a Inode, but can be serialized for local storage to disk

type UploadManager

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

UploadManager is used to manage and retry uploads.

func NewUploadManager

func NewUploadManager(duration time.Duration, db *bolt.DB, fs *Filesystem, auth *graph.Auth) *UploadManager

NewUploadManager creates a new queue/thread for uploads

func (*UploadManager) CancelUpload added in v0.9.0

func (u *UploadManager) CancelUpload(id string)

CancelUpload is used to kill any pending uploads for a session

func (*UploadManager) QueueUpload

func (u *UploadManager) QueueUpload(inode *Inode) error

QueueUpload queues an item for upload.

type UploadSession

type UploadSession struct {
	ID                 string    `json:"id"`
	OldID              string    `json:"oldID"`
	ParentID           string    `json:"parentID"`
	NodeID             uint64    `json:"nodeID"`
	Name               string    `json:"name"`
	ExpirationDateTime time.Time `json:"expirationDateTime"`
	Size               uint64    `json:"size,omitempty"`
	Data               []byte    `json:"data,omitempty"`
	QuickXORHash       string    `json:"quickxorhash,omitempty"`
	ModTime            time.Time `json:"modTime,omitempty"`

	sync.Mutex
	UploadURL string `json:"uploadUrl"`
	ETag      string `json:"eTag,omitempty"`
	// contains filtered or unexported fields
}

UploadSession contains a snapshot of the file we're uploading. We have to take the snapshot or the file may have changed on disk during upload (which would break the upload). It is not recommended to directly deserialize into this structure from API responses in case Microsoft ever adds a size, data, or modTime field to the response.

func NewUploadSession

func NewUploadSession(inode *Inode, data *[]byte) (*UploadSession, error)

NewUploadSession wraps an upload of a file into an UploadSession struct responsible for performing uploads for a file.

func (*UploadSession) MarshalJSON added in v0.9.0

func (u *UploadSession) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON marshaler to avoid race conditions

func (*UploadSession) Upload

func (u *UploadSession) Upload(auth *graph.Auth) error

Upload copies the file's contents to the server. Should only be called as a goroutine, or it can potentially block for a very long time. The uploadSession.error field contains errors to be handled if called as a goroutine.

type UploadSessionPost

type UploadSessionPost struct {
	Name             string `json:"name,omitempty"`
	ConflictBehavior string `json:"@microsoft.graph.conflictBehavior,omitempty"`
	FileSystemInfo   `json:"fileSystemInfo,omitempty"`
}

UploadSessionPost is the initial post used to create an upload session

Directories

Path Synopsis
Package graph provides the basic APIs to interact with Microsoft Graph.
Package graph provides the basic APIs to interact with Microsoft Graph.
quickxorhash
Package quickxorhash provides the quickXorHash algorithm which is a quick, simple non-cryptographic hash algorithm that works by XORing the bytes in a circular-shifting fashion.
Package quickxorhash provides the quickXorHash algorithm which is a quick, simple non-cryptographic hash algorithm that works by XORing the bytes in a circular-shifting fashion.

Jump to

Keyboard shortcuts

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