Rename Node.FileType -> Type
This commit is contained in:
parent
5e3a41dbd2
commit
5764b55aee
13 changed files with 58 additions and 58 deletions
|
@ -91,7 +91,7 @@ func (c CmdFind) findInTree(repo *repository.Repository, id restic.ID, path stri
|
|||
debug.Log("restic.find", " pattern does not match\n")
|
||||
}
|
||||
|
||||
if node.FileType == "dir" {
|
||||
if node.Type == "dir" {
|
||||
subdirResults, err := c.findInTree(repo, *node.Subtree, filepath.Join(path, node.Name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -30,7 +30,7 @@ func (cmd CmdLs) printNode(prefix string, n *restic.Node) string {
|
|||
return filepath.Join(prefix, n.Name)
|
||||
}
|
||||
|
||||
switch n.FileType {
|
||||
switch n.Type {
|
||||
case "file":
|
||||
return fmt.Sprintf("%s %5d %5d %6d %s %s",
|
||||
n.Mode, n.UID, n.GID, n.Size, n.ModTime, filepath.Join(prefix, n.Name))
|
||||
|
@ -41,7 +41,7 @@ func (cmd CmdLs) printNode(prefix string, n *restic.Node) string {
|
|||
return fmt.Sprintf("%s %5d %5d %6d %s %s -> %s",
|
||||
n.Mode|os.ModeSymlink, n.UID, n.GID, n.Size, n.ModTime, filepath.Join(prefix, n.Name), n.LinkTarget)
|
||||
default:
|
||||
return fmt.Sprintf("<Node(%s) %s>", n.FileType, n.Name)
|
||||
return fmt.Sprintf("<Node(%s) %s>", n.Type, n.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ func (cmd CmdLs) printTree(prefix string, repo *repository.Repository, id restic
|
|||
for _, entry := range tree.Nodes {
|
||||
cmd.global.Printf(cmd.printNode(prefix, entry) + "\n")
|
||||
|
||||
if entry.FileType == "dir" && entry.Subtree != nil {
|
||||
if entry.Type == "dir" && entry.Subtree != nil {
|
||||
err = cmd.printTree(filepath.Join(prefix, entry.Name), repo, *entry.Subtree)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -81,7 +81,7 @@ func ArchiveReader(repo restic.Repository, p *restic.Progress, rd io.Reader, nam
|
|||
Name: name,
|
||||
AccessTime: time.Now(),
|
||||
ModTime: time.Now(),
|
||||
FileType: "file",
|
||||
Type: "file",
|
||||
Mode: 0644,
|
||||
Size: fileSize,
|
||||
UID: sn.UID,
|
||||
|
|
|
@ -304,7 +304,7 @@ func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *restic.Progress, done <-
|
|||
}
|
||||
|
||||
// otherwise read file normally
|
||||
if node.FileType == "file" && len(node.Content) == 0 {
|
||||
if node.Type == "file" && len(node.Content) == 0 {
|
||||
debug.Log("Archiver.fileWorker", " read and save %v, content: %v", e.Path(), node.Content)
|
||||
err = arch.SaveFile(p, node)
|
||||
if err != nil {
|
||||
|
@ -371,7 +371,7 @@ func (arch *Archiver) dirWorker(wg *sync.WaitGroup, p *restic.Progress, done <-c
|
|||
node := res.(*restic.Node)
|
||||
tree.Insert(node)
|
||||
|
||||
if node.FileType == "dir" {
|
||||
if node.Type == "dir" {
|
||||
debug.Log("Archiver.dirWorker", "got tree node for %s: %v", node.Path, node.Subtree)
|
||||
|
||||
if node.Subtree.IsNull() {
|
||||
|
|
|
@ -581,7 +581,7 @@ func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
|
|||
var blobs []restic.ID
|
||||
|
||||
for _, node := range tree.Nodes {
|
||||
switch node.FileType {
|
||||
switch node.Type {
|
||||
case "file":
|
||||
if node.Content == nil {
|
||||
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("file %q has nil blob list", node.Name)})
|
||||
|
@ -609,7 +609,7 @@ func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
|
|||
// nothing to check
|
||||
|
||||
default:
|
||||
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("node %q with invalid type %q", node.Name, node.FileType)})
|
||||
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("node %q with invalid type %q", node.Name, node.Type)})
|
||||
}
|
||||
|
||||
if node.Name == "" {
|
||||
|
|
|
@ -12,7 +12,7 @@ func FindUsedBlobs(repo Repository, treeID ID, blobs BlobSet, seen BlobSet) erro
|
|||
}
|
||||
|
||||
for _, node := range tree.Nodes {
|
||||
switch node.FileType {
|
||||
switch node.Type {
|
||||
case "file":
|
||||
for _, blob := range node.Content {
|
||||
blobs.Insert(BlobHandle{ID: blob, Type: DataBlob})
|
||||
|
|
|
@ -51,7 +51,7 @@ func newDir(repo *repository.Repository, node *restic.Node, ownerIsRoot bool) (*
|
|||
// replaceSpecialNodes replaces nodes with name "." and "/" by their contents.
|
||||
// Otherwise, the node is returned.
|
||||
func replaceSpecialNodes(repo *repository.Repository, node *restic.Node) ([]*restic.Node, error) {
|
||||
if node.FileType != "dir" || node.Subtree == nil {
|
||||
if node.Type != "dir" || node.Subtree == nil {
|
||||
return []*restic.Node{node}, nil
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
|||
|
||||
for _, node := range d.items {
|
||||
var typ fuse.DirentType
|
||||
switch node.FileType {
|
||||
switch node.Type {
|
||||
case "dir":
|
||||
typ = fuse.DT_Dir
|
||||
case "file":
|
||||
|
@ -150,7 +150,7 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
|||
debug.Log("dir.Lookup", " Lookup(%v) -> not found", name)
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
switch node.FileType {
|
||||
switch node.Type {
|
||||
case "dir":
|
||||
return newDir(d.repo, node, d.ownerIsRoot)
|
||||
case "file":
|
||||
|
@ -158,7 +158,7 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
|||
case "symlink":
|
||||
return newLink(d.repo, node, d.ownerIsRoot)
|
||||
default:
|
||||
debug.Log("dir.Lookup", " node %v has unknown type %v", name, node.FileType)
|
||||
debug.Log("dir.Lookup", " node %v has unknown type %v", name, node.Type)
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
// Node is a file, directory or other item in a backup.
|
||||
type Node struct {
|
||||
Name string `json:"name"`
|
||||
FileType string `json:"type"`
|
||||
Type string `json:"type"`
|
||||
Mode os.FileMode `json:"mode,omitempty"`
|
||||
ModTime time.Time `json:"mtime,omitempty"`
|
||||
AccessTime time.Time `json:"atime,omitempty"`
|
||||
|
@ -47,7 +47,7 @@ type Node struct {
|
|||
}
|
||||
|
||||
func (node Node) String() string {
|
||||
switch node.FileType {
|
||||
switch node.Type {
|
||||
case "file":
|
||||
return fmt.Sprintf("%s %5d %5d %6d %s %s",
|
||||
node.Mode, node.UID, node.GID, node.Size, node.ModTime, node.Name)
|
||||
|
@ -56,7 +56,7 @@ func (node Node) String() string {
|
|||
node.Mode|os.ModeDir, node.UID, node.GID, node.Size, node.ModTime, node.Name)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("<Node(%s) %s>", node.FileType, node.Name)
|
||||
return fmt.Sprintf("<Node(%s) %s>", node.Type, node.Name)
|
||||
}
|
||||
|
||||
func (node Node) Tree() *Tree {
|
||||
|
@ -73,8 +73,8 @@ func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
|
|||
ModTime: fi.ModTime(),
|
||||
}
|
||||
|
||||
node.FileType = nodeTypeFromFileInfo(fi)
|
||||
if node.FileType == "file" {
|
||||
node.Type = nodeTypeFromFileInfo(fi)
|
||||
if node.Type == "file" {
|
||||
node.Size = uint64(fi.Size())
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ func nodeTypeFromFileInfo(fi os.FileInfo) string {
|
|||
func (node *Node) CreateAt(path string, repo Repository) error {
|
||||
debug.Log("Node.CreateAt", "create node %v at %v", node.Name, path)
|
||||
|
||||
switch node.FileType {
|
||||
switch node.Type {
|
||||
case "dir":
|
||||
if err := node.createDirAt(path); err != nil {
|
||||
return err
|
||||
|
@ -135,7 +135,7 @@ func (node *Node) CreateAt(path string, repo Repository) error {
|
|||
case "socket":
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("filetype %q not implemented!\n", node.FileType)
|
||||
return errors.Errorf("filetype %q not implemented!\n", node.Type)
|
||||
}
|
||||
|
||||
err := node.restoreMetadata(path)
|
||||
|
@ -154,14 +154,14 @@ func (node Node) restoreMetadata(path string) error {
|
|||
return errors.Wrap(err, "Lchown")
|
||||
}
|
||||
|
||||
if node.FileType != "symlink" {
|
||||
if node.Type != "symlink" {
|
||||
err = fs.Chmod(path, node.Mode)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Chmod")
|
||||
}
|
||||
}
|
||||
|
||||
if node.FileType != "dir" {
|
||||
if node.Type != "dir" {
|
||||
err = node.RestoreTimestamps(path)
|
||||
if err != nil {
|
||||
debug.Log("Node.restoreMetadata", "error restoring timestamps for dir %v: %v", path, err)
|
||||
|
@ -178,7 +178,7 @@ func (node Node) RestoreTimestamps(path string) error {
|
|||
syscall.NsecToTimespec(node.ModTime.UnixNano()),
|
||||
}
|
||||
|
||||
if node.FileType == "symlink" {
|
||||
if node.Type == "symlink" {
|
||||
return node.restoreSymlinkTimestamps(path, utimes)
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ func (node Node) Equals(other Node) bool {
|
|||
if node.Name != other.Name {
|
||||
return false
|
||||
}
|
||||
if node.FileType != other.FileType {
|
||||
if node.Type != other.Type {
|
||||
return false
|
||||
}
|
||||
if node.Mode != other.Mode {
|
||||
|
@ -371,13 +371,13 @@ func (node Node) sameContent(other Node) bool {
|
|||
}
|
||||
|
||||
func (node *Node) IsNewer(path string, fi os.FileInfo) bool {
|
||||
if node.FileType != "file" {
|
||||
if node.Type != "file" {
|
||||
debug.Log("node.IsNewer", "node %v is newer: not file", path)
|
||||
return true
|
||||
}
|
||||
|
||||
tpe := nodeTypeFromFileInfo(fi)
|
||||
if node.Name != fi.Name() || node.FileType != tpe {
|
||||
if node.Name != fi.Name() || node.Type != tpe {
|
||||
debug.Log("node.IsNewer", "node %v is newer: name or type changed", path)
|
||||
return true
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
|
|||
return err
|
||||
}
|
||||
|
||||
switch node.FileType {
|
||||
switch node.Type {
|
||||
case "file":
|
||||
node.Size = uint64(stat.size())
|
||||
node.Links = uint64(stat.nlink())
|
||||
|
@ -480,7 +480,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
|
|||
case "fifo":
|
||||
case "socket":
|
||||
default:
|
||||
err = errors.Errorf("invalid node type %q", node.FileType)
|
||||
err = errors.Errorf("invalid node type %q", node.Type)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
|
@ -73,7 +73,7 @@ func parseTime(s string) time.Time {
|
|||
var nodeTests = []restic.Node{
|
||||
restic.Node{
|
||||
Name: "testFile",
|
||||
FileType: "file",
|
||||
Type: "file",
|
||||
Content: restic.IDs{},
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
|
@ -84,7 +84,7 @@ var nodeTests = []restic.Node{
|
|||
},
|
||||
restic.Node{
|
||||
Name: "testSuidFile",
|
||||
FileType: "file",
|
||||
Type: "file",
|
||||
Content: restic.IDs{},
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
|
@ -95,7 +95,7 @@ var nodeTests = []restic.Node{
|
|||
},
|
||||
restic.Node{
|
||||
Name: "testSuidFile2",
|
||||
FileType: "file",
|
||||
Type: "file",
|
||||
Content: restic.IDs{},
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
|
@ -106,7 +106,7 @@ var nodeTests = []restic.Node{
|
|||
},
|
||||
restic.Node{
|
||||
Name: "testSticky",
|
||||
FileType: "file",
|
||||
Type: "file",
|
||||
Content: restic.IDs{},
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
|
@ -117,7 +117,7 @@ var nodeTests = []restic.Node{
|
|||
},
|
||||
restic.Node{
|
||||
Name: "testDir",
|
||||
FileType: "dir",
|
||||
Type: "dir",
|
||||
Subtree: nil,
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
|
@ -128,7 +128,7 @@ var nodeTests = []restic.Node{
|
|||
},
|
||||
restic.Node{
|
||||
Name: "testSymlink",
|
||||
FileType: "symlink",
|
||||
Type: "symlink",
|
||||
LinkTarget: "invalid",
|
||||
UID: uint32(os.Getuid()),
|
||||
GID: uint32(os.Getgid()),
|
||||
|
@ -155,10 +155,10 @@ func TestNodeRestoreAt(t *testing.T) {
|
|||
nodePath := filepath.Join(tempdir, test.Name)
|
||||
OK(t, test.CreateAt(nodePath, nil))
|
||||
|
||||
if test.FileType == "symlink" && runtime.GOOS == "windows" {
|
||||
if test.Type == "symlink" && runtime.GOOS == "windows" {
|
||||
continue
|
||||
}
|
||||
if test.FileType == "dir" {
|
||||
if test.Type == "dir" {
|
||||
OK(t, test.RestoreTimestamps(nodePath))
|
||||
}
|
||||
|
||||
|
@ -169,25 +169,25 @@ func TestNodeRestoreAt(t *testing.T) {
|
|||
OK(t, err)
|
||||
|
||||
Assert(t, test.Name == n2.Name,
|
||||
"%v: name doesn't match (%v != %v)", test.FileType, test.Name, n2.Name)
|
||||
Assert(t, test.FileType == n2.FileType,
|
||||
"%v: type doesn't match (%v != %v)", test.FileType, test.FileType, n2.FileType)
|
||||
"%v: name doesn't match (%v != %v)", test.Type, test.Name, n2.Name)
|
||||
Assert(t, test.Type == n2.Type,
|
||||
"%v: type doesn't match (%v != %v)", test.Type, test.Type, n2.Type)
|
||||
Assert(t, test.Size == n2.Size,
|
||||
"%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size)
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
Assert(t, test.UID == n2.UID,
|
||||
"%v: UID doesn't match (%v != %v)", test.FileType, test.UID, n2.UID)
|
||||
"%v: UID doesn't match (%v != %v)", test.Type, test.UID, n2.UID)
|
||||
Assert(t, test.GID == n2.GID,
|
||||
"%v: GID doesn't match (%v != %v)", test.FileType, test.GID, n2.GID)
|
||||
if test.FileType != "symlink" {
|
||||
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
||||
if test.Type != "symlink" {
|
||||
Assert(t, test.Mode == n2.Mode,
|
||||
"%v: mode doesn't match (0%o != 0%o)", test.FileType, test.Mode, n2.Mode)
|
||||
"%v: mode doesn't match (0%o != 0%o)", test.Type, test.Mode, n2.Mode)
|
||||
}
|
||||
}
|
||||
|
||||
AssertFsTimeEqual(t, "AccessTime", test.FileType, test.AccessTime, n2.AccessTime)
|
||||
AssertFsTimeEqual(t, "ModTime", test.FileType, test.ModTime, n2.ModTime)
|
||||
AssertFsTimeEqual(t, "AccessTime", test.Type, test.AccessTime, n2.AccessTime)
|
||||
AssertFsTimeEqual(t, "ModTime", test.Type, test.ModTime, n2.ModTime)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ func (res *Restorer) restoreTo(dst string, dir string, treeID ID) error {
|
|||
}
|
||||
}
|
||||
|
||||
if node.FileType == "dir" {
|
||||
if node.Type == "dir" {
|
||||
if node.Subtree == nil {
|
||||
return errors.Errorf("Dir without subtree in tree %v", treeID.Str())
|
||||
}
|
||||
|
|
|
@ -108,10 +108,10 @@ func (fs fakeFileSystem) saveTree(seed int64, depth int) ID {
|
|||
id := fs.saveTree(treeSeed, depth-1)
|
||||
|
||||
node := &Node{
|
||||
Name: fmt.Sprintf("dir-%v", treeSeed),
|
||||
FileType: "dir",
|
||||
Mode: 0755,
|
||||
Subtree: &id,
|
||||
Name: fmt.Sprintf("dir-%v", treeSeed),
|
||||
Type: "dir",
|
||||
Mode: 0755,
|
||||
Subtree: &id,
|
||||
}
|
||||
|
||||
tree.Nodes = append(tree.Nodes, node)
|
||||
|
@ -122,10 +122,10 @@ func (fs fakeFileSystem) saveTree(seed int64, depth int) ID {
|
|||
fileSize := (maxFileSize / maxSeed) * fileSeed
|
||||
|
||||
node := &Node{
|
||||
Name: fmt.Sprintf("file-%v", fileSeed),
|
||||
FileType: "file",
|
||||
Mode: 0644,
|
||||
Size: uint64(fileSize),
|
||||
Name: fmt.Sprintf("file-%v", fileSeed),
|
||||
Type: "file",
|
||||
Mode: 0644,
|
||||
Size: uint64(fileSize),
|
||||
}
|
||||
|
||||
node.Content = fs.saveFile(fakeFile(fs.t, fileSeed, fileSize))
|
||||
|
|
|
@ -95,7 +95,7 @@ func (t Tree) Find(name string) (*Node, error) {
|
|||
// Subtrees returns a slice of all subtree IDs of the tree.
|
||||
func (t Tree) Subtrees() (trees IDs) {
|
||||
for _, node := range t.Nodes {
|
||||
if node.FileType == "dir" && node.Subtree != nil {
|
||||
if node.Type == "dir" && node.Subtree != nil {
|
||||
trees = append(trees, *node.Subtree)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func (tw *TreeWalker) walk(path string, tree *Tree, done chan struct{}) {
|
|||
// load all subtrees in parallel
|
||||
results := make([]<-chan loadTreeResult, len(tree.Nodes))
|
||||
for i, node := range tree.Nodes {
|
||||
if node.FileType == "dir" {
|
||||
if node.Type == "dir" {
|
||||
resCh := make(chan loadTreeResult, 1)
|
||||
tw.ch <- loadTreeJob{
|
||||
id: *node.Subtree,
|
||||
|
@ -86,7 +86,7 @@ func (tw *TreeWalker) walk(path string, tree *Tree, done chan struct{}) {
|
|||
p := filepath.Join(path, node.Name)
|
||||
var job WalkTreeJob
|
||||
|
||||
if node.FileType == "dir" {
|
||||
if node.Type == "dir" {
|
||||
if results[i] == nil {
|
||||
panic("result chan should not be nil")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue