boltfs

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

README

boltfs

1. 运行完整测试套件

go test ./... -timeout 30s

2. 生成最终覆盖率报告

go test ./... -coverprofile=final_coverage.out

go tool cover -html=final_coverage.out -o final_coverage.html

3. 检查是否有竞态条件

go test ./... -race -timeout 30s

4. 运行基准测试

go test ./... -bench=. -benchtime=3s -timeout 90s

goos: darwin
goarch: arm64
pkg: github.com/lazygo/boltfs
cpu: Apple M4 Pro
BenchmarkFileOperations/Write-1KB-14                 152          22761997 ns/op
BenchmarkFileOperations/Read-1KB-14              4349034               826.5 ns/op
BenchmarkFileOperations/Write-10KB-14                157          23145365 ns/op           0.44 MB/s
BenchmarkFileOperations/Stat-14                 18354676               183.3 ns/op
BenchmarkDirectoryOperations/MkdirAll-5-levels-14                     75          47860731 ns/op
BenchmarkDirectoryOperations/Readdir-100-files-14                3951260               951.2 ns/op
BenchmarkConcurrentOperations/Concurrent-Create-100-14               145          24198567 ns/op
BenchmarkConcurrentOperations/Concurrent-Read-Same-File-14               2196055              1620 ns/op
PASS
ok      github.com/lazygo/boltfs        54.600s

5. 查看最终覆盖率

go tool cover -func=final_coverage.out | tail -5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsDirectory  = errors.New("is a directory")
	ErrNotDirectory = errors.New("not a directory")
)

错误定义

View Source
var (
	ErrInvalidSeek = errors.New("invalid seek")
)

Functions

This section is empty.

Types

type BoltFS

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

BoltFS 基于BoltDB的文件系统,实现afero.Fs接口

func NewBoltFS

func NewBoltFS(dbPath string, readOnly bool) (*BoltFS, error)

NewBoltFS 创建新的BoltDB文件系统

func (*BoltFS) Chmod

func (fs *BoltFS) Chmod(name string, mode os.FileMode) error

Chmod 修改文件权限

func (*BoltFS) Chown

func (fs *BoltFS) Chown(name string, uid, gid int) error

Chown 修改文件所有者(在Windows上不支持,在Unix-like系统上模拟)

func (*BoltFS) Chtimes

func (fs *BoltFS) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes 修改文件时间

func (*BoltFS) Close

func (fs *BoltFS) Close() error

Close 关闭文件系统

func (*BoltFS) Compact

func (fs *BoltFS) Compact() error

Compact 压缩数据库

func (*BoltFS) Create

func (fs *BoltFS) Create(name string) (afero.File, error)

Create 创建文件

func (*BoltFS) GetThumbnail

func (fs *BoltFS) GetThumbnail(path string) ([]byte, error)

GetThumbnail 获取缩略图

func (*BoltFS) Lchown

func (fs *BoltFS) Lchown(name string, uid, gid int) error

Lchown 修改符号链接所有者(不支持)

func (*BoltFS) Mkdir

func (fs *BoltFS) Mkdir(name string, perm os.FileMode) error

Mkdir 创建目录

func (*BoltFS) MkdirAll

func (fs *BoltFS) MkdirAll(path string, perm os.FileMode) error

MkdirAll 递归创建目录

func (*BoltFS) Name

func (fs *BoltFS) Name() string

Name 返回文件系统名称

func (*BoltFS) Open

func (fs *BoltFS) Open(name string) (afero.File, error)

Open 打开文件(只读)

func (*BoltFS) OpenFile

func (fs *BoltFS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)

OpenFile 打开文件

func (*BoltFS) ReadlinkIfPossible

func (fs *BoltFS) ReadlinkIfPossible(name string) (string, error)

ReadlinkIfPossible 读取符号链接(不支持)

func (*BoltFS) Remove

func (fs *BoltFS) Remove(name string) error

Remove 删除文件或空目录

func (*BoltFS) RemoveAll

func (fs *BoltFS) RemoveAll(path string) error

RemoveAll 递归删除

func (*BoltFS) Rename

func (fs *BoltFS) Rename(oldname, newname string) error

Rename 重命名文件或目录

func (*BoltFS) SaveMetadata

func (fs *BoltFS) SaveMetadata(meta *FileMetadata) error

