type Ifchange struct {
tgt *Tgt
- meta string
+ meta [InodeLen + HashLen]byte
}
-func (ifchange *Ifchange) Inode() Inode {
- return Inode(ifchange.meta[:InodeLen])
+func (ifchange *Ifchange) Inode() *Inode {
+ inode := Inode(ifchange.meta[:InodeLen])
+ return &inode
}
func (ifchange *Ifchange) Hash() Hash {
}
_, err = io.Copy(w, bytes.NewBuffer(chunkWrite(bytes.Join([][]byte{
{DepTypeIfchange},
- []byte(inode),
+ inode[:],
[]byte(hsh),
[]byte(tgt.RelTo(cwd)),
}, nil))))
if len(chunk) < InodeLen+HashLen+1 {
return nil, "", errors.New("too short \"ifchange\" format")
}
- name := string(chunk[InodeLen+HashLen:])
- meta := string(chunk[:InodeLen+HashLen])
tgtH, _ := pathSplit(tgt.a)
- ifchange := &Ifchange{tgt: NewTgt(path.Join(tgtH, name)), meta: meta}
- cachedFound := false
+ name := string(chunk[InodeLen+HashLen:])
+ ifchange := &Ifchange{
+ tgt: NewTgt(path.Join(tgtH, name)),
+ meta: ([InodeLen + HashLen]byte)(chunk),
+ }
for _, cached := range IfchangeCache[ifchange.tgt.rel] {
if ifchange.meta == cached.meta {
- ifchange = cached
- cachedFound = true
- break
+ return cached, name, nil
}
}
- if IfchangeCache != nil && !cachedFound {
+ if IfchangeCache != nil {
IfchangeCache[ifchange.tgt.rel] = append(IfchangeCache[ifchange.tgt.rel], ifchange)
}
return ifchange, name, nil
if err != nil {
break
}
- var inode Inode
+ var inode *Inode
inode, _, err = inodeFromFileByFd(fd)
if err != nil {
fd.Close()
_, err = io.Copy(fdDepW, bytes.NewBuffer(
chunkWrite(bytes.Join([][]byte{
{DepTypeIfchange},
- []byte(inode),
+ inode[:],
[]byte(hsh),
[]byte(name),
}, nil))))
if err != nil {
break
}
- var inode Inode
+ var inode *Inode
inode, _, err = inodeFromFileByFd(fd)
if err != nil {
fd.Close()
_, err = io.Copy(fdDepW, bytes.NewBuffer(
chunkWrite(bytes.Join([][]byte{
{DepTypeIfchange},
- []byte(inode),
+ inode[:],
[]byte(hsh),
[]byte(name),
}, nil))))
package main
import (
+ "bytes"
"encoding/binary"
"os"
"strconv"
// It is big-endian 64-bit unsigned integers: size, inodeNum,
// ctime sec, ctime nsec, mtime sec, mtime nsec.
-type Inode string
+type Inode [InodeLen]byte
-func (our Inode) Equals(their Inode) bool {
- if our[:2*8] != their[:2*8] {
+func (our *Inode) Equals(their *Inode) bool {
+ if !bytes.Equal(our[:2*8], their[:2*8]) {
return false
}
switch InodeTrust {
case InodeTrustCtime:
- if our[2*8:4*8] != their[2*8:4*8] {
+ if !bytes.Equal(our[2*8:4*8], their[2*8:4*8]) {
return false
}
case InodeTrustMtime:
- if our[4*8:6*8] != their[4*8:6*8] {
+ if !bytes.Equal(our[4*8:6*8], their[4*8:6*8]) {
return false
}
}
return true
}
-func (inode Inode) RecfileFields() []recfile.Field {
+func (inode *Inode) RecfileFields() []recfile.Field {
return []recfile.Field{
{Name: "Size", Value: strconv.FormatUint(binary.BigEndian.Uint64(
[]byte(inode[0*8:1*8])), 10)},
}
}
-func inodeFromFileStat(fi os.FileInfo, stat unix.Stat_t) Inode {
+func inodeFromFileStat(fi os.FileInfo, stat unix.Stat_t) *Inode {
ctimeSec, ctimeNsec := stat.Ctim.Unix()
mtimeSec := fi.ModTime().Unix()
mtimeNsec := fi.ModTime().UnixNano()
- buf := make([]byte, InodeLen)
- binary.BigEndian.PutUint64(buf[0*8:1*8], uint64(fi.Size()))
- binary.BigEndian.PutUint64(buf[1*8:2*8], uint64(stat.Ino))
- binary.BigEndian.PutUint64(buf[2*8:3*8], uint64(ctimeSec))
- binary.BigEndian.PutUint64(buf[3*8:4*8], uint64(ctimeNsec))
- binary.BigEndian.PutUint64(buf[4*8:5*8], uint64(mtimeSec))
- binary.BigEndian.PutUint64(buf[5*8:6*8], uint64(mtimeNsec))
- return Inode(buf)
+ inode := new(Inode)
+ binary.BigEndian.PutUint64(inode[0*8:1*8], uint64(fi.Size()))
+ binary.BigEndian.PutUint64(inode[1*8:2*8], uint64(stat.Ino))
+ binary.BigEndian.PutUint64(inode[2*8:3*8], uint64(ctimeSec))
+ binary.BigEndian.PutUint64(inode[3*8:4*8], uint64(ctimeNsec))
+ binary.BigEndian.PutUint64(inode[4*8:5*8], uint64(mtimeSec))
+ binary.BigEndian.PutUint64(inode[5*8:6*8], uint64(mtimeNsec))
+ return inode
}
-func inodeFromFileByFd(fd *os.File) (inode Inode, isDir bool, err error) {
+func inodeFromFileByFd(fd *os.File) (inode *Inode, isDir bool, err error) {
fi, err := fd.Stat()
if err != nil {
return
return
}
-func inodeFromFileByPath(p string) (Inode, error) {
+func inodeFromFileByPath(p string) (*Inode, error) {
fi, err := os.Stat(p)
if err != nil {
- return "", err
+ return nil, err
}
var stat unix.Stat_t
err = unix.Stat(p, &stat)
if err != nil {
- return "", err
+ return nil, err
}
return inodeFromFileStat(fi, stat), nil
}
DepFixHashCache = make(map[string]Hash)
err = depFix(Cwd)
case CmdNameRedoInode:
- var inode Inode
+ var inode *Inode
for _, tgt := range tgts {
inode, err = inodeFromFileByPath(tgt.a)
if err != nil {
}
var typ byte
var chunk []byte
+ var inode Inode
for len(data) > 0 {
typ, chunk, data, _ = chunkRead(data)
switch typ {
}...)
case DepTypeIfchange:
name := string(chunk[InodeLen+HashLen:])
- meta := string(chunk[:InodeLen+HashLen])
+ meta := chunk[:InodeLen+HashLen]
fields := []recfile.Field{
{Name: "Type", Value: "ifchange"},
{Name: "Target", Value: name},
fields = append(fields, recfile.Field{
Name: "Hash", Value: Hash(meta[InodeLen:]).String(),
})
- fields = append(fields, Inode(meta[:InodeLen]).RecfileFields()...)
+ inode = Inode(meta[:][:InodeLen])
+ fields = append(fields, inode.RecfileFields()...)
err = recfileWrite(w, fields...)
case DepTypeIfchangeNonex:
err = recfileWrite(w, []recfile.Field{
package main
import (
+ "bytes"
"errors"
"fmt"
"io"
return ood, TgtError{tgt, ErrLine(err)}
}
- if inode[:8] != ifchange.Inode()[:8] {
+ if !bytes.Equal(inode[:8], ifchange.Inode()[:8]) {
tracef(CDebug, "ood: %s%s -> %s: size differs", indent, tgt, ifchange.tgt)
ood = true
OODCache[ifchange.tgt.rel] = ood
}
func isModified(dep *Dep, tgt *Tgt) (
- modified bool, ourInode Inode, hshPrev Hash, err error,
+ modified bool, ourInode *Inode, hshPrev Hash, err error,
) {
if dep == nil {
return
// Was $1 touched?
if inode, err := inodeFromFileByPath(tgt.a); err == nil {
- if inodePrev == "" {
+ if inodePrev == nil {
runErr.Err = Err1WasTouched
errs <- runErr
return