database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 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
	PrivateDir  fs.FileMode = 0o700

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

Variables

View Source
var (
	ErrBucketNotFound = bolt.ErrBucketNotFound
	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")

	TestMode = false // nolint: gochecknoglobals
)
View Source
var ErrImportList = errors.New("import list is empty")

Functions

func Abs

func Abs(name string) (string, error)

Abs returns an absolute representation of the named bucket.

func AbsB added in v0.9.0

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

AbsB returns an absolute representation of the named bucket.

func All added in v1.0.1

func All(db *bolt.DB) (names []string, err 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 added in v1.0.1

func CSVExport(bucket string, db *bolt.DB) (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 added in v1.0.1

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

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

func Check added in v1.0.1

func Check() error

Check the size and existence of the database file.

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 internal 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 Create added in v1.0.1

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 added in v0.1.0

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

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

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 Info

func Info() (string, error)

Info returns a printout of the buckets and their statistics.

func IsEmpty

func IsEmpty() (bool, error)

IsEmpty returns true when 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.

func Usage added in v1.0.1

func Usage(name string, db *bolt.DB) (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(bucket string, db *bolt.DB) (ls Lists, err error)

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

func Scanner added in v1.0.1

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(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.

Directories

Path Synopsis
internal
bucket
© Ben Garrett https://github.com/bengarrett/dupers
© Ben Garrett https://github.com/bengarrett/dupers
csv
© 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