Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #119 from bstasyszyn/118
Browse files Browse the repository at this point in the history
fix: ListInstalledChaincodesLegacy uses wrong directory
  • Loading branch information
bstasyszyn authored Oct 17, 2019
2 parents 5941d21 + 3301698 commit dbb9e53
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 5 deletions.
64 changes: 64 additions & 0 deletions core/chaincode/persistence/mock/legacy_package_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion core/chaincode/persistence/package_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type StorePackageProvider interface {
// LegacyPackageProvider is the interface needed to retrieve
// the code package from a ChaincodeDeploymentSpec
type LegacyPackageProvider interface {
GetChaincodeInstallPath() string
GetChaincodeCodePackage(name, version string) (codePackage []byte, err error)
ListInstalledChaincodes(dir string, de ccprovider.DirEnumerator, ce ccprovider.ChaincodeExtractor) ([]chaincode.InstalledChaincode, error)
}
Expand Down Expand Up @@ -99,7 +100,7 @@ func (p *PackageProvider) getCodePackageFromLegacyPP(name, version string) ([]by
// ListInstalledChaincodesLegacy returns metadata (name, version, and ID) for
// each chaincode installed on a peer with the legacy lifecycle
func (p *PackageProvider) ListInstalledChaincodesLegacy() ([]chaincode.InstalledChaincode, error) {
installedChaincodesLegacy, err := p.LegacyPP.ListInstalledChaincodes(p.Store.GetChaincodeInstallPath(), ioutil.ReadDir, ccprovider.LoadPackage)
installedChaincodesLegacy, err := p.LegacyPP.ListInstalledChaincodes(p.LegacyPP.GetChaincodeInstallPath(), ioutil.ReadDir, ccprovider.LoadPackage)
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions core/common/ccprovider/ccprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func (*CCInfoFSImpl) GetChaincodeFromPath(ccname string, ccversion string, path
return cccdspack, nil
}

// GetChaincodeInstallPath returns the path to the installed chaincodes
func (*CCInfoFSImpl) GetChaincodeInstallPath() string {
return chaincodeInstallPath
}

// PutChaincodeIntoFS is a wrapper for putting raw ChaincodeDeploymentSpec
//using CDSPackage. This is only used in UTs
func (*CCInfoFSImpl) PutChaincode(depSpec *pb.ChaincodeDeploymentSpec) (CCPackage, error) {
Expand Down
9 changes: 9 additions & 0 deletions core/common/ccprovider/ccprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ func TestChaincodeData(t *testing.T) {
assert.Equal(t, po, []byte("Policy"))
}

func TestGetChaincodeInstallPath(t *testing.T) {
c := &ccprovider.CCInfoFSImpl{}
installPath := c.GetChaincodeInstallPath()
defer ccprovider.SetChaincodesPath(installPath)

ccprovider.SetChaincodesPath("blahblah")
assert.Equal(t, "blahblah", c.GetChaincodeInstallPath())
}

func setupDirectoryStructure(t *testing.T) (string, map[string][]byte) {
files := []string{
"example02.1.0", // Version contains the delimiter '.' is a valid case
Expand Down
8 changes: 4 additions & 4 deletions internal/peer/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func serve(args []string) error {
Parser: ccPackageParser,
}

// Configure CC package storage
lsccInstallPath := filepath.Join(coreconfig.GetPath("peer.fileSystemPath"), "chaincodes")
ccprovider.SetChaincodesPath(lsccInstallPath)

// legacyMetadataManager collects metadata information from the legacy
// lifecycle (lscc). This is expected to disappear with FAB-15061.
legacyMetadataManager, err := cclifecycle.NewMetadataManager(
Expand Down Expand Up @@ -270,10 +274,6 @@ func serve(args []string) error {
},
)

// Configure CC package storage
lsccInstallPath := filepath.Join(coreconfig.GetPath("peer.fileSystemPath"), "chaincodes")
ccprovider.SetChaincodesPath(lsccInstallPath)

if err := lifecycleCache.InitializeLocalChaincodes(); err != nil {
return errors.WithMessage(err, "could not initialize local chaincodes")
}
Expand Down

0 comments on commit dbb9e53

Please sign in to comment.