From: Sergey Matveev Date: Wed, 23 Feb 2022 09:04:19 +0000 (+0300) Subject: Store InodeNum X-Git-Tag: v1.23.0~1 X-Git-Url: http://www.git.cypherpunks.ru/?p=goredo.git;a=commitdiff_plain;h=c1b88a9301143b14fc3ef2a9b6bd9ac2ecf070f3 Store InodeNum --- diff --git a/dep.rec b/dep.rec index 56c32ca..db28e9d 100644 --- a/dep.rec +++ b/dep.rec @@ -6,10 +6,11 @@ %rec: Dependency %doc: Dependency information %mandatory: Type -%allowed: Target Size CtimeSec CtimeNsec MtimeSec MtimeNsec Hash -%unique: Type Target Size CtimeSec CtimeNsec MtimeSec MtimeNsec Hash +%allowed: Target Size InodeNum CtimeSec CtimeNsec MtimeSec MtimeNsec Hash +%unique: Type Target Size InodeNum CtimeSec CtimeNsec MtimeSec MtimeNsec Hash %type: Type enum ifcreate ifchange always stamp %type: Size int +%type: InodeNum int %type: CtimeSec int %type: CtimeNsec int %type: MtimeSec int diff --git a/doc/news.texi b/doc/news.texi index b1487f7..6cdbe07 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -9,6 +9,9 @@ @command{redo-ifchange}'s @option{-f} option forces each target rebuilding. Comparing to @command{redo}, it will parallelize the process. +@item + Inode's number is also stored as dependency information, just to + prevent possible @code{ctime} collision of two files. @end itemize @anchor{Release 1_22_0} diff --git a/doc/ood.texi b/doc/ood.texi index e4d5555..3250f2e 100644 --- a/doc/ood.texi +++ b/doc/ood.texi @@ -13,8 +13,8 @@ collision-resistant hash function of enough length. @command{goredo} uses @url{https://github.com/BLAKE3-team/BLAKE3, BLAKE3} with 256-bit output for that purpose. -Also it stores file's size. Obviously if size differs, then file's -content too and there is no need to read and hash it. +Also it stores file's size and its inode number. Obviously if size +differs, then file's content too and there is no need to read and hash it. @vindex REDO_INODE_TRUST But still it could be relatively expensive. So there are additional diff --git a/doc/state.texi b/doc/state.texi index db32628..5b0e05c 100644 --- a/doc/state.texi +++ b/doc/state.texi @@ -18,8 +18,11 @@ Target: foo.o.do Type: ifchange Target: default.o.do Size: 123 +InodeNum: 2345 CtimeSec: 1605721341 CtimeNsec: 253305000 +MtimeSec: 1645606823 +MtimeNsec: 369936700 Hash: f4929732f96f11e6d4ebe94536b5edef426d00ed0146853e37a87f4295e18eda Type: always diff --git a/inode.go b/inode.go index afb323c..82b6198 100644 --- a/inode.go +++ b/inode.go @@ -43,6 +43,7 @@ var InodeTrust InodeTrustType type Inode struct { Size int64 + InodeNum uint64 CtimeSec int64 CtimeNsec int64 MtimeSec int64 @@ -53,6 +54,9 @@ func (our *Inode) Equals(their *Inode) bool { if our.Size != their.Size { return false } + if our.InodeNum != their.InodeNum { + return false + } switch InodeTrust { case InodeTrustCtime: if our.CtimeSec != their.CtimeSec || our.CtimeNsec != their.CtimeNsec { @@ -72,6 +76,7 @@ func (our *Inode) Equals(their *Inode) bool { func (inode *Inode) RecfileFields() []recfile.Field { return []recfile.Field{ {Name: "Size", Value: strconv.FormatInt(inode.Size, 10)}, + {Name: "InodeNum", Value: strconv.FormatUint(inode.InodeNum, 10)}, {Name: "CtimeSec", Value: strconv.FormatInt(inode.CtimeSec, 10)}, {Name: "CtimeNsec", Value: strconv.FormatInt(inode.CtimeNsec, 10)}, {Name: "MtimeSec", Value: strconv.FormatInt(inode.MtimeSec, 10)}, @@ -95,6 +100,7 @@ func inodeFromFile(fd *os.File) (*Inode, error) { mtimeNsec := fi.ModTime().UnixNano() return &Inode{ Size: fi.Size(), + InodeNum: uint64(stat.Ino), CtimeSec: ctimeSec, CtimeNsec: ctimeNsec, MtimeSec: mtimeSec, MtimeNsec: mtimeNsec, }, nil @@ -102,6 +108,7 @@ func inodeFromFile(fd *os.File) (*Inode, error) { func inodeFromRec(m map[string]string) (*Inode, error) { size := m["Size"] + inodeNum := m["InodeNum"] ctimeSec := m["CtimeSec"] ctimeNsec := m["CtimeNsec"] mtimeSec := m["MtimeSec"] @@ -121,6 +128,12 @@ func inodeFromRec(m map[string]string) (*Inode, error) { if err != nil { return nil, err } + if inodeNum != "" { + inode.InodeNum, err = strconv.ParseUint(inodeNum, 10, 64) + if err != nil { + return nil, err + } + } inode.CtimeSec, err = strconv.ParseInt(ctimeSec, 10, 64) if err != nil { return nil, err