SaveMetadata 方法,用于外部调用

func (*BoltFS) Stat

func (fs *BoltFS) Stat(name string) (os.FileInfo, error)

Stat 获取文件信息

func (*BoltFS) Stats

func (fs *BoltFS) Stats() (map[string]any, error)

Stats 获取文件系统统计信息

func (*BoltFS) StoreThumbnail

func (fs *BoltFS) StoreThumbnail(originalPath string, thumbnailData []byte, contentType string) error

StoreThumbnail 存储缩略图

func (*BoltFS) SymlinkIfPossible

func (fs *BoltFS) SymlinkIfPossible(oldname, newname string) error

SymlinkIfPossible 创建符号链接(不支持)

type BoltFile

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

BoltFile 实现afero.File接口

func (*BoltFile) Close

func (f *BoltFile) Close() error

Close 关闭文件

func (*BoltFile) Name

func (f *BoltFile) Name() string

Name 返回文件名

func (*BoltFile) Read

func (f *BoltFile) Read(p []byte) (n int, err error)

Read 读取文件

func (*BoltFile) ReadAt

func (f *BoltFile) ReadAt(p []byte, off int64) (n int, err error)

ReadAt 从指定位置读取

func (*BoltFile) Readdir

func (f *BoltFile) Readdir(count int) ([]os.FileInfo, error)

Readdir 读取目录内容

func (*BoltFile) Readdirnames

func (f *BoltFile) Readdirnames(count int) ([]string, error)

Readdirnames 读取目录名称

func (*BoltFile) Seek

func (f *BoltFile) Seek(offset int64, whence int) (int64, error)

Seek 移动文件指针

func (*BoltFile) Stat

func (f *BoltFile) Stat() (os.FileInfo, error)

Stat 获取文件信息

func (*BoltFile) Sync

func (f *BoltFile) Sync() error

Sync 同步到存储

func (*BoltFile) Truncate

func (f *BoltFile) Truncate(size int64) error

Truncate 截断文件

func (*BoltFile) Write

func (f *BoltFile) Write(p []byte) (n int, err error)

Write 写入文件

func (*BoltFile) WriteAt

func (f *BoltFile) WriteAt(p []byte, off int64) (n int, err error)

WriteAt 在指定位置写入

func (*BoltFile) WriteString

func (f *BoltFile) WriteString(s string) (int, error)

WriteString 写入字符串

type BoltFileInfo

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

BoltFileInfo 实现os.FileInfo接口

func (*BoltFileInfo) IsDir

func (fi *BoltFileInfo) IsDir() bool

func (*BoltFileInfo) ModTime

func (fi *BoltFileInfo) ModTime() time.Time

func (*BoltFileInfo) Mode

func (fi *BoltFileInfo) Mode() os.FileMode

func (*BoltFileInfo) Name

func (fi *BoltFileInfo) Name() string

func (*BoltFileInfo) Size

func (fi *BoltFileInfo) Size() int64

func (*BoltFileInfo) Sys

func (fi *BoltFileInfo) Sys() interface{}

type DirEntry

type DirEntry struct {
	Name     string    `json:"name"`
	IsDir    bool      `json:"is_dir"`
	Modified time.Time `json:"modified"`
}

DirEntry 目录条目

type FileMetadata

type FileMetadata struct {
	Name         string    `json:"name"`
	Size         int64     `json:"size"`
	Mode         uint32    `json:"mode"`
	ModTime      time.Time `json:"mod_time"`
	AccessTime   time.Time `json:"access_time"`
	IsDir        bool      `json:"is_dir"`
	ParentDir    string    `json:"parent_dir"`
	DataKey      string    `json:"data_key"`      // 数据在BoltDB中的key
	Version      int       `json:"version"`       // 乐观锁版本
	ContentType  string    `json:"content_type"`  // 文件类型,对缩略图有用
	ThumbnailKey string    `json:"thumbnail_key"` // 缩略图key(如果有)
	// contains filtered or unexported fields
}

FileMetadata 文件元数据

func NewFileMetadata

func NewFileMetadata(name string, isDir bool, perm os.FileMode) *FileMetadata

NewFileMetadata 创建新文件元数据

func (*FileMetadata) Clone

func (m *FileMetadata) Clone() *FileMetadata

func (*FileMetadata) GetSize

func (m *FileMetadata) GetSize() int64

