Skip to content

Commit

Permalink
Merge pull request #466 from jfrog/skip-metadata-directories
Browse files Browse the repository at this point in the history
Skip locally generated files for npm and rpm repositories
  • Loading branch information
bhanurp authored Sep 3, 2024
2 parents 72c926b + 5b0fb4c commit 3b221c8
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion storage/remoteBackup/remoteBackup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ storage {
def dest = cfg[item.repoKey]
try {
def destpath = RepoPathFactory.create(dest, item.relPath)
repositories.copy(item.repoPath, destpath)
def isCopyAllowed = canCopyBasedOnPackageType(item, repositories)
if (isCopyAllowed) {
repositories.copy(item.repoPath, destpath)
} else {
log.warn("Skipping copying $item.repoPath to $dest as it is not allowed because it is local generated path")
}
} catch (Exception ex) {
log.warn("Unable to backup $item.repoPath to $dest: $ex.message")
}
Expand All @@ -77,6 +82,21 @@ storage {
}
}

static def canCopyBasedOnPackageType(item, repositories) {
def packageType = repositories.getRepositoryConfiguration(item.getRepoKey()).getPackageType()
def path = item.repoPath.getPath()
switch (packageType) {
case "npm":
return !path.startsWith(".npm")
case "rpm":
return !path.startsWith("repodata")
case "deb":
return !path.startsWith("dists")
default:
return true
}
}

def runBackup(repos) {
def etcdir = ctx.artifactoryHome.etcDir
def cfgfile = new File(etcdir, REMOTE_BACKUP)
Expand All @@ -97,6 +117,11 @@ def runBackup(repos) {
cfg = cfgtmp
}
def complete = 0, total = 0
// This is to avoid copying the metadata files for example
// .npm is for npm repositories
// repodata is for yum repositories
// dists is for debian repositories
def localGeneratedPaths = [".npm", "repodata", "dists"]
for (repopair in cfg.entrySet()) {
def src = repopair.key, dest = repopair.value
def quer = new JsonBuilder([type: 'file', repo: src]).toString()
Expand All @@ -113,6 +138,9 @@ def runBackup(repos) {
repositories.getFileInfo(destpath).checksumsInfo.sha1))) {
total += 1
try {
if (localGeneratedPaths.any { path.startsWith(it) }){
continue
}
repositories.copy(srcpath, destpath)
complete += 1
} catch (Exception ex) {
Expand Down

0 comments on commit 3b221c8

Please sign in to comment.