github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/sign/hook.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package sign 10 11 import ( 12 "path/filepath" 13 14 "github.com/vchain-us/vcn/pkg/store" 15 16 "github.com/vchain-us/vcn/pkg/api" 17 "github.com/vchain-us/vcn/pkg/bundle" 18 "github.com/vchain-us/vcn/pkg/extractor/dir" 19 ) 20 21 type hook struct { 22 a api.Artifact 23 } 24 25 func newHook(a *api.Artifact) *hook { 26 if a != nil { 27 h := hook{ 28 a: a.Copy(), 29 } 30 dir.RemoveMetadata(a) 31 return &h 32 } 33 return nil 34 } 35 36 func (h *hook) finalize(v *api.BlockchainVerification, readOnly bool) error { 37 if h != nil && !v.Unknown() { 38 manifest, path := dir.Metadata(h.a) 39 if manifest != nil && path != "" { 40 // manifest is optional, we can ignore errors 41 store.SaveManifest(h.a.Kind, path, *manifest) 42 if !readOnly { 43 bundle.WriteManifest(*manifest, filepath.Join(path, bundle.ManifestFilename)) 44 } 45 } 46 } 47 return nil 48 } 49 50 func (h *hook) finalizeWithoutVerification(readOnly bool) error { 51 if h != nil { 52 manifest, path := dir.Metadata(h.a) 53 if manifest != nil && path != "" { 54 // manifest is optional, we can ignore errors 55 store.SaveManifest(h.a.Kind, path, *manifest) 56 if !readOnly { 57 bundle.WriteManifest(*manifest, filepath.Join(path, bundle.ManifestFilename)) 58 } 59 } 60 } 61 return nil 62 }