github.com/mckael/restic@v0.8.3/cmd/restic/integration_helpers_unix_test.go (about)

     1  //+build !windows
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"io/ioutil"
     8  	"os"
     9  	"path/filepath"
    10  	"syscall"
    11  )
    12  
    13  func (e *dirEntry) equals(other *dirEntry) bool {
    14  	if e.path != other.path {
    15  		fmt.Fprintf(os.Stderr, "%v: path does not match (%v != %v)\n", e.path, e.path, other.path)
    16  		return false
    17  	}
    18  
    19  	if e.fi.Mode() != other.fi.Mode() {
    20  		fmt.Fprintf(os.Stderr, "%v: mode does not match (%v != %v)\n", e.path, e.fi.Mode(), other.fi.Mode())
    21  		return false
    22  	}
    23  
    24  	if !sameModTime(e.fi, other.fi) {
    25  		fmt.Fprintf(os.Stderr, "%v: ModTime does not match (%v != %v)\n", e.path, e.fi.ModTime(), other.fi.ModTime())
    26  		return false
    27  	}
    28  
    29  	stat, _ := e.fi.Sys().(*syscall.Stat_t)
    30  	stat2, _ := other.fi.Sys().(*syscall.Stat_t)
    31  
    32  	if stat.Uid != stat2.Uid {
    33  		fmt.Fprintf(os.Stderr, "%v: UID does not match (%v != %v)\n", e.path, stat.Uid, stat2.Uid)
    34  		return false
    35  	}
    36  
    37  	if stat.Gid != stat2.Gid {
    38  		fmt.Fprintf(os.Stderr, "%v: GID does not match (%v != %v)\n", e.path, stat.Gid, stat2.Gid)
    39  		return false
    40  	}
    41  
    42  	if stat.Nlink != stat2.Nlink {
    43  		fmt.Fprintf(os.Stderr, "%v: Number of links do not match (%v != %v)\n", e.path, stat.Nlink, stat2.Nlink)
    44  		return false
    45  	}
    46  
    47  	return true
    48  }
    49  
    50  func nlink(info os.FileInfo) uint64 {
    51  	stat, _ := info.Sys().(*syscall.Stat_t)
    52  	return uint64(stat.Nlink)
    53  }
    54  
    55  func createFileSetPerHardlink(dir string) map[uint64][]string {
    56  	var stat syscall.Stat_t
    57  	linkTests := make(map[uint64][]string)
    58  	files, err := ioutil.ReadDir(dir)
    59  	if err != nil {
    60  		return nil
    61  	}
    62  	for _, f := range files {
    63  
    64  		if err := syscall.Stat(filepath.Join(dir, f.Name()), &stat); err != nil {
    65  			return nil
    66  		}
    67  		linkTests[uint64(stat.Ino)] = append(linkTests[uint64(stat.Ino)], f.Name())
    68  	}
    69  	return linkTests
    70  }