Skip to content

Commit fc2c857

Browse files
committed
fix: [#495] Upload issues due to incomplete regex.
1 parent 562bc49 commit fc2c857

File tree

1 file changed

+17
-19
lines changed
  • internal/app/n3dr/artifactsv2/upload

1 file changed

+17
-19
lines changed

internal/app/n3dr/artifactsv2/upload/upload.go

+17-19
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,13 @@ func (n *Nexus3) checkLocalChecksumAndCompareWithOneInRemote(f, localDiskRepo, d
323323
scheme = "https"
324324
}
325325

326-
u := scheme + "://" + n.FQDN + "/repository/" + localDiskRepo + "/" + dir + "/" + filename + ".sha512"
327-
log.Debugf("upload URL: '%s'", u)
326+
// URL for checking the sha512 checksum of a file that has been stored in Nexus3
327+
// which has to be compared with the one of the downloaded file.
328+
// If equal then do not upload the file again
329+
checksumOfArtifactInNexus3Sha512URL := scheme + "://" + n.FQDN + "/repository/" + localDiskRepo + "/" + dir + "/" + filename + ".sha512"
330+
log.Debugf("checksumOfArtifactInNexus3Sha512URL: '%s'", checksumOfArtifactInNexus3Sha512URL)
328331

329-
req, err := http.NewRequest("GET", u, nil)
332+
req, err := http.NewRequest("GET", checksumOfArtifactInNexus3Sha512URL, nil)
330333
if err != nil {
331334
return false, err
332335
}
@@ -341,20 +344,16 @@ func (n *Nexus3) checkLocalChecksumAndCompareWithOneInRemote(f, localDiskRepo, d
341344
panic(err)
342345
}
343346
}()
344-
defer func() {
345-
if err := resp.Body.Close(); err != nil {
346-
panic(err)
347-
}
348-
}()
349347
bodyBytes, err := io.ReadAll(resp.Body)
350348
if err != nil {
351349
return false, err
352350
}
353-
bodyString := string(bodyBytes)
354-
log.Debugf("checksum of artifact in nexus3: '%s'", bodyString)
351+
checksumOfArtifactInNexus3 := string(bodyBytes)
352+
log.Debugf("checksum of artifact in nexus3: '%s'", checksumOfArtifactInNexus3)
355353

356-
if bodyString == downloadedFileChecksum {
354+
if checksumOfArtifactInNexus3 == downloadedFileChecksum {
357355
identical = true
356+
log.Infof("the checksum of the filesystem: '%s' is identical to the one in Nexus3: '%s'. Outcome: '%t'", downloadedFileChecksum, checksumOfArtifactInNexus3, identical)
358357
}
359358

360359
return identical, nil
@@ -466,29 +465,28 @@ func (n *Nexus3) UploadSingleArtifact(client *client.Nexus3, path, localDiskRepo
466465
c.Maven2Version = &mp.version
467466

468467
// Match "/some/group/" and capture the group name.
469-
regex := `^` + localDiskRepoHome + `/([\w+\/]+)/` + mp.artifact
468+
regex := `^` + localDiskRepoHome + `/([\.\-\d+\w+\/]+)/` + mp.artifact
470469
re := regexp.MustCompile(regex)
471470
groupID := ""
472471

473472
// Extract the group name from the path.
473+
// * the path will be validated
474+
// * subsequently the groupID will be extracted from the path. Note: a groupID could be: 'some/group/some/artifact'
474475
match := re.FindStringSubmatch(path)
475476
if len(match) >= 2 {
477+
log.Tracef("elements: '%v' that were found that are required to determine the groupID", match)
476478
groupID = match[1]
479+
log.Debugf("the following groupID has been found: '%s'", groupID)
477480
groupID = strings.ReplaceAll(groupID, `/`, `.`)
481+
log.Tracef("groupID without slash: '%s'", groupID)
478482
} else {
479483
return false, fmt.Errorf("groupID should not be empty, path: '%s' and regex: '%s'", path, regex)
480484
}
481485
c.Maven2GroupID = &groupID
482486
generatePOM := true
483487
c.Maven2GeneratePom = &generatePOM
484488

485-
maven2Asset1 := "empty"
486-
maven2Asset2 := "empty"
487-
maven2Asset3 := "empty"
488-
maven2Asset4 := "empty"
489-
maven2Asset5 := "empty"
490-
maven2Asset6 := "empty"
491-
maven2Asset7 := "empty"
489+
maven2Asset1, maven2Asset2, maven2Asset3, maven2Asset4, maven2Asset5, maven2Asset6, maven2Asset7 := "empty", "empty", "empty", "empty", "empty", "empty", "empty"
492490

493491
if c.Maven2Asset1 != nil {
494492
maven2Asset1 = c.Maven2Asset1.Name()

0 commit comments

Comments
 (0)