Rename Node.FileType -> Type

This commit is contained in:
Alexander Neumann 2016-09-01 21:20:03 +02:00
parent 5e3a41dbd2
commit 5764b55aee
13 changed files with 58 additions and 58 deletions

View file

@ -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") 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)) subdirResults, err := c.findInTree(repo, *node.Subtree, filepath.Join(path, node.Name))
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -30,7 +30,7 @@ func (cmd CmdLs) printNode(prefix string, n *restic.Node) string {
return filepath.Join(prefix, n.Name) return filepath.Join(prefix, n.Name)
} }
switch n.FileType { switch n.Type {
case "file": case "file":
return fmt.Sprintf("%s %5d %5d %6d %s %s", return fmt.Sprintf("%s %5d %5d %6d %s %s",
n.Mode, n.UID, n.GID, n.Size, n.ModTime, filepath.Join(prefix, n.Name)) 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", 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) n.Mode|os.ModeSymlink, n.UID, n.GID, n.Size, n.ModTime, filepath.Join(prefix, n.Name), n.LinkTarget)
default: 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 { for _, entry := range tree.Nodes {
cmd.global.Printf(cmd.printNode(prefix, entry) + "\n") 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) err = cmd.printTree(filepath.Join(prefix, entry.Name), repo, *entry.Subtree)
if err != nil { if err != nil {
return err return err

View file

@ -81,7 +81,7 @@ func ArchiveReader(repo restic.Repository, p *restic.Progress, rd io.Reader, nam
Name: name, Name: name,
AccessTime: time.Now(), AccessTime: time.Now(),
ModTime: time.Now(), ModTime: time.Now(),
FileType: "file", Type: "file",
Mode: 0644, Mode: 0644,
Size: fileSize, Size: fileSize,
UID: sn.UID, UID: sn.UID,

View file

@ -304,7 +304,7 @@ func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *restic.Progress, done <-
} }
// otherwise read file normally // 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) debug.Log("Archiver.fileWorker", " read and save %v, content: %v", e.Path(), node.Content)
err = arch.SaveFile(p, node) err = arch.SaveFile(p, node)
if err != nil { if err != nil {
@ -371,7 +371,7 @@ func (arch *Archiver) dirWorker(wg *sync.WaitGroup, p *restic.Progress, done <-c
node := res.(*restic.Node) node := res.(*restic.Node)
tree.Insert(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) debug.Log("Archiver.dirWorker", "got tree node for %s: %v", node.Path, node.Subtree)
if node.Subtree.IsNull() { if node.Subtree.IsNull() {

View file

@ -581,7 +581,7 @@ func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
var blobs []restic.ID var blobs []restic.ID
for _, node := range tree.Nodes { for _, node := range tree.Nodes {
switch node.FileType { switch node.Type {
case "file": case "file":
if node.Content == nil { if node.Content == nil {
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("file %q has nil blob list", node.Name)}) 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 // nothing to check
default: 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 == "" { if node.Name == "" {

View file

@ -12,7 +12,7 @@ func FindUsedBlobs(repo Repository, treeID ID, blobs BlobSet, seen BlobSet) erro
} }
for _, node := range tree.Nodes { for _, node := range tree.Nodes {
switch node.FileType { switch node.Type {
case "file": case "file":
for _, blob := range node.Content { for _, blob := range node.Content {
blobs.Insert(BlobHandle{ID: blob, Type: DataBlob}) blobs.Insert(BlobHandle{ID: blob, Type: DataBlob})

View file

@ -51,7 +51,7 @@ func newDir(repo *repository.Repository, node *restic.Node, ownerIsRoot bool) (*
// replaceSpecialNodes replaces nodes with name "." and "/" by their contents. // replaceSpecialNodes replaces nodes with name "." and "/" by their contents.
// Otherwise, the node is returned. // Otherwise, the node is returned.
func replaceSpecialNodes(repo *repository.Repository, node *restic.Node) ([]*restic.Node, error) { 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 return []*restic.Node{node}, nil
} }
@ -124,7 +124,7 @@ func (d *dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
for _, node := range d.items { for _, node := range d.items {
var typ fuse.DirentType var typ fuse.DirentType
switch node.FileType { switch node.Type {
case "dir": case "dir":
typ = fuse.DT_Dir typ = fuse.DT_Dir
case "file": 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) debug.Log("dir.Lookup", " Lookup(%v) -> not found", name)
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
switch node.FileType { switch node.Type {
case "dir": case "dir":
return newDir(d.repo, node, d.ownerIsRoot) return newDir(d.repo, node, d.ownerIsRoot)
case "file": case "file":
@ -158,7 +158,7 @@ func (d *dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
case "symlink": case "symlink":
return newLink(d.repo, node, d.ownerIsRoot) return newLink(d.repo, node, d.ownerIsRoot)
default: 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 return nil, fuse.ENOENT
} }
} }

View file

@ -21,7 +21,7 @@ import (
// Node is a file, directory or other item in a backup. // Node is a file, directory or other item in a backup.
type Node struct { type Node struct {
Name string `json:"name"` Name string `json:"name"`
FileType string `json:"type"` Type string `json:"type"`
Mode os.FileMode `json:"mode,omitempty"` Mode os.FileMode `json:"mode,omitempty"`
ModTime time.Time `json:"mtime,omitempty"` ModTime time.Time `json:"mtime,omitempty"`
AccessTime time.Time `json:"atime,omitempty"` AccessTime time.Time `json:"atime,omitempty"`
@ -47,7 +47,7 @@ type Node struct {
} }
func (node Node) String() string { func (node Node) String() string {
switch node.FileType { switch node.Type {
case "file": case "file":
return fmt.Sprintf("%s %5d %5d %6d %s %s", return fmt.Sprintf("%s %5d %5d %6d %s %s",
node.Mode, node.UID, node.GID, node.Size, node.ModTime, node.Name) 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) 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 { func (node Node) Tree() *Tree {
@ -73,8 +73,8 @@ func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
ModTime: fi.ModTime(), ModTime: fi.ModTime(),
} }
node.FileType = nodeTypeFromFileInfo(fi) node.Type = nodeTypeFromFileInfo(fi)
if node.FileType == "file" { if node.Type == "file" {
node.Size = uint64(fi.Size()) node.Size = uint64(fi.Size())
} }
@ -107,7 +107,7 @@ func nodeTypeFromFileInfo(fi os.FileInfo) string {
func (node *Node) CreateAt(path string, repo Repository) error { func (node *Node) CreateAt(path string, repo Repository) error {
debug.Log("Node.CreateAt", "create node %v at %v", node.Name, path) debug.Log("Node.CreateAt", "create node %v at %v", node.Name, path)
switch node.FileType { switch node.Type {
case "dir": case "dir":
if err := node.createDirAt(path); err != nil { if err := node.createDirAt(path); err != nil {
return err return err
@ -135,7 +135,7 @@ func (node *Node) CreateAt(path string, repo Repository) error {
case "socket": case "socket":
return nil return nil
default: 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) err := node.restoreMetadata(path)
@ -154,14 +154,14 @@ func (node Node) restoreMetadata(path string) error {
return errors.Wrap(err, "Lchown") return errors.Wrap(err, "Lchown")
} }
if node.FileType != "symlink" { if node.Type != "symlink" {
err = fs.Chmod(path, node.Mode) err = fs.Chmod(path, node.Mode)
if err != nil { if err != nil {
return errors.Wrap(err, "Chmod") return errors.Wrap(err, "Chmod")
} }
} }
if node.FileType != "dir" { if node.Type != "dir" {
err = node.RestoreTimestamps(path) err = node.RestoreTimestamps(path)
if err != nil { if err != nil {
debug.Log("Node.restoreMetadata", "error restoring timestamps for dir %v: %v", path, err) 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()), syscall.NsecToTimespec(node.ModTime.UnixNano()),
} }
if node.FileType == "symlink" { if node.Type == "symlink" {
return node.restoreSymlinkTimestamps(path, utimes) return node.restoreSymlinkTimestamps(path, utimes)
} }
@ -283,7 +283,7 @@ func (node Node) Equals(other Node) bool {
if node.Name != other.Name { if node.Name != other.Name {
return false return false
} }
if node.FileType != other.FileType { if node.Type != other.Type {
return false return false
} }
if node.Mode != other.Mode { 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 { 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) debug.Log("node.IsNewer", "node %v is newer: not file", path)
return true return true
} }
tpe := nodeTypeFromFileInfo(fi) 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) debug.Log("node.IsNewer", "node %v is newer: name or type changed", path)
return true return true
} }
@ -465,7 +465,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
return err return err
} }
switch node.FileType { switch node.Type {
case "file": case "file":
node.Size = uint64(stat.size()) node.Size = uint64(stat.size())
node.Links = uint64(stat.nlink()) node.Links = uint64(stat.nlink())
@ -480,7 +480,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
case "fifo": case "fifo":
case "socket": case "socket":
default: default:
err = errors.Errorf("invalid node type %q", node.FileType) err = errors.Errorf("invalid node type %q", node.Type)
} }
return err return err

View file

@ -73,7 +73,7 @@ func parseTime(s string) time.Time {
var nodeTests = []restic.Node{ var nodeTests = []restic.Node{
restic.Node{ restic.Node{
Name: "testFile", Name: "testFile",
FileType: "file", Type: "file",
Content: restic.IDs{}, Content: restic.IDs{},
UID: uint32(os.Getuid()), UID: uint32(os.Getuid()),
GID: uint32(os.Getgid()), GID: uint32(os.Getgid()),
@ -84,7 +84,7 @@ var nodeTests = []restic.Node{
}, },
restic.Node{ restic.Node{
Name: "testSuidFile", Name: "testSuidFile",
FileType: "file", Type: "file",
Content: restic.IDs{}, Content: restic.IDs{},
UID: uint32(os.Getuid()), UID: uint32(os.Getuid()),
GID: uint32(os.Getgid()), GID: uint32(os.Getgid()),
@ -95,7 +95,7 @@ var nodeTests = []restic.Node{
}, },
restic.Node{ restic.Node{
Name: "testSuidFile2", Name: "testSuidFile2",
FileType: "file", Type: "file",
Content: restic.IDs{}, Content: restic.IDs{},
UID: uint32(os.Getuid()), UID: uint32(os.Getuid()),
GID: uint32(os.Getgid()), GID: uint32(os.Getgid()),
@ -106,7 +106,7 @@ var nodeTests = []restic.Node{
}, },
restic.Node{ restic.Node{
Name: "testSticky", Name: "testSticky",
FileType: "file", Type: "file",
Content: restic.IDs{}, Content: restic.IDs{},
UID: uint32(os.Getuid()), UID: uint32(os.Getuid()),
GID: uint32(os.Getgid()), GID: uint32(os.Getgid()),
@ -117,7 +117,7 @@ var nodeTests = []restic.Node{
}, },
restic.Node{ restic.Node{
Name: "testDir", Name: "testDir",
FileType: "dir", Type: "dir",
Subtree: nil, Subtree: nil,
UID: uint32(os.Getuid()), UID: uint32(os.Getuid()),
GID: uint32(os.Getgid()), GID: uint32(os.Getgid()),
@ -128,7 +128,7 @@ var nodeTests = []restic.Node{
}, },
restic.Node{ restic.Node{
Name: "testSymlink", Name: "testSymlink",
FileType: "symlink", Type: "symlink",
LinkTarget: "invalid", LinkTarget: "invalid",
UID: uint32(os.Getuid()), UID: uint32(os.Getuid()),
GID: uint32(os.Getgid()), GID: uint32(os.Getgid()),
@ -155,10 +155,10 @@ func TestNodeRestoreAt(t *testing.T) {
nodePath := filepath.Join(tempdir, test.Name) nodePath := filepath.Join(tempdir, test.Name)
OK(t, test.CreateAt(nodePath, nil)) OK(t, test.CreateAt(nodePath, nil))
if test.FileType == "symlink" && runtime.GOOS == "windows" { if test.Type == "symlink" && runtime.GOOS == "windows" {
continue continue
} }
if test.FileType == "dir" { if test.Type == "dir" {
OK(t, test.RestoreTimestamps(nodePath)) OK(t, test.RestoreTimestamps(nodePath))
} }
@ -169,25 +169,25 @@ func TestNodeRestoreAt(t *testing.T) {
OK(t, err) OK(t, err)
Assert(t, test.Name == n2.Name, Assert(t, test.Name == n2.Name,
"%v: name doesn't match (%v != %v)", test.FileType, test.Name, n2.Name) "%v: name doesn't match (%v != %v)", test.Type, test.Name, n2.Name)
Assert(t, test.FileType == n2.FileType, Assert(t, test.Type == n2.Type,
"%v: type doesn't match (%v != %v)", test.FileType, test.FileType, n2.FileType) "%v: type doesn't match (%v != %v)", test.Type, test.Type, n2.Type)
Assert(t, test.Size == n2.Size, Assert(t, test.Size == n2.Size,
"%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size) "%v: size doesn't match (%v != %v)", test.Size, test.Size, n2.Size)
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
Assert(t, test.UID == n2.UID, 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, Assert(t, test.GID == n2.GID,
"%v: GID doesn't match (%v != %v)", test.FileType, test.GID, n2.GID) "%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
if test.FileType != "symlink" { if test.Type != "symlink" {
Assert(t, test.Mode == n2.Mode, 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, "AccessTime", test.Type, test.AccessTime, n2.AccessTime)
AssertFsTimeEqual(t, "ModTime", test.FileType, test.ModTime, n2.ModTime) AssertFsTimeEqual(t, "ModTime", test.Type, test.ModTime, n2.ModTime)
} }
} }

View file

@ -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 { if node.Subtree == nil {
return errors.Errorf("Dir without subtree in tree %v", treeID.Str()) return errors.Errorf("Dir without subtree in tree %v", treeID.Str())
} }

View file

@ -109,7 +109,7 @@ func (fs fakeFileSystem) saveTree(seed int64, depth int) ID {
node := &Node{ node := &Node{
Name: fmt.Sprintf("dir-%v", treeSeed), Name: fmt.Sprintf("dir-%v", treeSeed),
FileType: "dir", Type: "dir",
Mode: 0755, Mode: 0755,
Subtree: &id, Subtree: &id,
} }
@ -123,7 +123,7 @@ func (fs fakeFileSystem) saveTree(seed int64, depth int) ID {
node := &Node{ node := &Node{
Name: fmt.Sprintf("file-%v", fileSeed), Name: fmt.Sprintf("file-%v", fileSeed),
FileType: "file", Type: "file",
Mode: 0644, Mode: 0644,
Size: uint64(fileSize), Size: uint64(fileSize),
} }

View file

@ -95,7 +95,7 @@ func (t Tree) Find(name string) (*Node, error) {
// Subtrees returns a slice of all subtree IDs of the tree. // Subtrees returns a slice of all subtree IDs of the tree.
func (t Tree) Subtrees() (trees IDs) { func (t Tree) Subtrees() (trees IDs) {
for _, node := range t.Nodes { for _, node := range t.Nodes {
if node.FileType == "dir" && node.Subtree != nil { if node.Type == "dir" && node.Subtree != nil {
trees = append(trees, *node.Subtree) trees = append(trees, *node.Subtree)
} }
} }

View file

@ -71,7 +71,7 @@ func (tw *TreeWalker) walk(path string, tree *Tree, done chan struct{}) {
// load all subtrees in parallel // load all subtrees in parallel
results := make([]<-chan loadTreeResult, len(tree.Nodes)) results := make([]<-chan loadTreeResult, len(tree.Nodes))
for i, node := range tree.Nodes { for i, node := range tree.Nodes {
if node.FileType == "dir" { if node.Type == "dir" {
resCh := make(chan loadTreeResult, 1) resCh := make(chan loadTreeResult, 1)
tw.ch <- loadTreeJob{ tw.ch <- loadTreeJob{
id: *node.Subtree, id: *node.Subtree,
@ -86,7 +86,7 @@ func (tw *TreeWalker) walk(path string, tree *Tree, done chan struct{}) {
p := filepath.Join(path, node.Name) p := filepath.Join(path, node.Name)
var job WalkTreeJob var job WalkTreeJob
if node.FileType == "dir" { if node.Type == "dir" {
if results[i] == nil { if results[i] == nil {
panic("result chan should not be nil") panic("result chan should not be nil")
} }