add proper constants for node type

This commit is contained in:
Michael Eischer
2024-08-31 18:20:01 +02:00
parent 3b438e5c7c
commit ca1e5e10b6
42 changed files with 206 additions and 206 deletions
+2 -17
View File
@@ -67,7 +67,7 @@ func sendNodes(ctx context.Context, repo restic.BlobLoader, root *restic.Node, c
}
// If this is no directory we are finished
if !IsDir(root) {
if root.Type != restic.NodeTypeDir {
return nil
}
@@ -81,7 +81,7 @@ func sendNodes(ctx context.Context, repo restic.BlobLoader, root *restic.Node, c
node.Path = path.Join(root.Path, nodepath)
if !IsFile(node) && !IsDir(node) && !IsLink(node) {
if node.Type != restic.NodeTypeFile && node.Type != restic.NodeTypeDir && node.Type != restic.NodeTypeSymlink {
return nil
}
@@ -176,18 +176,3 @@ func (d *Dumper) writeNode(ctx context.Context, w io.Writer, node *restic.Node)
return wg.Wait()
}
// IsDir checks if the given node is a directory.
func IsDir(node *restic.Node) bool {
return node.Type == "dir"
}
// IsLink checks if the given node as a link.
func IsLink(node *restic.Node) bool {
return node.Type == "symlink"
}
// IsFile checks if the given node is a file.
func IsFile(node *restic.Node) bool {
return node.Type == "file"
}
+3 -3
View File
@@ -79,16 +79,16 @@ func (d *Dumper) dumpNodeTar(ctx context.Context, node *restic.Node, w *tar.Writ
header.Mode |= cISVTX
}
if IsFile(node) {
if node.Type == restic.NodeTypeFile {
header.Typeflag = tar.TypeReg
}
if IsLink(node) {
if node.Type == restic.NodeTypeSymlink {
header.Typeflag = tar.TypeSymlink
header.Linkname = node.LinkTarget
}
if IsDir(node) {
if node.Type == restic.NodeTypeDir {
header.Typeflag = tar.TypeDir
header.Name += "/"
}
+1 -1
View File
@@ -124,7 +124,7 @@ func TestFieldTooLong(t *testing.T) {
node := restic.Node{
Name: "file_with_xattr",
Path: "/file_with_xattr",
Type: "file",
Type: restic.NodeTypeFile,
Mode: 0644,
ExtendedAttributes: []restic.ExtendedAttribute{
{
+2 -2
View File
@@ -40,7 +40,7 @@ func (d *Dumper) dumpNodeZip(ctx context.Context, node *restic.Node, zw *zip.Wri
}
header.SetMode(node.Mode)
if IsDir(node) {
if node.Type == restic.NodeTypeDir {
header.Name += "/"
}
@@ -49,7 +49,7 @@ func (d *Dumper) dumpNodeZip(ctx context.Context, node *restic.Node, zw *zip.Wri
return errors.Wrap(err, "ZipHeader")
}
if IsLink(node) {
if node.Type == restic.NodeTypeSymlink {
if _, err = w.Write([]byte(node.LinkTarget)); err != nil {
return errors.Wrap(err, "Write")
}