refactor(ax): expand semantic backend naming
This commit is contained in:
parent
d4615a2ad8
commit
c0ee58201b
4 changed files with 62 additions and 62 deletions
|
|
@ -337,15 +337,15 @@ func (medium *Medium) Rename(oldPath, newPath string) error {
|
|||
|
||||
// Move explicit directories
|
||||
dirsToMove := make(map[string]string)
|
||||
for d := range medium.directorySet {
|
||||
if d == oldPath || core.HasPrefix(d, oldPrefix) {
|
||||
newD := core.Concat(newPath, core.TrimPrefix(d, oldPath))
|
||||
dirsToMove[d] = newD
|
||||
for directoryPath := range medium.directorySet {
|
||||
if directoryPath == oldPath || core.HasPrefix(directoryPath, oldPrefix) {
|
||||
newDirectoryPath := core.Concat(newPath, core.TrimPrefix(directoryPath, oldPath))
|
||||
dirsToMove[directoryPath] = newDirectoryPath
|
||||
}
|
||||
}
|
||||
for old, nw := range dirsToMove {
|
||||
delete(medium.directorySet, old)
|
||||
medium.directorySet[nw] = true
|
||||
for oldDirectoryPath, newDirectoryPath := range dirsToMove {
|
||||
delete(medium.directorySet, oldDirectoryPath)
|
||||
medium.directorySet[newDirectoryPath] = true
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -376,11 +376,11 @@ func (medium *Medium) List(filePath string) ([]fs.DirEntry, error) {
|
|||
seen[e.Name()] = true
|
||||
}
|
||||
|
||||
for d := range medium.directorySet {
|
||||
if !core.HasPrefix(d, prefix) {
|
||||
for directoryPath := range medium.directorySet {
|
||||
if !core.HasPrefix(directoryPath, prefix) {
|
||||
continue
|
||||
}
|
||||
rest := core.TrimPrefix(d, prefix)
|
||||
rest := core.TrimPrefix(directoryPath, prefix)
|
||||
if rest == "" {
|
||||
continue
|
||||
}
|
||||
|
|
@ -515,8 +515,8 @@ func (medium *Medium) hasPrefixLocked(prefix string) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
}
|
||||
for d := range medium.directorySet {
|
||||
if core.HasPrefix(d, prefix) {
|
||||
for directoryPath := range medium.directorySet {
|
||||
if core.HasPrefix(directoryPath, prefix) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
node/node.go
10
node/node.go
|
|
@ -81,11 +81,11 @@ func (node *Node) ToTar() ([]byte, error) {
|
|||
|
||||
// Example: restored, _ := node.FromTar(snapshot)
|
||||
func FromTar(data []byte) (*Node, error) {
|
||||
n := New()
|
||||
if err := n.LoadTar(data); err != nil {
|
||||
restoredNode := New()
|
||||
if err := restoredNode.LoadTar(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return n, nil
|
||||
return restoredNode, nil
|
||||
}
|
||||
|
||||
// Example: _ = nodeTree.LoadTar(snapshot)
|
||||
|
|
@ -319,8 +319,8 @@ func (node *Node) ReadDir(name string) ([]fs.DirEntry, error) {
|
|||
seen[firstComponent] = true
|
||||
|
||||
if core.Contains(relPath, "/") {
|
||||
dir := &dirInfo{name: firstComponent, modTime: time.Now()}
|
||||
entries = append(entries, fs.FileInfoToDirEntry(dir))
|
||||
directoryInfo := &dirInfo{name: firstComponent, modTime: time.Now()}
|
||||
entries = append(entries, fs.FileInfoToDirEntry(directoryInfo))
|
||||
} else {
|
||||
file := node.files[filePath]
|
||||
info, _ := file.Stat()
|
||||
|
|
|
|||
60
s3/s3.go
60
s3/s3.go
|
|
@ -58,10 +58,10 @@ func deleteObjectsError(prefix string, errs []types.Error) error {
|
|||
return nil
|
||||
}
|
||||
details := make([]string, 0, len(errs))
|
||||
for _, item := range errs {
|
||||
key := aws.ToString(item.Key)
|
||||
code := aws.ToString(item.Code)
|
||||
message := aws.ToString(item.Message)
|
||||
for _, errorItem := range errs {
|
||||
key := aws.ToString(errorItem.Key)
|
||||
code := aws.ToString(errorItem.Code)
|
||||
message := aws.ToString(errorItem.Message)
|
||||
switch {
|
||||
case code != "" && message != "":
|
||||
details = append(details, core.Concat(key, ": ", code, " ", message))
|
||||
|
|
@ -239,11 +239,11 @@ func (medium *Medium) DeleteAll(filePath string) error {
|
|||
prefix += "/"
|
||||
}
|
||||
|
||||
paginator := true
|
||||
continueListing := true
|
||||
var continuationToken *string
|
||||
|
||||
for paginator {
|
||||
listOut, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
for continueListing {
|
||||
listOutput, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
Bucket: aws.String(medium.bucket),
|
||||
Prefix: aws.String(prefix),
|
||||
ContinuationToken: continuationToken,
|
||||
|
|
@ -252,13 +252,13 @@ func (medium *Medium) DeleteAll(filePath string) error {
|
|||
return core.E("s3.DeleteAll", core.Concat("failed to list objects: ", prefix), err)
|
||||
}
|
||||
|
||||
if len(listOut.Contents) == 0 {
|
||||
if len(listOutput.Contents) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
objects := make([]types.ObjectIdentifier, len(listOut.Contents))
|
||||
for i, obj := range listOut.Contents {
|
||||
objects[i] = types.ObjectIdentifier{Key: obj.Key}
|
||||
objects := make([]types.ObjectIdentifier, len(listOutput.Contents))
|
||||
for i, object := range listOutput.Contents {
|
||||
objects[i] = types.ObjectIdentifier{Key: object.Key}
|
||||
}
|
||||
|
||||
deleteOut, err := medium.client.DeleteObjects(context.Background(), &awss3.DeleteObjectsInput{
|
||||
|
|
@ -272,10 +272,10 @@ func (medium *Medium) DeleteAll(filePath string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if listOut.IsTruncated != nil && *listOut.IsTruncated {
|
||||
continuationToken = listOut.NextContinuationToken
|
||||
if listOutput.IsTruncated != nil && *listOutput.IsTruncated {
|
||||
continuationToken = listOutput.NextContinuationToken
|
||||
} else {
|
||||
paginator = false
|
||||
continueListing = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -321,7 +321,7 @@ func (medium *Medium) List(filePath string) ([]fs.DirEntry, error) {
|
|||
|
||||
var entries []fs.DirEntry
|
||||
|
||||
listOut, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
listOutput, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
Bucket: aws.String(medium.bucket),
|
||||
Prefix: aws.String(prefix),
|
||||
Delimiter: aws.String("/"),
|
||||
|
|
@ -331,7 +331,7 @@ func (medium *Medium) List(filePath string) ([]fs.DirEntry, error) {
|
|||
}
|
||||
|
||||
// Common prefixes are "directories"
|
||||
for _, commonPrefix := range listOut.CommonPrefixes {
|
||||
for _, commonPrefix := range listOutput.CommonPrefixes {
|
||||
if commonPrefix.Prefix == nil {
|
||||
continue
|
||||
}
|
||||
|
|
@ -353,21 +353,21 @@ func (medium *Medium) List(filePath string) ([]fs.DirEntry, error) {
|
|||
}
|
||||
|
||||
// Contents are "files" (excluding the prefix itself)
|
||||
for _, obj := range listOut.Contents {
|
||||
if obj.Key == nil {
|
||||
for _, object := range listOutput.Contents {
|
||||
if object.Key == nil {
|
||||
continue
|
||||
}
|
||||
name := core.TrimPrefix(*obj.Key, prefix)
|
||||
name := core.TrimPrefix(*object.Key, prefix)
|
||||
if name == "" || core.Contains(name, "/") {
|
||||
continue
|
||||
}
|
||||
var size int64
|
||||
if obj.Size != nil {
|
||||
size = *obj.Size
|
||||
if object.Size != nil {
|
||||
size = *object.Size
|
||||
}
|
||||
var modTime time.Time
|
||||
if obj.LastModified != nil {
|
||||
modTime = *obj.LastModified
|
||||
if object.LastModified != nil {
|
||||
modTime = *object.LastModified
|
||||
}
|
||||
entries = append(entries, &dirEntry{
|
||||
name: name,
|
||||
|
|
@ -532,7 +532,7 @@ func (medium *Medium) Exists(filePath string) bool {
|
|||
if !core.HasSuffix(prefix, "/") {
|
||||
prefix += "/"
|
||||
}
|
||||
listOut, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
listOutput, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
Bucket: aws.String(medium.bucket),
|
||||
Prefix: aws.String(prefix),
|
||||
MaxKeys: aws.Int32(1),
|
||||
|
|
@ -540,7 +540,7 @@ func (medium *Medium) Exists(filePath string) bool {
|
|||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return len(listOut.Contents) > 0 || len(listOut.CommonPrefixes) > 0
|
||||
return len(listOutput.Contents) > 0 || len(listOutput.CommonPrefixes) > 0
|
||||
}
|
||||
|
||||
// Example: ok := medium.IsDir("reports")
|
||||
|
|
@ -555,7 +555,7 @@ func (medium *Medium) IsDir(filePath string) bool {
|
|||
prefix += "/"
|
||||
}
|
||||
|
||||
listOut, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
listOutput, err := medium.client.ListObjectsV2(context.Background(), &awss3.ListObjectsV2Input{
|
||||
Bucket: aws.String(medium.bucket),
|
||||
Prefix: aws.String(prefix),
|
||||
MaxKeys: aws.Int32(1),
|
||||
|
|
@ -563,7 +563,7 @@ func (medium *Medium) IsDir(filePath string) bool {
|
|||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return len(listOut.Contents) > 0 || len(listOut.CommonPrefixes) > 0
|
||||
return len(listOutput.Contents) > 0 || len(listOutput.CommonPrefixes) > 0
|
||||
}
|
||||
|
||||
// --- Internal types ---
|
||||
|
|
@ -624,9 +624,9 @@ func (file *s3File) Read(buffer []byte) (int, error) {
|
|||
if file.offset >= int64(len(file.content)) {
|
||||
return 0, goio.EOF
|
||||
}
|
||||
n := copy(buffer, file.content[file.offset:])
|
||||
file.offset += int64(n)
|
||||
return n, nil
|
||||
bytesRead := copy(buffer, file.content[file.offset:])
|
||||
file.offset += int64(bytesRead)
|
||||
return bytesRead, nil
|
||||
}
|
||||
|
||||
func (file *s3File) Close() error {
|
||||
|
|
|
|||
|
|
@ -246,8 +246,8 @@ func (medium *Medium) DeleteAll(filePath string) error {
|
|||
if err != nil {
|
||||
return core.E("sqlite.DeleteAll", core.Concat("delete failed: ", key), err)
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
if n == 0 {
|
||||
rowsAffected, _ := res.RowsAffected()
|
||||
if rowsAffected == 0 {
|
||||
return core.E("sqlite.DeleteAll", core.Concat("path not found: ", key), fs.ErrNotExist)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -303,7 +303,7 @@ func (medium *Medium) Rename(oldPath, newPath string) error {
|
|||
oldPrefix := oldKey + "/"
|
||||
newPrefix := newKey + "/"
|
||||
|
||||
rows, err := tx.Query(
|
||||
childRows, err := tx.Query(
|
||||
`SELECT path, content, mode, is_dir, mtime FROM `+medium.table+` WHERE path LIKE ?`,
|
||||
oldPrefix+"%",
|
||||
)
|
||||
|
|
@ -319,22 +319,22 @@ func (medium *Medium) Rename(oldPath, newPath string) error {
|
|||
mtime time.Time
|
||||
}
|
||||
var children []child
|
||||
for rows.Next() {
|
||||
var c child
|
||||
if err := rows.Scan(&c.path, &c.content, &c.mode, &c.isDir, &c.mtime); err != nil {
|
||||
rows.Close()
|
||||
for childRows.Next() {
|
||||
var childEntry child
|
||||
if err := childRows.Scan(&childEntry.path, &childEntry.content, &childEntry.mode, &childEntry.isDir, &childEntry.mtime); err != nil {
|
||||
childRows.Close()
|
||||
return core.E("sqlite.Rename", "scan child failed", err)
|
||||
}
|
||||
children = append(children, c)
|
||||
children = append(children, childEntry)
|
||||
}
|
||||
rows.Close()
|
||||
childRows.Close()
|
||||
|
||||
for _, c := range children {
|
||||
newChildPath := core.Concat(newPrefix, core.TrimPrefix(c.path, oldPrefix))
|
||||
for _, childEntry := range children {
|
||||
newChildPath := core.Concat(newPrefix, core.TrimPrefix(childEntry.path, oldPrefix))
|
||||
_, err = tx.Exec(
|
||||
`INSERT INTO `+medium.table+` (path, content, mode, is_dir, mtime) VALUES (?, ?, ?, ?, ?)
|
||||
ON CONFLICT(path) DO UPDATE SET content = excluded.content, mode = excluded.mode, is_dir = excluded.is_dir, mtime = excluded.mtime`,
|
||||
newChildPath, c.content, c.mode, c.isDir, c.mtime,
|
||||
newChildPath, childEntry.content, childEntry.mode, childEntry.isDir, childEntry.mtime,
|
||||
)
|
||||
if err != nil {
|
||||
return core.E("sqlite.Rename", "insert child failed", err)
|
||||
|
|
@ -639,9 +639,9 @@ func (file *sqliteFile) Read(buffer []byte) (int, error) {
|
|||
if file.offset >= int64(len(file.content)) {
|
||||
return 0, goio.EOF
|
||||
}
|
||||
n := copy(buffer, file.content[file.offset:])
|
||||
file.offset += int64(n)
|
||||
return n, nil
|
||||
bytesRead := copy(buffer, file.content[file.offset:])
|
||||
file.offset += int64(bytesRead)
|
||||
return bytesRead, nil
|
||||
}
|
||||
|
||||
func (file *sqliteFile) Close() error {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue