Skip to content

Commit

Permalink
fix: [#495] Upload issues due to incomplete regex. (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
030 authored Feb 24, 2024
1 parent 562bc49 commit 40355f4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: '3'
env:
GIT_CHGLOG_URL: https://github.com/git-chglog/git-chglog/releases/download
GIT_CHGLOG_VERSION: v0.15.1/git-chglog_0.15.1_linux_amd64.tar.gz
CHANGELOG_NEXT_TAG: 7.5.0
CHANGELOG_NEXT_TAG: 7.5.1

tasks:
changelog:
Expand Down
2 changes: 1 addition & 1 deletion build/package/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: n3dr
base: core22
version: 7.5.0
version: 7.5.1
summary: Nexus3 Disaster Recovery
description: |
Download all artifacts at once or migrate automatically from Nexus to Nexus.
Expand Down
15 changes: 13 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
## [Unreleased]


<a name="7.5.1"></a>
## [7.5.1] - 2024-02-24
### Build
- **deps:** bump schubergphilis/mcvs-golang-action from 0.3.0 to 0.4.1 ([#483](https://github.com/030/n3dr/issues/483))

### Fix
- [[#495](https://github.com/030/n3dr/issues/495)] Upload issues due to incomplete regex.
- [[#493](https://github.com/030/n3dr/issues/493)] Resolve issue in integration test. ([#494](https://github.com/030/n3dr/issues/494))


<a name="7.5.0"></a>
## [7.5.0] - 2024-02-10
### Build
Expand All @@ -13,7 +23,7 @@
- **deps:** bump github.com/docker/docker from 20.10.24+incompatible to 20.10.27+incompatible ([#466](https://github.com/030/n3dr/issues/466))

### Feat
- [[#459](https://github.com/030/n3dr/issues/459)] Display how long N3DR was running.
- [[#459](https://github.com/030/n3dr/issues/459)] Display how long N3DR was running. ([#475](https://github.com/030/n3dr/issues/475))


<a name="7.4.1"></a>
Expand Down Expand Up @@ -474,7 +484,8 @@ The `backup`, `upload` and `repositories` commands have been removed.
<a name="1.0.0"></a>
## 1.0.0 - 2019-05-12

[Unreleased]: https://github.com/030/n3dr/compare/7.5.0...HEAD
[Unreleased]: https://github.com/030/n3dr/compare/7.5.1...HEAD
[7.5.1]: https://github.com/030/n3dr/compare/7.5.0...7.5.1
[7.5.0]: https://github.com/030/n3dr/compare/7.4.1...7.5.0
[7.4.1]: https://github.com/030/n3dr/compare/7.4.0...7.4.1
[7.4.0]: https://github.com/030/n3dr/compare/7.3.3...7.4.0
Expand Down
6 changes: 3 additions & 3 deletions docs/quickstarts/snippets/n3dr/DOWNLOAD.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Download

Download the [latest N3DR binary](https://github.com/030/n3dr/releases/tag/7.5.0):
Download the [latest N3DR binary](https://github.com/030/n3dr/releases/tag/7.5.1):

```bash
cd /tmp && \
curl -L https://github.com/030/n3dr/releases/download/7.5.0/n3dr-ubuntu-latest \
curl -L https://github.com/030/n3dr/releases/download/7.5.1/n3dr-ubuntu-latest \
-o n3dr-ubuntu-latest && \
curl -L https://github.com/030/n3dr/releases/download/7.5.0/\
curl -L https://github.com/030/n3dr/releases/download/7.5.1/\
n3dr-ubuntu-latest.sha512.txt \
-o n3dr-ubuntu-latest.sha512.txt && \
sha512sum -c n3dr-ubuntu-latest.sha512.txt && \
Expand Down
36 changes: 17 additions & 19 deletions internal/app/n3dr/artifactsv2/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,13 @@ func (n *Nexus3) checkLocalChecksumAndCompareWithOneInRemote(f, localDiskRepo, d
scheme = "https"
}

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

req, err := http.NewRequest("GET", u, nil)
req, err := http.NewRequest("GET", checksumOfArtifactInNexus3Sha512URL, nil)
if err != nil {
return false, err
}
Expand All @@ -341,20 +344,16 @@ func (n *Nexus3) checkLocalChecksumAndCompareWithOneInRemote(f, localDiskRepo, d
panic(err)
}
}()
defer func() {
if err := resp.Body.Close(); err != nil {
panic(err)
}
}()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return false, err
}
bodyString := string(bodyBytes)
log.Debugf("checksum of artifact in nexus3: '%s'", bodyString)
checksumOfArtifactInNexus3 := string(bodyBytes)
log.Debugf("checksum of artifact in nexus3: '%s'", checksumOfArtifactInNexus3)

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

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

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

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

maven2Asset1 := "empty"
maven2Asset2 := "empty"
maven2Asset3 := "empty"
maven2Asset4 := "empty"
maven2Asset5 := "empty"
maven2Asset6 := "empty"
maven2Asset7 := "empty"
maven2Asset1, maven2Asset2, maven2Asset3, maven2Asset4, maven2Asset5, maven2Asset6, maven2Asset7 := "empty", "empty", "empty", "empty", "empty", "empty", "empty"

if c.Maven2Asset1 != nil {
maven2Asset1 = c.Maven2Asset1.Name()
Expand Down

0 comments on commit 40355f4

Please sign in to comment.