utils

package
v0.0.0-...-56fb507 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizeApp

func AuthorizeApp(tokenLocation string)

AuthorizeApp triggers the OAuth 2.0 web authentication for Piledriver

func CreateFile

func CreateFile(service *drive.Service, local string, parentID string) (string, error)

CreateFile creates the file in drive, with the parent directory specified by parentID and filename same as input file. It does NOT check for the validity of parentID. If queue is nil, the Do() will be executed in this method itself

func CreateFolder

func CreateFolder(service *drive.Service, remote string, parentID ...string) (string, error)

CreateFolder creates a folder in drive, with a parent directory specified by parentID If no parent directories are specified, then it is not set

func DebounceEvents

func DebounceEvents(input, output chan Event)

DebounceEvents removes identical events less than some threshold.

func DeleteFileOrFolder

func DeleteFileOrFolder(service *drive.Service, id string) error

DeleteFileOrFolder deletes the file (or folder) in the drive with the givwn ID

func ExecuteEvents

func ExecuteEvents(state *State)

ExecuteEvents takes a channel Events and executes them

func GetDriveService

func GetDriveService(tokenLocation string) *drive.Service

GetDriveService reads the token from the file denoted by tokenLocation and then returns the Google Drive service. If it cannot find the token file, it errors out and stops the program.

func QueryAllContents

func QueryAllContents(service *drive.Service) ([]*drive.File, error)

QueryAllContents returns a list of all the files uploaded to Drive by Piledriver that were not trashed by the user

func QueryFileID

func QueryFileID(service *drive.Service, local string) (string, error)

QueryFileID queries Google drive for the id of a file (or folder) with the givwn path If the file is found, then err is nil

func RenameFileOrFolder

func RenameFileOrFolder(service *drive.Service, info RenameInfo) (*drive.File, error)

RenameFileOrFolder models the UNIX mv (1) command for Google Drive

func UpdateFile

func UpdateFile(service *drive.Service, local, fileID string) (*drive.File, error)

UpdateFile updates the file to the new contents

func WatchLoop

func WatchLoop(state *State)

WatchLoop watches for file change events in a loop recursive causes it to add new directories being created

Types

type Event

type Event struct {
	OldPath   string
	Path      string
	Category  EventCategory
	IDMap     map[IDKey]string
	Timestamp time.Time
}

Event is the internal representation of file watcher events

func (Event) String

func (ev Event) String() string

type EventCategory

type EventCategory uint

EventCategory denotes the type of event that has been detected

const (
	FileCreated EventCategory = iota
	DirectoryCreated
	FileDeleted
	DirectoryDeleted
	FileRenamed
	DirectoryRenamed
	FileWritten
	MaxEventCategory
)

Various types of event categories

type IDKey

type IDKey int

IDKey denotes the key for the ID type

const (
	CurrID IDKey = iota
	ParentID
)

Various types of id's

type PathID

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

PathID contains the path and the id returned for it

type RenameInfo

type RenameInfo struct {
	ID          string
	OldParentID string
	NewParentID string
	NewName     string
}

RenameInfo contains fields necessary for renaming a file/folder

type State

type State struct {
	Config          config.Config
	LogFilePath     string
	FileEvents      chan Event
	DebouncedEvents chan Event
	// contains filtered or unexported fields
}

State holds global state info for the program

func NewState

func NewState() *State

NewState returns a new blank state

func (*State) AddDir

func (state *State) AddDir(dir string) error

AddDir adds a directory to the watcher and scans paths

func (*State) InitService

func (state *State) InitService(tokenPath string)

InitService initializes the service field

func (*State) InitWatcher

func (state *State) InitWatcher()

InitWatcher initializes the watcher field

func (*State) Service

func (state *State) Service() *drive.Service

Service returns the service field

func (*State) Tree

func (state *State) Tree(name string) (*afs.Tree, bool)

Tree returns the tree with the given name If a tree with this name is found, then the boolean is true else false

Jump to

Keyboard shortcuts

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