From 40355f4303ef104afeac8e0cacc6da772a5e41f4 Mon Sep 17 00:00:00 2001
From: Ben van B <030@users.noreply.github.com>
Date: Sat, 24 Feb 2024 14:39:33 +0100
Subject: [PATCH] fix: [#495] Upload issues due to incomplete regex. (#498)
---
Taskfile.yml | 2 +-
build/package/snap/snapcraft.yaml | 2 +-
docs/CHANGELOG.md | 15 ++++++--
docs/quickstarts/snippets/n3dr/DOWNLOAD.md | 6 ++--
.../app/n3dr/artifactsv2/upload/upload.go | 36 +++++++++----------
5 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/Taskfile.yml b/Taskfile.yml
index 498dc091..fba50ec5 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -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:
diff --git a/build/package/snap/snapcraft.yaml b/build/package/snap/snapcraft.yaml
index 446ca71f..cd250e4c 100644
--- a/build/package/snap/snapcraft.yaml
+++ b/build/package/snap/snapcraft.yaml
@@ -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.
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 285ec09d..4892b4e8 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -2,6 +2,16 @@
## [Unreleased]
+
+## [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))
+
+
## [7.5.0] - 2024-02-10
### Build
@@ -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))
@@ -474,7 +484,8 @@ The `backup`, `upload` and `repositories` commands have been removed.
## 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
diff --git a/docs/quickstarts/snippets/n3dr/DOWNLOAD.md b/docs/quickstarts/snippets/n3dr/DOWNLOAD.md
index 00bb93d1..44739e28 100644
--- a/docs/quickstarts/snippets/n3dr/DOWNLOAD.md
+++ b/docs/quickstarts/snippets/n3dr/DOWNLOAD.md
@@ -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 && \
diff --git a/internal/app/n3dr/artifactsv2/upload/upload.go b/internal/app/n3dr/artifactsv2/upload/upload.go
index 96a51bf7..978078bd 100644
--- a/internal/app/n3dr/artifactsv2/upload/upload.go
+++ b/internal/app/n3dr/artifactsv2/upload/upload.go
@@ -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
}
@@ -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
@@ -466,15 +465,20 @@ 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)
}
@@ -482,13 +486,7 @@ func (n *Nexus3) UploadSingleArtifact(client *client.Nexus3, path, localDiskRepo
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()