github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/extractor/dir/metadata.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 dir
    10  
    11  import (
    12  	"github.com/vchain-us/vcn/pkg/api"
    13  	"github.com/vchain-us/vcn/pkg/bundle"
    14  )
    15  
    16  const (
    17  	manifestFile = ".vcn.manifest.json"
    18  )
    19  
    20  // Metadata extracts dir related info from a.
    21  func Metadata(a api.Artifact) (manifest *bundle.Manifest, path string) {
    22  	if a.Kind != Scheme {
    23  		return
    24  	}
    25  
    26  	// Get manifest
    27  	m := a.Metadata[ManifestKey]
    28  	if m != nil {
    29  		if mm, ok := m.(*bundle.Manifest); ok {
    30  			manifest = mm
    31  		}
    32  	}
    33  
    34  	// Get path
    35  	p := a.Metadata[PathKey]
    36  	if p != nil {
    37  		if pp, ok := p.(string); ok {
    38  			path = pp
    39  		}
    40  	}
    41  
    42  	return
    43  }
    44  
    45  // RemoveMetadata removes dir related info from a.
    46  func RemoveMetadata(a *api.Artifact) {
    47  	if a == nil || a.Kind != Scheme {
    48  		return
    49  	}
    50  	delete(a.Metadata, ManifestKey)
    51  	delete(a.Metadata, PathKey)
    52  }