database

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package database interacts with Dupers bbolt database and buckets.

© Ben Garrett https://github.com/bengarrett/dupers

Index

Constants

View Source
const (
	PrivateFile fs.FileMode = 0o600 // PrivateFile mode means only the owner has read/write access.
	PrivateDir  fs.FileMode = 0o700 // PrivateDir mode means only the owner has read/write/dir access.

	NotFound = "This is okay as one will be created when using the dupe or search commands."
)
View Source
const (
	Timeout = 3 * time.Second // Timeout lock option for the Bolt database.

)

Variables

View Source
var (
	ErrEmpty     = errors.New("database is empty and contains no items")
	ErrNoCompact = errors.New("compression has not reduced the database size")
	ErrNoClean   = errors.New("database has nothing to clean")
	ErrNoTerm    = errors.New("cannot compare an empty term")
	ErrNotFound  = errors.New("database file does not exist")
	ErrSameName  = errors.New("bucket target is the same as the bucket name")
	ErrZeroByte  = errors.New("database is a zero byte file and is unusable")
)
View Source
var (
	ErrImportList = errors.New("import list cannot be empty")
	ErrNoBucket   = errors.New("the named bucket cannot be empty")
	ErrNoDest     = errors.New("the destination path cannot be empty")
	ErrNoFilename = errors.New("the named file cannot be empty")
)

Functions

func Abs

func Abs(name string) (string, error)

Abs returns an absolute representation of the named bucket.

func AbsB

func AbsB(name string) ([]byte, error)

AbsB returns an absolute representation of the named bucket.

func All

func All(db *bolt.DB) ([]string, error)

All returns every stored bucket within the database.

func Backup

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

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

func CSVExport

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

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

func CSVImport

func CSVImport(db *bolt.DB, name string, assumeYes bool) (int, error)

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

func Check

func Check() (int64, error)

Check returns size and existence of the database file.

func Clean

func Clean(db *bolt.DB, 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(db *bolt.DB, debug bool) error

Compact the database by reclaiming internal space.

func CopyFile

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

CopyFile duplicates the named file to the destination filepath.

func Count

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

Count the number of records in the named bucket.

func Create

func Create(path string) error

Create a new database at the given path.

func DB

func DB() (string, error)

DB returns the absolute path of the database.

func Exist

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

Exist returns an error if the bucket does not exists in the database.

func Home

func Home() (string, error)

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

func Import

func Import(db *bolt.DB, name Bucket, ls *Lists) (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 Info

func Info(db *bolt.DB) (string, error)

Info returns a printout of the buckets and their statistics.

func IsEmpty

func IsEmpty(db *bolt.DB) error

IsEmpty returns a bolt.ErrBucketNotFound error when the database has no buckets.

func OpenRead

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

OpenRead opens the Bolt database for reading.

func OpenWrite

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

OpenRead opens the Bolt database for writing and reading.

func Remove

func Remove(db *bolt.DB, name string) error

Remove the named bucket from the database.

func Rename

func Rename(db *bolt.DB, name, target string) error

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

func Usage

func Usage(db *bolt.DB, name string, assumeYes bool) (string, error)

Usage checks the validity and usage of the named bucket in the database.

Types

type Bucket

type Bucket string

Bucket is the absolute path to the directory that is 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(db *bolt.DB, bucket string) (Lists, error)

List returns the filepaths and SHA256 checksums stored in the bucket.

func Scanner

func Scanner(file *os.File) (string, *Lists, error)

Scanner reads the content of an export csv file. It returns the stored bucket and csv data as a List ready for import.

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(db *bolt.DB, s string, buckets ...string) (*Matches, error)

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

func CompareBase

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

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

func CompareBaseNoCase

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

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

func CompareNoCase

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

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

Directories

Path Synopsis
© Ben Garrett https://github.com/bengarrett/dupers
© Ben Garrett https://github.com/bengarrett/dupers
© Ben Garrett https://github.com/bengarrett/dupers
© Ben Garrett https://github.com/bengarrett/dupers

Jump to

Keyboard shortcuts

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