]> Cypherpunks.ru repositories - goredo.git/commitdiff
Store InodeNum
authorSergey Matveev <stargrave@stargrave.org>
Wed, 23 Feb 2022 09:04:19 +0000 (12:04 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 23 Feb 2022 09:32:33 +0000 (12:32 +0300)
dep.rec
doc/news.texi
doc/ood.texi
doc/state.texi
inode.go

diff --git a/dep.rec b/dep.rec
index 56c32cab8014b4567cf0d8018e58fe378acc3559..db28e9da83d8b28b9f3806b1609d6afc3a2905cf 100644 (file)
--- 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
index b1487f7741f373a90dd1cb99ab293005cc3ca7bb..6cdbe077851e1b2818a97be93faf8cf8b0967404 100644 (file)
@@ -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}
index e4d55552a7bd6056ede206b26b305ff5a350cc39..3250f2e321b423cca6275b6257a86e0b52544019 100644 (file)
@@ -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
index db32628f5c51e4e8a19a178bbdf041c410c7f62e..5b0e05c221ac148a3d5f4381647b4f4c78b19eee 100644 (file)
@@ -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
index afb323cb15aa6deb3a89c231c3ea9247ebd17a34..82b61984ab0f37e05c14dd0e2034410ec0dfe4d2 100644 (file)
--- 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