6
6
"net/http"
7
7
"os"
8
8
"path/filepath"
9
+ "regexp"
9
10
"sync"
10
11
"time"
11
12
@@ -86,7 +87,7 @@ func (n *Nexus3) download(checksum, downloadedFileChecksum string, asset *models
86
87
return nil
87
88
}
88
89
89
- func (n * Nexus3 ) downloadSingleArtifact (asset * models.AssetXO , repo string ) {
90
+ func (n * Nexus3 ) downloadSingleArtifact (asset * models.AssetXO , repo string ) error {
90
91
shaType , checksum := artifacts .Checksum (asset )
91
92
92
93
log .WithFields (log.Fields {
@@ -101,6 +102,17 @@ func (n *Nexus3) downloadSingleArtifact(asset *models.AssetXO, repo string) {
101
102
}
102
103
if ! filesToBeSkipped {
103
104
file := filepath .Join (n .DownloadDirName , repo , assetPath )
105
+
106
+ // skip download of artifact if it does not match the regex
107
+ r , err := regexp .Compile (n .Regex )
108
+ if err != nil {
109
+ return err
110
+ }
111
+ if ! r .MatchString (file ) {
112
+ log .Debugf ("file: '%s' skipped as it does not match regex: '%s'" , file , n .Regex )
113
+ return nil
114
+ }
115
+
104
116
downloadedFileChecksum , err := artifacts .ChecksumLocalFile (file , shaType )
105
117
if err != nil {
106
118
panic (err )
@@ -110,6 +122,8 @@ func (n *Nexus3) downloadSingleArtifact(asset *models.AssetXO, repo string) {
110
122
panic (err )
111
123
}
112
124
}
125
+
126
+ return nil
113
127
}
114
128
115
129
func (n * Nexus3 ) downloadIfChecksumMismatchLocalFile (continuationToken , repo string ) error {
@@ -129,13 +143,17 @@ func (n *Nexus3) downloadIfChecksumMismatchLocalFile(continuationToken, repo str
129
143
for _ , item := range resp .GetPayload ().Items {
130
144
for _ , asset := range item .Assets {
131
145
if n .WithoutWaitGroups || n .WithoutWaitGroupArtifacts {
132
- n .downloadSingleArtifact (asset , repo )
146
+ if err := n .downloadSingleArtifact (asset , repo ); err != nil {
147
+ return err
148
+ }
133
149
} else {
134
150
wg .Add (1 )
135
151
go func (asset * models.AssetXO ) {
136
152
defer wg .Done ()
137
153
138
- n .downloadSingleArtifact (asset , repo )
154
+ if err := n .downloadSingleArtifact (asset , repo ); err != nil {
155
+ panic (err )
156
+ }
139
157
}(asset )
140
158
}
141
159
}
@@ -199,7 +217,7 @@ func (n *Nexus3) repository(repo *models.AbstractAPIRepository) {
199
217
func (n * Nexus3 ) Backup () error {
200
218
var wg sync.WaitGroup
201
219
202
- cn := connection.Nexus3 {BasePathPrefix : n .BasePathPrefix , FQDN : n .FQDN , DownloadDirName : n .DownloadDirName , Pass : n .Pass , User : n .User , HTTPS : n .HTTPS , DockerHost : n .DockerHost , DockerPort : n .DockerPort , DockerPortSecure : n .DockerPortSecure }
220
+ cn := connection.Nexus3 {BasePathPrefix : n .BasePathPrefix , FQDN : n .FQDN , DownloadDirName : n .DownloadDirName , Pass : n .Pass , User : n .User , HTTPS : n .HTTPS , DockerHost : n .DockerHost , DockerPort : n .DockerPort , DockerPortSecure : n .DockerPortSecure , Regex : n . Regex }
203
221
a := artifacts.Nexus3 {Nexus3 : & cn }
204
222
repos , err := a .Repos ()
205
223
if err != nil {
0 commit comments