Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip locally generated files for npm and rpm repositories #466

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading