2 goredo -- 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"
37 func (our *Inode) Equals(their *Inode) bool {
38 return (our.Size == their.Size) &&
39 (our.CtimeSec == their.CtimeSec) &&
40 (our.CtimeNsec == their.CtimeNsec)
43 func (inode *Inode) RecfileFields() []recfile.Field {
44 return []recfile.Field{
45 {Name: "Size", Value: strconv.FormatInt(inode.Size, 10)},
46 {Name: "CtimeSec", Value: strconv.FormatInt(inode.CtimeSec, 10)},
47 {Name: "CtimeNsec", Value: strconv.FormatInt(inode.CtimeNsec, 10)},
51 func inodeFromFile(fd *os.File) (*Inode, error) {
58 err = unix.Fstat(int(fd.Fd()), &stat)
62 sec, nsec := stat.Ctim.Unix()
63 return &Inode{Size: fi.Size(), CtimeSec: sec, CtimeNsec: nsec}, nil
66 func inodeFromRec(m map[string]string) (*Inode, error) {
68 ctimeSec := m["CtimeSec"]
69 ctimeNsec := m["CtimeNsec"]
71 return nil, errors.New("Size is missing")
74 return nil, errors.New("CtimeSec is missing")
77 return nil, errors.New("CtimeNsec is missing")
81 inode.Size, err = strconv.ParseInt(size, 10, 64)
85 inode.CtimeSec, err = strconv.ParseInt(ctimeSec, 10, 64)
89 inode.CtimeNsec, err = strconv.ParseInt(ctimeNsec, 10, 64)