database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package database interacts with Dupers bbolt database and buckets.

Package database interacts with Dupers bbolt database and buckets.

Index

Constants

View Source
const (
	PrivateFile fs.FileMode = 0600
	PrivateDir  fs.FileMode = 0700

	NotFound = "This is okay as one will be created when using the dupe or search commands."
)

Variables

View Source
var (
	ErrBucketNotFound = bolt.ErrBucketNotFound
	ErrBucketAsFile   = errors.New("bucket points to a file, not a directory")
	ErrDBClean        = errors.New("database has nothing to clean")
	ErrDBCompact      = errors.New("database compression has not reduced the size")
	ErrDBEmpty        = errors.New("database is empty and contains no items")
	ErrDBNotFound     = errors.New("database file does not exist")
	ErrDBZeroByte     = errors.New("database is a zero byte file")
	ErrImportFile     = errors.New("not a valid duper export file")
)
View Source
var (
	ErrBucketExists = errors.New("bucket already exists in the database")
	ErrBucketNotDir = errors.New("bucket path is not a directory")
	ErrBucketPath   = errors.New("directory used by the bucket does not exist on your system")
	ErrChecksumLen  = errors.New("hexadecimal value is invalid")
	ErrFileNoDesc   = errors.New("no file descriptor")
	ErrImportList   = errors.New("import list is empty")
	ErrImportSyntax = errors.New("import item has incorrect syntax")
	ErrImportPath   = errors.New("import item has an invalid file path")
)

Functions

func Abs

func Abs(bucket string) ([]byte, error)

Abs returns an absolute representation of the named bucket.

func AllBuckets

func AllBuckets(db *bolt.DB) (names []string, err error)

AllBuckets lists all the stored bucket names in the database.

func Backup

func Backup() (name string, written int64, err error)

Backup makes a copy of the database to the named location.

func Clean

func Clean(quiet, debug bool, buckets ...string) error

Clean the stale items from database buckets. Stale items are file pointers that no longer exist on the host file system.

func Compact

func Compact(debug bool) error

Compact the database by reclaiming space.

func CopyFile

func CopyFile(name, dest string) (int64, error)

CopyFile duplicates the named file to the destination filepath.

func Count added in v0.0.8

func Count(name string, db *bolt.DB) (items int, err error)

Count the number of records in the bucket.

func DB

func DB() (string, error)

DB returns the absolute path of the Bolt database.

func Exist added in v0.1.0

func Exist(bucket string, db *bolt.DB) error

Exist returns an nil value if the bucket exists in the database.

func ExportCSV added in v0.1.0

func ExportCSV(bucket string, db *bolt.DB) (name string, err error)

ExportCSV saves the bucket data to an export csv file. The generated file is RFC 4180 compatible using comma-separated values.

func Home added in v0.1.0

func Home() (string, error)

Home returns the user's home directory. Or if that fails, returns the current working directory.

func Import added in v0.1.0

func Import(name Bucket, ls *Lists, db *bolt.DB) (imported int, err error)

Import the list of data and save it to the database. If the named bucket does not exist, it is created.

func ImportCSV added in v0.1.0

func ImportCSV(name string, db *bolt.DB) (records int, err error)

ImportCSV reads the named export csv file and imports its content to the database.

func Info

func Info() (string, error)

Info returns a printout of the buckets and their statistics.

func IsEmpty

func IsEmpty() (bool, error)

XXX IsEmpty returns true if the database has no buckets.

func OpenRead added in v0.0.9

func OpenRead() (db *bolt.DB, err error)

OpenRead opens the Bolt database for reading.

func OpenWrite added in v0.0.9

func OpenWrite() (db *bolt.DB, err error)

OpenRead opens the Bolt database for writing and reading.

func RM

func RM(name string) error

RM removes the named bucket from the database.

func Rename added in v0.1.0

func Rename(name, newName string) error

Rename the named bucket in the database to use a new directory path.

Types

type Bucket

type Bucket string

Bucket is the absolute path to a directory that's used as the bucket name.

type Filepath

type Filepath string

Filepath is the absolute path to a file used as a map key.

type Lists

type Lists map[Filepath][32]byte

Lists are a collection of fetched filepaths and their SHA256 checksums.

func List

func List(bucket string, db *bolt.DB) (ls Lists, err error)

List returns the file paths and SHA256 checksums stored in the bucket.

type Matches

type Matches map[Filepath]Bucket

Matches are a collection of fetched filepaths and the bucket they were sourced from.

func Compare

func Compare(s string, buckets ...string) (*Matches, error)

Compare finds exact matches of the string contained within the stored filenames and paths.

func CompareBase

func CompareBase(s string, buckets ...string) (*Matches, error)

CompareBase finds exact matches of the string contained within the stored filenames.

func CompareBaseNoCase

func CompareBaseNoCase(s string, buckets ...string) (*Matches, error)

CompareBaseNoCase finds case insensitive matches of the string contained within the stored filenames.

func CompareNoCase

func CompareNoCase(s string, buckets ...string) (*Matches, error)

CompareNoCase finds case insensitive matches of the string contained within the stored filenames and paths.

Jump to

Keyboard shortcuts

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