2 goredo -- djb's redo implementation on pure Go
3 Copyright (C) 2020-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Inode metainformation
27 "go.cypherpunks.ru/recfile"
28 "golang.org/x/sys/unix"
31 const EnvInodeNoTrust = "REDO_INODE_NO_TRUST"
33 var InodeTrust bool = false
41 func (our *Inode) Equals(their *Inode) bool {
42 return (our.Size == their.Size) &&
43 (our.CtimeSec == their.CtimeSec) &&
44 (our.CtimeNsec == their.CtimeNsec)
47 func (inode *Inode) RecfileFields() []recfile.Field {
48 return []recfile.Field{
49 {Name: "Size", Value: strconv.FormatInt(inode.Size, 10)},
50 {Name: "CtimeSec", Value: strconv.FormatInt(inode.CtimeSec, 10)},
51 {Name: "CtimeNsec", Value: strconv.FormatInt(inode.CtimeNsec, 10)},
55 func inodeFromFile(fd *os.File) (*Inode, error) {
62 err = unix.Fstat(int(fd.Fd()), &stat)
66 sec, nsec := stat.Ctim.Unix()
67 return &Inode{Size: fi.Size(), CtimeSec: sec, CtimeNsec: nsec}, nil
70 func inodeFromRec(m map[string]string) (*Inode, error) {
72 ctimeSec := m["CtimeSec"]
73 ctimeNsec := m["CtimeNsec"]
75 return nil, errors.New("Size is missing")
78 return nil, errors.New("CtimeSec is missing")
81 return nil, errors.New("CtimeNsec is missing")
85 inode.Size, err = strconv.ParseInt(size, 10, 64)
89 inode.CtimeSec, err = strconv.ParseInt(ctimeSec, 10, 64)
93 inode.CtimeNsec, err = strconv.ParseInt(ctimeNsec, 10, 64)