Skip to content

Commit 24687d0

Browse files
committed
integrated cidx into pidx module, fixed panic
1 parent 1066343 commit 24687d0

File tree

7 files changed

+107
-478
lines changed

7 files changed

+107
-478
lines changed

cmd/installer/pack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (p *PackType) purge() (bool, error) {
345345
return false, err
346346
}
347347

348-
cTag := xml.CacheTag{Vendor: p.Vendor, Name: p.Name, Version: p.Version}
348+
cTag := xml.PdscTag{Vendor: p.Vendor, Name: p.Name, Version: p.Version}
349349
if err = Installation.PublicCacheIndexXML.RemovePdsc(cTag); err == nil {
350350
webFile := Installation.WebDir + "/" + p.VName() + utils.PdscExtension
351351
files = append(files, webFile) // also add pdsc file in .Web

cmd/installer/root.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func InitializeCache() error {
576576
return errs.ErrUnknownBehavior
577577
}
578578
releaseTag := pdscXML.FindReleaseTagByVersion("")
579-
cacheTag := xml.CacheTag{
579+
cacheTag := xml.PdscTag{
580580
Vendor: packInfo.Vendor,
581581
Name: packInfo.Pack,
582582
Version: releaseTag.Version,
@@ -591,7 +591,7 @@ func InitializeCache() error {
591591
cacheTag.URL = releaseTag.URL[:i+1]
592592
}
593593
}
594-
_ = Installation.PublicCacheIndexXML.AddPdsc(cacheTag)
594+
_ = Installation.PublicCacheIndexXML.AddReplacePdsc(cacheTag)
595595
}
596596
return nil
597597
}
@@ -709,7 +709,7 @@ func DownloadPDSCFiles(skipInstalledPdscFiles bool, concurrency int, timeout int
709709
//
710710
// Returns:
711711
// - error: An error if any operation fails, otherwise nil.
712-
func UpdateInstalledPDSCFiles(pidxXML *xml.PidxXML, cidxXML *xml.CidxXML, updatePrivatePdsc, showInfo bool, concurrency int, timeout int) error {
712+
func UpdateInstalledPDSCFiles(pidxXML, cidxXML *xml.PidxXML, updatePrivatePdsc, showInfo bool, concurrency int, timeout int) error {
713713
ctx := context.TODO()
714714
concurrency = CheckConcurrency(concurrency)
715715
sem := semaphore.NewWeighted(int64(concurrency))
@@ -1005,7 +1005,7 @@ func UpdatePublicIndex(indexPath string, sparse, downloadPdsc, downloadRemaining
10051005
}
10061006
}
10071007

1008-
cidxXML := xml.NewCidxXML(Installation.PublicCacheIndex)
1008+
cidxXML := xml.NewPidxXML(Installation.PublicCacheIndex, true)
10091009
if err := cidxXML.Read(); err != nil { // public cache index XML
10101010
if err = InitializeCache(); err != nil {
10111011
return err
@@ -1604,11 +1604,11 @@ func SetPackRoot(packRoot string, create bool) error {
16041604
WebDir: filepath.Join(packRoot, ".Web"),
16051605
PackIdx: filepath.Join(packRoot, "pack.idx"),
16061606
}
1607-
Installation.LocalPidx = xml.NewPidxXML(filepath.Join(Installation.LocalDir, "local_repository.pidx"))
1607+
Installation.LocalPidx = xml.NewPidxXML(filepath.Join(Installation.LocalDir, "local_repository.pidx"), false)
16081608
Installation.PublicIndex = filepath.Join(Installation.WebDir, PublicIndexName)
16091609
Installation.PublicCacheIndex = filepath.Join(Installation.WebDir, PublicCacheIndex)
1610-
Installation.PublicIndexXML = xml.NewPidxXML(Installation.PublicIndex)
1611-
Installation.PublicCacheIndexXML = xml.NewCidxXML(Installation.PublicCacheIndex)
1610+
Installation.PublicIndexXML = xml.NewPidxXML(Installation.PublicIndex, false)
1611+
Installation.PublicCacheIndexXML = xml.NewPidxXML(Installation.PublicCacheIndex, true)
16121612

16131613
missingDirs := []string{}
16141614
for _, dir := range []string{packRoot, Installation.DownloadDir, Installation.LocalDir, Installation.WebDir} {
@@ -1698,8 +1698,8 @@ type PacksInstallationType struct {
16981698
// PublicIndexXML stores a xml.PidxXML reference for PackRoot/WebDir/index.pidx
16991699
PublicIndexXML *xml.PidxXML
17001700

1701-
// PublicCacheIndexXML stores a xml.CidxXML reference for PackRoot/WebDir/cache.idx
1702-
PublicCacheIndexXML *xml.CidxXML
1701+
// PublicCacheIndexXML stores a xml.PidxXML reference for PackRoot/WebDir/cache.idx
1702+
PublicCacheIndexXML *xml.PidxXML
17031703

17041704
// LocalPidx is a reference to "local_repository.pidx" that contains a flat
17051705
// list of PDSC tags representing all packs installed via PDSC files.
@@ -1713,6 +1713,8 @@ type PacksInstallationType struct {
17131713
PackIdx string
17141714

17151715
ReadOnly bool
1716+
1717+
lock sync.Mutex
17161718
}
17171719

17181720
// updateCfg represents the content of "update.cfg" file.
@@ -2119,7 +2121,7 @@ func (p *PacksInstallationType) downloadPdscFile(pdscTag xml.PdscTag, skipInstal
21192121
return errs.ErrUnknownBehavior
21202122
}
21212123
releaseTag := pdscXML.FindReleaseTagByVersion("")
2122-
cacheTag := xml.CacheTag{
2124+
cacheTag := xml.PdscTag{
21232125
Vendor: pdscTag.Vendor,
21242126
Name: pdscTag.Name,
21252127
Version: releaseTag.Version,
@@ -2134,7 +2136,10 @@ func (p *PacksInstallationType) downloadPdscFile(pdscTag xml.PdscTag, skipInstal
21342136
cacheTag.URL = releaseTag.URL[:i+1]
21352137
}
21362138
}
2137-
_ = p.PublicCacheIndexXML.AddPdsc(cacheTag)
2139+
2140+
p.lock.Lock()
2141+
defer p.lock.Unlock()
2142+
_ = p.PublicCacheIndexXML.AddReplacePdsc(cacheTag)
21382143
_ = p.PublicCacheIndexXML.Write()
21392144

21402145
return err

cmd/installer/root_pdsc_add_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestAddPdsc(t *testing.T) {
3838
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
3939
installer.UnlockPackRoot()
4040
assert.Nil(installer.ReadIndexFiles())
41-
installer.Installation.LocalPidx = xml.NewPidxXML(badLocalRepositoryPidx)
41+
installer.Installation.LocalPidx = xml.NewPidxXML(badLocalRepositoryPidx, false)
4242
defer removePackRoot(localTestingDir)
4343

4444
err := installer.AddPdsc(pdscPack123)

cmd/installer/root_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ func TestUpdatePublicIndex(t *testing.T) {
759759
// Create a temp index file to serve it for update
760760
tempIndexFile := filepath.Join(localTestingDir, installer.PublicIndexName)
761761
assert.Nil(utils.CopyFile(samplePublicIndex, tempIndexFile))
762-
indexXML := xml.NewPidxXML(tempIndexFile)
762+
indexXML := xml.NewPidxXML(tempIndexFile, false)
763763
assert.Nil(indexXML.Read())
764764
assert.Nil(indexXML.AddPdsc(xml.PdscTag{
765765
URL: indexServer.URL(),
@@ -827,7 +827,7 @@ func TestUpdatePublicIndex(t *testing.T) {
827827
// Now get a new index.pidx and the 1.2.4 pdscs into the server and attempt updating with sparse=false
828828
tempIndexFile := filepath.Join(localTestingDir, installer.PublicIndexName)
829829
assert.Nil(utils.CopyFile(samplePublicIndex, tempIndexFile))
830-
indexXML := xml.NewPidxXML(tempIndexFile)
830+
indexXML := xml.NewPidxXML(tempIndexFile, false)
831831
assert.Nil(indexXML.Read())
832832

833833
for i := 1; i < 11; i++ {

0 commit comments

Comments
 (0)