-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
67 lines (53 loc) · 1.24 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"bytes"
"io"
"os"
"github.com/smtc/rsync"
)
func isCharDevice(filemode os.FileMode) bool {
return filemode&os.ModeCharDevice == os.ModeCharDevice
}
func isDevice(filemode os.FileMode) bool {
return filemode&os.ModeDevice == os.ModeDevice
}
func isDir(filemode os.FileMode) bool {
return filemode&os.ModeDir == os.ModeDir
}
func isNamedPipe(filemode os.FileMode) bool {
return filemode&os.ModeNamedPipe == os.ModeNamedPipe
}
func isSocket(filemode os.FileMode) bool {
return filemode&os.ModeSocket == os.ModeSocket
}
func isSymlink(filemode os.FileMode) bool {
return filemode&os.ModeSymlink == os.ModeSymlink
}
/*
func major(rdev uint64) uint64 {
return (rdev >> 8) & 0xff
}
func minor(rdev uint64) uint64 {
return (rdev & 0xff) | ((rdev & 0xffff0000) >> 8)
}
*/
func signatureFromReader(dstBuf *bytes.Buffer, fd io.ReadSeeker, len int64) error {
// Save the current offset
savedOffset, err := fd.Seek(0, 1)
if err != nil {
return err
}
// Create signature of the source file
err = rsync.GenSign(fd, len, 2048, dstBuf)
if err != nil {
return err
}
// Return cursor to the original offset
_, err = fd.Seek(savedOffset, 0)
return err
}
func zero(b []byte) {
for i := 0; i < len(b); i++ {
b[i] = 0x00
}
}