修改 GetSize 等需要并发安全的方法

func (*FileMetadata) Lock

func (m *FileMetadata) Lock()

Lock 获取写锁

func (*FileMetadata) Marshal

func (m *FileMetadata) Marshal() ([]byte, error)

Marshal 序列化元数据

func (*FileMetadata) RLock

func (m *FileMetadata) RLock()

RLock 获取读锁

func (*FileMetadata) RUnlock

func (m *FileMetadata) RUnlock()

RUnlock 释放读锁

func (*FileMetadata) SetSize

func (m *FileMetadata) SetSize(size int64)

func (*FileMetadata) ToFileInfo

func (m *FileMetadata) ToFileInfo() os.FileInfo

ToFileInfo 转换为os.FileInfo ToFileInfo 转换为os.FileInfo

func (*FileMetadata) Unlock

func (m *FileMetadata) Unlock()

Unlock 释放写锁

func (*FileMetadata) Unmarshal

func (m *FileMetadata) Unmarshal(data []byte) error

Unmarshal 反序列化元数据

type IndexManager

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

IndexManager 索引管理器

func NewIndexManager

func NewIndexManager(db *bolt.DB, enableCache bool) *IndexManager

NewIndexManager 创建索引管理器

func (*IndexManager) AddContentIndex

func (im *IndexManager) AddContentIndex(contentHash string, filePath string) error

AddContentIndex 添加内容索引(用于文件去重)

func (*IndexManager) AddToDirIndex

func (im *IndexManager) AddToDirIndex(dirPath, fileName string, isDir bool) error

AddToDirIndex 添加文件到目录索引

func (*IndexManager) BatchUpdate

func (im *IndexManager) BatchUpdate(updates []IndexUpdate) error

BatchUpdate 批量更新索引

func (*IndexManager) DeletePath

func (im *IndexManager) DeletePath(path string) error

DeletePath 删除路径索引

func (*IndexManager) FindDuplicateFiles

func (im *IndexManager) FindDuplicateFiles(contentHash string) ([]string, error)

FindDuplicateFiles 查找重复文件

func (*IndexManager) GetPath

func (im *IndexManager) GetPath(path string) (*FileMetadata, error)

GetPath 获取路径索引

func (*IndexManager) GetStats

func (im *IndexManager) GetStats() (*IndexStats, error)

GetStats 获取索引统计信息

func (*IndexManager) Initialize

func (im *IndexManager) Initialize() error

Initialize 初始化索引Buckets

func (*IndexManager) ListDir

func (im *IndexManager) ListDir(dirPath string) ([]DirEntry, error)

ListDir 列出目录内容

func (*IndexManager) PathExists

func (im *IndexManager) PathExists(path string) bool

PathExists 检查路径是否存在

func (*IndexManager) PutPath

func (im *IndexManager) PutPath(path string, meta *FileMetadata) error

PutPath 添加/更新路径索引

func (*IndexManager) RemoveContentIndex

func (im *IndexManager) RemoveContentIndex(contentHash, filePath string) error

RemoveContentIndex 移除内容索引

func (*IndexManager) RemoveFromDirIndex

func (im *IndexManager) RemoveFromDirIndex(dirPath, fileName string) error

RemoveFromDirIndex 从目录索引移除文件

func (*IndexManager) SearchByPattern

func (im *IndexManager) SearchByPattern(pattern string) ([]string, error)

SearchByPattern 模式搜索(简单通配符)

func (*IndexManager) SearchByPrefix

func (im *IndexManager) SearchByPrefix(prefix string) ([]string, error)

SearchByPrefix 前缀搜索

type IndexStats

type IndexStats struct {
	TotalFiles          int64 `json:"total_files"`
	TotalDirs           int64 `json:"total_dirs"`
	UniqueContentHashes int64 `json:"unique_content_hashes"`
}

IndexStats 索引统计信息

type IndexUpdate

type IndexUpdate struct {
	Type     UpdateType
	Key      string
	Metadata *FileMetadata
	DirPath  string
	FileName string
	IsDir    bool
}

IndexUpdate 索引更新操作

type UpdateType

type UpdateType int
const (
	UpdateTypePath UpdateType = iota
	UpdateTypeDirAdd
	UpdateTypeDirRemove
)

Jump to

Keyboard shortcuts

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