types

package
v0.0.0-...-aafedb1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Custom errors

This package provides types for the other packages here. Functions here have no complicated logic so tests aren't needed.

Index

Constants

View Source
const (
	//Is this request allowed to fail? If a request fails, the worker desestimates the complete slice, but some requests may fail.
	O_REQ_MAY_FAIL = 1 << 0
	//Process a request anyway after some req before did fail
	O_REQ_DO_ANYWAY = 1 << 1
)
View Source
const (
	//In seconds
	HOUSEKEEPING_INTERVAL = 120
)
View Source
const SCOPES = "https://www.googleapis.com/auth/drive"

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgumentsError

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

func NewArgumentsError

func NewArgumentsError(format string, arguments ...interface{}) ArgumentsError

func (ArgumentsError) Error

func (ae ArgumentsError) Error() string

type Config

type Config struct {
	Base             *string
	Files            ConfigFiles
	Local            LocalConfig
	Drive            DriveConfig
	Events           EventsConfig
	Socket           SocketConfig
	AuthOnly, DryRun *bool
	ID               *string
	Scopes           string
}

Config structures

func NewConfig

func NewConfig(init ...*Config) Config

type ConfigFiles

type ConfigFiles struct {
	UserConfig, Credentials, Token, Lockfile, Ignore, LocalDir *string
}

type DriveConfig

type DriveConfig struct {
	Workers                                          uint
	AllowSharedFiles, DeleteForever, AllowDriveFiles bool
	RemoveOrphans                                    *bool
	UpdateAtime                                      bool
}

type EntryExistsError

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

func NewEntryExistsError

func NewEntryExistsError(entry string) EntryExistsError

func (EntryExistsError) Error

func (er EntryExistsError) Error() string

type EntryNotFoundError

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

func NewEntryNotFoundError

func NewEntryNotFoundError(entry string) EntryNotFoundError

func (EntryNotFoundError) Error

func (er EntryNotFoundError) Error() string

type Event

type Event struct {
	//Type holds the type of the event as reported by fsnotify.Event.String() and splitted. All uppercase.
	//Type fsnotify bundles multiple events for the same file separated by pipes. We split them on different events.
	Type string
	//Name holds the filename where the event comes from
	//Path holds the path relative to the watch dir
	//FullPath holds the full path on the filesystem to the specified object. Not present on remote events
	//FileID holds the FileID reported by te file's xattrs. It can be an empty string for new files or on filesystems w/o xattrs(5)
	Name, Path, FullPath, FileID string
	//OldPath holds the old file path on move requests
	OldPath string
	//File holds the current value for the drive file. On REMOVE events it holds a cached value
	File *drv.File
	//Origin holds a tiny int value for where the event was originated. 0-> Local, 1-> Remote
	Origin byte
	//Propagate holds a boolean depending if the event should be listened out of the localfs package. Usually it's always true
	Propagate bool
	//Time holds the time where the event was fired
	Time time.Time
	//The fields here are only filled when the type is an error
	//Error holds an error ocurred on Location
	Error error
	//Message holds the error string
	Message string
	//Location contains the package where the error was originated
	Location string
}

Events fired from Localfs or Drive

Event types: - CREATE -> Triggered when a file is added to the hierarchy. This triggers one side sending it to the other one and adding it to the conversion tree when it happens on Drive. - REMOVE -> Triggered when a file or directory is removed. This triggers the remotion of it's counterpart on the other side an on conversion tree when it happens on Drive. - WRITE -> Triggered when a file is updated. This triggers a update on the other side. - RENAME -> When a file is renamed, it's stored waiting for confirmation from a CREATE event and done after the second RENAME event on the old file - CHMOD -> When the attributes of a file changes, this event is fired. May be a date or permissions change.

type EventWaitPool

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

A simple map holding events which are waiting to be released It holds events until a timer has fired. Then they're released to the sender channel

func NewEventWaitPool

func NewEventWaitPool(sender chan<- *Event, timeout int) *EventWaitPool

func (*EventWaitPool) Add

func (wp *EventWaitPool) Add(path string, event *Event)

Add a file to the pool. Does nothing if the file already exists After the timeout is fired, the event is sent

type EventsConfig

type EventsConfig struct {
	Workers    uint
	MaxRetries uint
}

type File

type File struct {
	*drv.File
	//Local file path
	Path string
}

The File type wraps a Drive File with its path. About nameless fields, take a look at https://golang.org/ref/spec#Struct_types

func NewFile

func NewFile(drvFile *drv.File, path string) *File

type FileActionsMap

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

A simple map to handle concurrent actions over the same file It's thread safe

func NewFileActionsMap

func NewFileActionsMap(ctx context.Context) *FileActionsMap

Create a new FileActionsMap with the specified context as root for events w/o their own context

func (*FileActionsMap) Register

func (fam *FileActionsMap) Register(fileId, evtType string, ctx context.Context, cancelFunc context.CancelFunc) error

Register an event and wait if needed. This function may return an error if the context or cancelFunc were nil or the context error. There isn't any return value. There are 4 possible ways - The event is registered and the function returns - The function blocks until a event is done - Other context is cancelled and the function continues - A combination of the previous 2

type FileExistsError

