@@ -9,11 +9,12 @@ package ccprovider
9
9
import (
10
10
"archive/tar"
11
11
"bytes"
12
- "compress/gzip "
12
+ "fmt "
13
13
"io"
14
14
"io/ioutil"
15
15
"path/filepath"
16
- "strings"
16
+
17
+ "github.com/hyperledger/fabric/core/chaincode/platforms"
17
18
)
18
19
19
20
const (
@@ -47,49 +48,14 @@ func ExtractStatedbArtifactsForChaincode(ccname, ccversion string) (installed bo
47
48
// The state db artifacts are expected to contain state db specific artifacts such as index specification in the case of couchdb.
48
49
// This function is called during chaincode instantiate/upgrade (from above), and from install, so that statedb artifacts can be created.
49
50
func ExtractStatedbArtifactsFromCCPackage (ccpackage CCPackage ) (statedbArtifactsTar []byte , err error ) {
50
-
51
51
cds := ccpackage .GetDepSpec ()
52
- is := bytes .NewReader (cds .CodePackage )
53
- gr , err := gzip .NewReader (is )
52
+ pform , err := platforms .Find (cds .ChaincodeSpec .Type )
54
53
if err != nil {
55
- ccproviderLogger .Errorf ("Failure opening codepackage gzip stream: %s" , err )
56
- return nil , err
57
- }
58
- tr := tar .NewReader (gr )
59
- statedbTarBuffer := bytes .NewBuffer (nil )
60
- tw := tar .NewWriter (statedbTarBuffer )
61
-
62
- // For each file in the code package tar,
63
- // add it to the statedb artifact tar if it has "statedb" in the path
64
- for {
65
- header , err := tr .Next ()
66
- if err == io .EOF {
67
- // We only get here if there are no more entries to scan
68
- break
69
- }
70
-
71
- if err != nil {
72
- return nil , err
73
- }
74
- ccproviderLogger .Debugf ("header.Name = %s" , header .Name )
75
- if ! strings .HasPrefix (header .Name , ccPackageStatedbDir ) {
76
- continue
77
- }
78
- if err = tw .WriteHeader (header ); err != nil {
79
- ccproviderLogger .Error ("Error adding header to statedb tar:" , err , header .Name )
80
- return nil , err
81
- }
82
- if _ , err := io .Copy (tw , tr ); err != nil {
83
- ccproviderLogger .Error ("Error copying file to statedb tar:" , err , header .Name )
84
- return nil , err
85
- }
86
- ccproviderLogger .Debug ("Wrote file to statedb tar:" , header .Name )
87
- }
88
- if err = tw .Close (); err != nil {
89
- return nil , err
54
+ ccproviderLogger .Infof ("invalid deployment spec (bad platform type:%s)" , cds .ChaincodeSpec .Type )
55
+ return nil , fmt .Errorf ("invalid deployment spec" )
90
56
}
91
- ccproviderLogger . Debug ( "Created statedb artifact tar" )
92
- return statedbTarBuffer . Bytes (), nil
57
+ metaprov := pform . GetMetadataProvider ( cds )
58
+ return metaprov . GetMetadataAsTarEntries ()
93
59
}
94
60
95
61
// ExtractFileEntries extract file entries from the given `tarBytes`. A file entry is included in the
0 commit comments