@@ -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
0 commit comments