@@ -155,7 +155,7 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
155155
156156 if pack .isPackID && nometa {
157157 if meta , found := utils .SemverHasMeta (pack .Version ); found {
158- return pack , fmt .Errorf ("%w: \" %s \" . Expected vendor.pack.version" , errs .ErrBadPackVersion , meta )
158+ return pack , fmt .Errorf ("%w: %q . Expected vendor.pack.version" , errs .ErrBadPackVersion , meta )
159159 }
160160 }
161161
@@ -188,20 +188,20 @@ func preparePack(packPath string, toBeRemoved, forceLatest, noLocal, nometa bool
188188// Returns:
189189// - error: an error object if the file does not exist or if there is an issue during download.
190190func (p * PackType ) fetch (timeout int ) error {
191- log .Debugf ("Fetching pack file \" %s \" (or just making sure it exists locally)" , p .path )
191+ log .Debugf ("Fetching pack file %q (or just making sure it exists locally)" , p .path )
192192 var err error
193193 if strings .HasPrefix (p .path , "http" ) {
194- p .path , err = utils .DownloadFile (p .path , false , timeout )
194+ p .path , err = utils .DownloadFile (p .path , true , false , timeout )
195195 if err == errs .ErrTerminatedByUser {
196- log .Infof ("Aborting pack download. Removing \" %s \" " , p .path )
196+ log .Infof ("Aborting pack download. Removing %q " , p .path )
197197 }
198198
199199 p .isDownloaded = true
200200 return err
201201 }
202202
203203 if ! utils .FileExists (p .path ) {
204- log .Errorf ("File \" %s \" doesn't exist" , p .path )
204+ log .Errorf ("File %q doesn't exist" , p .path )
205205 return errs .ErrFileNotFound
206206 }
207207
@@ -212,10 +212,10 @@ func (p *PackType) fetch(timeout int) error {
212212// to be installed.
213213func (p * PackType ) validate () error {
214214 log .Debug ("Validating pack" )
215- pdscFileName := p .PdscFileName ()
215+ myPdscFileName := p .PdscFileName ()
216216 for _ , file := range p .zipReader .File {
217- if filepath .Base (file .Name ) == pdscFileName {
218-
217+ ext := strings . ToLower ( filepath .Ext (file .Name ))
218+ if ext == PdscExtension {
219219 // Check if pack was compressed in a subfolder
220220 subfoldersCount := strings .Count (file .Name , "/" ) + strings .Count (file .Name , "\\ " )
221221 if subfoldersCount > 1 {
@@ -226,10 +226,12 @@ func (p *PackType) validate() error {
226226
227227 // Ensure the file path does not contain ".."
228228 if strings .Contains (file .Name , ".." ) {
229- log .Errorf ("File \" %s \" invalid file path" , file .Name )
229+ log .Errorf ("File %q invalid file path" , file .Name )
230230 return errs .ErrInvalidFilePath
231231 }
232232
233+ myPdscFileName = p .PackID () + filepath .Ext (file .Name )
234+
233235 // Read pack's pdsc
234236 tmpPdscFileName := filepath .Join (os .TempDir (), utils .RandStringBytes (10 ))
235237 defer os .RemoveAll (tmpPdscFileName )
@@ -247,20 +249,31 @@ func (p *PackType) validate() error {
247249 version := p .GetVersion ()
248250 latestVersion := p .Pdsc .LatestVersion ()
249251
250- log .Debugf ("Making sure %s is the latest release in %s" , p . targetVersion , pdscFileName )
252+ log .Debugf ("Making sure %s is the latest release in %s" , version , myPdscFileName )
251253
252254 if utils .SemverCompare (version , latestVersion ) != 0 {
253255 releaseTag := p .Pdsc .FindReleaseTagByVersion (version )
254256 if releaseTag == nil {
255- log .Errorf ("The pack's pdsc (%s) has no release tag matching version \" %s \" " , pdscFileName , version )
257+ log .Errorf ("The pack's pdsc (%s) has no release tag matching version %q" , myPdscFileName , version )
256258 return errs .ErrPackVersionNotFoundInPdsc
257259 }
258260
259- log .Errorf ("The latest release (%s) in pack's pdsc (%s) does not match pack version \" %s \" " , latestVersion , pdscFileName , version )
261+ log .Errorf ("The latest release (%s) in pack's pdsc (%s) does not match pack version %q" , latestVersion , myPdscFileName , version )
260262 return errs .ErrPackVersionNotLatestReleasePdsc
261263 }
262264
263265 p .Pdsc .FileName = file .Name
266+
267+ pdscFileName := p .PdscFileName () // destination file name in .Download directory
268+ pdscFilePath := filepath .Join (tmpPdscFileName , file .Name ) // #nosec
269+ newPdscFileName := p .PdscFileNameWithVersion ()
270+
271+ if ! p .IsPublic {
272+ _ = utils .CopyFile (pdscFilePath , filepath .Join (Installation .LocalDir , pdscFileName ))
273+ }
274+
275+ _ = utils .CopyFile (pdscFilePath , filepath .Join (Installation .DownloadDir , newPdscFileName ))
276+
264277 return nil
265278 } else {
266279 if strings .Contains (file .Name , ".." ) {
@@ -269,7 +282,7 @@ func (p *PackType) validate() error {
269282 }
270283 }
271284
272- log .Errorf ("\" %s \" not found in \" %s \" " , pdscFileName , p .path )
285+ log .Errorf ("%q not found in %q" , myPdscFileName , p .path )
273286 return errs .ErrPdscFileNotFound
274287}
275288
@@ -329,12 +342,12 @@ func (p *PackType) install(installation *PacksInstallationType, checkEula bool)
329342 p .path = filepath .FromSlash (p .path )
330343 p .path = filepath .Clean (p .path )
331344
332- log .Debugf ("Installing \" %s \" " , p .path )
345+ log .Debugf ("Installing %q " , p .path )
333346
334347 var err error
335348 p .zipReader , err = zip .OpenReader (p .path )
336349 if err != nil {
337- log .Errorf ("Can't decompress \" %s \" : %s" , p .path , err )
350+ log .Errorf ("Can't decompress %q : %s" , p .path , err )
338351 return errs .ErrFailedDecompressingFile
339352 }
340353
@@ -379,12 +392,12 @@ func (p *PackType) install(installation *PacksInstallationType, checkEula bool)
379392 // Inflate all files
380393 err = utils .EnsureDir (packHomeDir )
381394 if err != nil {
382- log .Errorf ("Can't access pack directory \" %s \" : %s" , packHomeDir , err )
395+ log .Errorf ("Can't access pack directory %q : %s" , packHomeDir , err )
383396 return err
384397 }
385398
386399 if log .IsLevelEnabled (log .DebugLevel ) {
387- log .Debugf ("Extracting files from \" %s \" to \" %s \" " , p .path , packHomeDir )
400+ log .Debugf ("Extracting files from %q to %q " , p .path , packHomeDir )
388401 } else {
389402 log .Infof ("Extracting files to %s..." , packHomeDir )
390403 }
@@ -411,7 +424,7 @@ func (p *PackType) install(installation *PacksInstallationType, checkEula bool)
411424 defer p .zipReader .Close ()
412425
413426 if err == errs .ErrTerminatedByUser {
414- log .Infof ("Aborting pack extraction. Removing \" %s \" " , packHomeDir )
427+ log .Infof ("Aborting pack extraction. Removing %q " , packHomeDir )
415428 if newErr := p .uninstall (installation ); newErr != nil {
416429 log .Error (err )
417430 }
@@ -423,16 +436,6 @@ func (p *PackType) install(installation *PacksInstallationType, checkEula bool)
423436 // Close zip file so Windows can't complain if we rename it
424437 p .zipReader .Close ()
425438
426- pdscFileName := p .PdscFileName ()
427- pdscFilePath := filepath .Join (packHomeDir , pdscFileName )
428- newPdscFileName := p .PdscFileNameWithVersion ()
429-
430- if ! p .IsPublic {
431- _ = utils .CopyFile (pdscFilePath , filepath .Join (Installation .LocalDir , pdscFileName ))
432- }
433-
434- _ = utils .CopyFile (pdscFilePath , filepath .Join (Installation .DownloadDir , newPdscFileName ))
435-
436439 if ! p .isDownloaded {
437440 return utils .CopyFile (p .path , packBackupPath )
438441 }
@@ -552,7 +555,7 @@ func (p *PackType) extractEula(packPath string) error {
552555 eulaFileName := packPath + "." + filepath .Base (p .Pdsc .License )
553556
554557 if utils .GetEncodedProgress () {
555- log .Infof ("[L:F\" %s \" ]" , eulaFileName )
558+ log .Infof ("[L:F%q ]" , eulaFileName )
556559 } else {
557560 log .Infof ("Extracting embedded license to %v" , eulaFileName )
558561 }
@@ -562,7 +565,7 @@ func (p *PackType) extractEula(packPath string) error {
562565 os .Remove (eulaFileName )
563566 }
564567 if utils .FileExists (eulaFileName ) {
565- log .Errorf ("Cannot remove previous copy of license file: \" %s \" " , eulaFileName )
568+ log .Errorf ("Cannot remove previous copy of license file: %q " , eulaFileName )
566569 return errs .ErrFailedCreatingFile
567570 }
568571
@@ -572,7 +575,7 @@ func (p *PackType) extractEula(packPath string) error {
572575// resolveVersionModifier takes into account eventual versionModifiers (@, @^, @~ and @>=) to determine
573576// which version of a pack should be targeted for installation
574577func (p * PackType ) resolveVersionModifier (pdscXML * xml.PdscXML ) {
575- log .Debugf ("Resolving version modifier for \" %s \" using PDSC \" %s \" " , p .path , pdscXML .FileName )
578+ log .Debugf ("Resolving version modifier for %q using PDSC %q " , p .path , pdscXML .FileName )
576579
577580 if p .versionModifier == utils .ExactVersion {
578581 p .targetVersion = p .Version
@@ -728,17 +731,17 @@ func (p *PackType) PackIDWithVersion() string {
728731
729732// PackFileName returns a string with how the pack file name would be: Vendor.PackName.x.y.z.pack
730733func (p * PackType ) PackFileName () string {
731- return p .PackIDWithVersion () + ".pack"
734+ return p .PackIDWithVersion () + PackExtension
732735}
733736
734737// PdscFileName returns a string with how the pack's pdsc file name would be: Vendor.PackName.pdsc
735738func (p * PackType ) PdscFileName () string {
736- return p .PackID () + ".pdsc"
739+ return p .PackID () + PdscExtension
737740}
738741
739742// PdscFileNameWithVersion returns a string with how the pack's pdsc file name would be: Vendor.PackName.x.y.z.pdsc
740743func (p * PackType ) PdscFileNameWithVersion () string {
741- return p .PackIDWithVersion () + ".pdsc"
744+ return p .PackIDWithVersion () + PdscExtension
742745}
743746
744747// GetVersion makes sure to get the latest version for the pack
0 commit comments