type FileExistsError struct {
	Msg, Path, ID string
}

File already exists on conversion tree

func NewFileExistsError

func NewFileExistsError(fileNameOrPath, fileId string) FileExistsError

func (FileExistsError) Error

func (pe FileExistsError) Error() string

type FileNotExistError

type FileNotExistError struct {
	Msg, Path, ID string
}

File doesn't exist on conversion tree

func NewFileNotExistError

func NewFileNotExistError(fileNameOrPath, fileId string) FileNotExistError

func (FileNotExistError) Error

func (pe FileNotExistError) Error() string

type IsFileError

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

func NewIsFileError

func NewIsFileError(path string) IsFileError

func (IsFileError) Error

func (sf IsFileError) Error() string

type LocalConfig

type LocalConfig struct {
	Modes struct {
		File, Dir os.FileMode
	}
}

type MutexedBlacklist

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

A simple mutexed map to check if a key exists

func NewMutexedBlacklist

func NewMutexedBlacklist() *MutexedBlacklist

func (*MutexedBlacklist) Add

func (mb *MutexedBlacklist) Add(key string) (err error)

Add a *sync.Cond to map under key. If it already exists, error won't be nil and value will have the current value

func (*MutexedBlacklist) Get

func (mb *MutexedBlacklist) Get(key string) (exists bool)

Get value contained in blacklist. If exists is false, the condition is nil

func (*MutexedBlacklist) Remove

func (mb *MutexedBlacklist) Remove(key string) error

Remove will unlock

type MutexedLinkedList

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

A safe linked list for concurrent access. The initial value is a list ready to use.

func (*MutexedLinkedList) Init

func (mll *MutexedLinkedList) Init()

A wrapper for List.Init()

func (*MutexedLinkedList) Iterate

func (mll *MutexedLinkedList) Iterate(callback func(interface{}))

func (*MutexedLinkedList) Len

func (mll *MutexedLinkedList) Len() int

func (*MutexedLinkedList) Put

func (mll *MutexedLinkedList) Put(element interface{})

type PathError

type PathError struct {
	Msg, Path, ID string
}

Error generating or locating a path

func NewPathError

func NewPathError(format, fileNameOrPath, fileId string) PathError

func (PathError) Error

func (pe PathError) Error() string

type Request

type Request struct {
	//Type holds the type of request
	Type string
	//Arguments holds a slice of string parameters for the function
	Arguments []string
	//Path holds the path to the file affected
	Path string
	//File holds a pointer to os.File or nil. This can be used to start a reader or a writer
	File *os.File
	//Destination of the Request. 0 -> Local IO. 1 -> Drive IO. 2 -> Worker thread (blacklist helpers)
	//Destination is only needed when delegating Requests on a workerThread which has to route them
	Destination byte
	//Options admit any option from the O_REQ_*
	Options byte
	//Context allows us to track the Request progress and cancel it if needed
	Context context.Context
	//Cancel function is called when the event is fullfilled
	Cancel context.CancelFunc
	//Status is a channel who returns an error or nil. Functions send status via this channel when they're ready. After it's been read, the channel is closed
	Status chan error
	//ReturnValue is populated with a return value. It's populated before Status and should be read after waiting for status. You know the type
	ReturnValue interface{}
}

Localfs requests

func NewRequest

func NewRequest(typeOfRequest, path string, arguments ...string) *Request

Initialize a IO Request with type, path and additional arguments

func NewRequestWithContext

func NewRequestWithContext(baseContext context.Context, typeOfRequest, path string, arguments ...string) *Request

Initialize a IO Request with context, path and additional arguments

type ResolveMap

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

This map has conditions to be resolved after a file has been created It's safe to be used by multiple goroutines. Use NewResolveMap to initialize

func NewResolveMap

func NewResolveMap(ctx context.Context) *ResolveMap

Generate a ResolveMap

func (*ResolveMap) Add

func (cm *ResolveMap) Add(key string, ctx context.Context) (err error)

Add a context to the map. Will be removed when done by the housekeeping thread

func (*ResolveMap) Check

func (cm *ResolveMap) Check(key string) (mapContext context.Context, exists bool)

Check if a key exists on the ResolveMap and return the inside context if present The context may exist and be finalized.

It's safe to check the exists bool as it will be false also if the context exists and it's already cancelled.

func (*ResolveMap) Wait

func (cm *ResolveMap) Wait(ctx context.Context, key string) (exists bool, err error)

Wait for a map key. Use the context to be able to interrupt the operation The error this function returns doesn't mean it has failed, it's the error reported by context which is populated after it was cancelled.

type ShadowFileError

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

func NewShadowFileError

func NewShadowFileError(id string) ShadowFileError

func (ShadowFileError) Error

func (sf ShadowFileError) Error() string

type SocketConfig

type SocketConfig struct {
	Path string
}

type TooManyErrors

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

func NewTooManyErrors

func NewTooManyErrors(errors, max int) TooManyErrors

func (TooManyErrors) Error

func (er TooManyErrors) Error() string

type UnimplementedType

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

func NewUnimplementedType

func NewUnimplementedType(typ string) UnimplementedType

func (UnimplementedType) Error

func (ut UnimplementedType) Error() string

Jump to

Keyboard shortcuts

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