Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | add timestamp to file manifest |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ea88da5a2317bc39820c88a059e6235a |
User & Date: | dnc 2019-05-24 16:15:52 |
Context
2019-05-27
| ||
13:33 | add role to file manifest testimony signed by author, or auditor, etc. check-in: a330762664 user: dnc tags: trunk | |
2019-05-24
| ||
16:15 | add timestamp to file manifest check-in: ea88da5a23 user: dnc tags: trunk | |
2019-05-23
| ||
16:53 | go mod compatibility check-in: ee9d5b8297 user: dnc tags: trunk | |
Changes
Changes to cmd/hancock/manifest.go.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 .. 48 49 50 51 52 53 54 55 56 57 58 59 60 61 .. 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
// expected by `hancock-sign`. package main import ( "fmt" "os" "path/filepath" "github.com/pkg/errors" "src.d10.dev/command" "src.d10.dev/hancock/model" ) func init() { ................................................................................ return err } if len(command.OperationFlagSet.Args()) == 0 { return errors.New("Expected <file or directory> parameter.") } noRecurse := errors.New("no recurse") // prepare for filepath.Walk for _, arg := range command.OperationFlagSet.Args() { err = filepath.Walk(arg, func(filepath string, info os.FileInfo, err error) error { if err != nil { command.Error(err) // log error return nil // continue walk } ................................................................................ } manifest, err := model.NewFileManifest(filepath) if err != nil { command.Error(err) // log error return nil // continue walk } // encoded manifest to stdout fmt.Println(mustEncode(manifest)) return nil // continue walk }) if err == noRecurse { |
> > > > |
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 .. 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 .. 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
// expected by `hancock-sign`. package main import ( "fmt" "os" "path/filepath" "time" "github.com/pkg/errors" "src.d10.dev/command" "src.d10.dev/hancock/model" ) func init() { ................................................................................ return err } if len(command.OperationFlagSet.Args()) == 0 { return errors.New("Expected <file or directory> parameter.") } noRecurse := errors.New("no recurse") // prepare for filepath.Walk timestamp := time.Now().Unix() for _, arg := range command.OperationFlagSet.Args() { err = filepath.Walk(arg, func(filepath string, info os.FileInfo, err error) error { if err != nil { command.Error(err) // log error return nil // continue walk } ................................................................................ } manifest, err := model.NewFileManifest(filepath) if err != nil { command.Error(err) // log error return nil // continue walk } manifest.Time = timestamp // give all manifests the same timestamp // encoded manifest to stdout fmt.Println(mustEncode(manifest)) return nil // continue walk }) if err == noRecurse { |
Changes to cmd/hancock/verify.go.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
// path check is disabled because an identical file may appear in more than one place. TODO(dnc) fix this, or enable strict mode //if manifest.Path != filepath { // command.Infof("path mismatch (local: %q, testimony: %q)", filepath, manifest.Path) // continue //} command.V(1).Infof("%q authenticated by %q", filepath, authority.name) verified = true // TODO(dnc): consider a count of weighted authorities, rather than simple verified or not default: command.V(2).Info(filepath, u.String(), resp.Status) continue } // end ipfs status default: command.V(2).Info(filepath, u.String(), resp.Status) |
> > > > > > | > > |
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
// path check is disabled because an identical file may appear in more than one place. TODO(dnc) fix this, or enable strict mode //if manifest.Path != filepath { // command.Infof("path mismatch (local: %q, testimony: %q)", filepath, manifest.Path) // continue //} if command.V(1) { t := time.Unix(manifest.Time, 0) // TODO(dnc) format time in friendly "days ago" syntax if filepath != manifest.Path { command.Infof("%q authenticated by %q as %q on %s", filepath, authority.name, manifest.Path, t.Format(time.RFC850)) } else { command.Infof("%q authenticated by %q on %s", filepath, authority.name, t.Format(time.RFC850)) } } verified = true // TODO(dnc): consider a count of weighted authorities, rather than simple verified or not default: command.V(2).Info(filepath, u.String(), resp.Status) continue } // end ipfs status default: command.V(2).Info(filepath, u.String(), resp.Status) |
Changes to model/manifest.go.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package model import ( "encoding/json" "io" "os" ) type FileManifest struct { Path string `json:"path,omitempty"` CID CID `json:"cid"` } func NewFileManifest(path string) (*FileManifest, error) { f, err := os.Open(path) if err != nil { return nil, err ................................................................................ cid := NewSha256CID(nil) _, err = io.Copy(cid, f) if err != nil { return nil, err } return &FileManifest{Path: path, CID: cid.Encode()}, nil } func mustJSON(v interface{}) string { enc, err := json.MarshalIndent(v, "", "\t") if err != nil { panic(err) } return string(enc) } |
>
>
|
>
>
>
>
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package model import ( "encoding/json" "io" "os" "time" ) type FileManifest struct { Path string `json:"path,omitempty"` Time int64 `json:"timestamp"` CID CID `json:"cid"` } func NewFileManifest(path string) (*FileManifest, error) { f, err := os.Open(path) if err != nil { return nil, err ................................................................................ cid := NewSha256CID(nil) _, err = io.Copy(cid, f) if err != nil { return nil, err } return &FileManifest{ Path: path, Time: time.Now().Unix(), CID: cid.Encode(), }, nil } func mustJSON(v interface{}) string { enc, err := json.MarshalIndent(v, "", "\t") if err != nil { panic(err) } return string(enc) } |