@@ -45,7 +45,7 @@ class Global {
45
45
46
46
def pluginGroup = ' cleaners'
47
47
def config = new ConfigSlurper (). parse(new File (ctx. artifactoryHome. haAwareEtcDir, PROPERTIES_FILE_PATH ). toURL())
48
- def regex = ~/ - \d + \ .\d +\.\d +/
48
+ def regex = ~/ .*-[ \ .\d +]*[-+][ \.\d +]* \. .* /
49
49
50
50
51
51
executions {
@@ -123,8 +123,12 @@ private def artifactCleanup(int months, String[] repos, log, paceTimeMS, dryRun
123
123
Global . stopCleaning = false
124
124
int cntFoundArtifacts = 0
125
125
int cntNoDeletePermissions = 0
126
+ int cntNoDeleteRegexPermissions = 0
127
+ int cntRemovedArtifacts = 0
126
128
long bytesFound = 0
127
129
long bytesFoundWithNoDeletePermission = 0
130
+ long bytesFoundWithRegexProtection = 0
131
+ long bytesRemoved = 0
128
132
def artifactsCleanedUp = searches. artifactsNotDownloadedSince(monthsUntil, monthsUntil, repos)
129
133
artifactsCleanedUp. find {
130
134
try {
@@ -152,24 +156,31 @@ private def artifactCleanup(int months, String[] repos, log, paceTimeMS, dryRun
152
156
cntNoDeletePermissions++
153
157
}
154
158
if (dryRun) {
155
- log. info " Found $it , $cntFoundArtifacts /$artifactsCleanedUp . size total $bytesFound bytes"
156
- log. info " \t ==> currentUser: ${ security.currentUser().getUsername()} "
157
- log. info " \t ==> canDelete: ${ security.canDelete(it)} "
159
+ log. debug " Found $it , $cntFoundArtifacts /$artifactsCleanedUp . size total $bytesFound bytes"
160
+ log. debug " \t ==> currentUser: ${ security.currentUser().getUsername()} "
161
+ log. debug " \t ==> canDelete: ${ security.canDelete(it)} "
158
162
if (! checkName(keepArtifacts, keepArtifactsRegex, it)) {
159
163
log. info " \t ==> protected by regex: ${ keepArtifactsRegex} "
160
164
}
161
165
} else {
162
166
if (security. canDelete(it) && (checkName(keepArtifacts, keepArtifactsRegex, it))) {
163
- log. info " Deleting $it , $cntFoundArtifacts /$artifactsCleanedUp . size total $bytesFound bytes"
167
+ bytesRemoved + = repositories. getItemInfo(it)?. getSize()
168
+ log. debug " Deleting $it , [$cntFoundArtifacts /$artifactsCleanedUp . size ]. Removed $bytesRemoved of total $bytesFound bytes"
164
169
repositories. delete it
165
170
} else {
166
- log. info " Can't delete $it (user ${ security.currentUser().getUsername()} has no delete permissions), " +
171
+ log. debug " Can't delete $it (user ${ security.currentUser().getUsername()} has no delete permissions), " +
167
172
" $cntFoundArtifacts /$artifactsCleanedUp . size total $bytesFound bytes"
168
- cntNoDeletePermissions++
173
+ if (security. canDelete(it)) {
174
+ // Because previous block was not processed, security.canDelete(it) AND/OR checkName is FALSE.
175
+ // I am checking if permissions to delete files are proper. If that's true, that means function checkName returned FALSE
176
+ // and artifact is protected by Regex.
177
+ bytesFoundWithRegexProtection + = repositories. getItemInfo(it)?. getSize()
178
+ cntNoDeleteRegexPermissions++
179
+ }
169
180
}
170
181
}
171
182
} catch (ItemNotFoundRuntimeException ex) {
172
- log. info " Failed to find $it , skipping"
183
+ log. debug " Failed to find $it , skipping"
173
184
}
174
185
175
186
def sleepTime = (Global . paceTimeMS > 0 ) ? Global . paceTimeMS : paceTimeMS
@@ -184,8 +195,11 @@ private def artifactCleanup(int months, String[] repos, log, paceTimeMS, dryRun
184
195
log. info " Dry run - nothing deleted. Found $cntFoundArtifacts artifacts consuming $bytesFound bytes"
185
196
log. info " From that $cntNoDeletePermissions artifacts no delete permission by user ($bytesFoundWithNoDeletePermission bytes)"
186
197
} else {
187
- log. info " Finished cleanup, try to delete $cntFoundArtifacts artifacts that took up $bytesFound bytes"
198
+ cntRemovedArtifacts = cntFoundArtifacts - cntNoDeletePermissions - cntNoDeleteRegexPermissions
199
+ log. info " Finished cleanup $repos repositories, try to delete $cntFoundArtifacts artifacts that took up $bytesFound bytes"
188
200
log. info " From that $cntNoDeletePermissions artifacts no delete permission by user ($bytesFoundWithNoDeletePermission bytes)"
201
+ log. info " and $cntNoDeleteRegexPermissions artifacts is protected by regex $keepArtifactsRegex ($bytesFoundWithRegexProtection bytes)"
202
+ log. info " After this cleanup, $cntRemovedArtifacts artifacts ($bytesRemoved bytes) was removed from $repos repositories"
189
203
}
190
204
}
191
205
@@ -235,4 +249,4 @@ private def getSkippedPaths(String[] repos) {
235
249
236
250
private def checkName (keepArtifacts , keepArtifactsRegex , artifactName ) {
237
251
return ! keepArtifacts || ! ((artifactName =~ keepArtifactsRegex). count > 0 )
238
- }
252
+ }
0 commit comments