getLog().info("Per configuration, we will NOT perform any remote operations on the S3 repository.");
logPrefix = "SKIPPING: ";
}
final S3RepositoryPath targetRepository = context.getS3TargetRepositoryPath();
final String targetBucket = targetRepository.getBucketName();
AmazonS3 s3Session = context.getS3Session();
File directoryToUpload = uploadMetadataOnly
? context.getLocalYumRepo().repoDataDirectory() // only the repodata directory
: stagingDirectory; // the entire staging directory/bucket
if (!allowCreateRepository && !context.getLocalYumRepo().isRepoDataExists()) {
throw new MojoExecutionException("refusing to create new repo: " + targetRepository +
" (use s3repo.allowCreateRepository = true to force)");
}
for (File toUpload : ExtraIOUtils.listAllFiles(directoryToUpload)) {
final String bucketKey = localFileToTargetS3BucketKey(toUpload, context);
getLog().info(logPrefix + "Uploading: " + toUpload.getName() + " => s3://" + targetRepository.getBucketName() + "/" + bucketKey + "...");
if (!doNotUpload) {
s3Session.putObject(new PutObjectRequest(targetBucket, bucketKey, toUpload));
}
}
if (uploadMetadataOnly && !context.sourceAndTargetRepositoryAreSame()) {
// we just uploaded metadata but there are files in the source repository
// that don't exist in the target, so we upload those here.
for (File toUpload : ExtraIOUtils.listAllFiles(stagingDirectory)) {
if (!context.getFilesFromTargetRepo().contains(toUpload)) {
// upload if it's not already in the target repo.
final String bucketKey = localFileToTargetS3BucketKey(toUpload, context);
getLog().info(logPrefix + "Uploading: " + toUpload.getName()
+ " => s3://" + targetRepository.getBucketName() + "/" + bucketKey + "...");
if (!doNotUpload) {
s3Session.putObject(new PutObjectRequest(targetBucket, bucketKey, toUpload));
}
}
}
}
// delete any excluded files remotely from the TARGET only.
for (String repoRelativePath : context.getExcludedFilesToDeleteFromTarget()) {
final String bucketKey = toBucketKey(targetRepository, repoRelativePath);
getLog().info(logPrefix + "Deleting: "
+ "s3://" + targetRepository.getBucketName() + "/" + bucketKey + " (excluded file)");
if (!doNotUpload) {
context.getS3Session().deleteObject(targetBucket, bucketKey);
}
}
// and finally, delete any remote bucket keys we wish to remove (e.g., old snaphots)...from the TARGET only.
for (SnapshotDescription toDelete : context.getSnapshotsToDeleteRemotely()) {
getLog().info(logPrefix + "Deleting: "
+ "s3://" + targetRepository.getBucketName() + "/" + toDelete.getBucketKey() + " (excluded file)");
getLog().info(logPrefix + "Deleting: " + toDelete + " (old snapshot)");
if (!doNotUpload) {
context.getS3Session().deleteObject(targetBucket, toDelete.getBucketKey());
}
}
// rename any snapshots...in TARGET only.
for (RemoteSnapshotRename toRename : context.getSnapshotsToRenameRemotely()) {
final String sourceBucketKey = toRename.getSource().getBucketKey();
final String targetBucketKey = toRename.getNewBucketKey();
getLog().info(logPrefix + "Renaming: "
+ "s3://" + targetRepository.getBucketName() + "/" + sourceBucketKey
+ " => s3://" + targetRepository.getBucketName() + "/" + targetBucketKey);
if (!doNotUpload) {
s3Session.copyObject(targetBucket, sourceBucketKey, targetBucket, targetBucketKey);
s3Session.deleteObject(targetBucket, sourceBucketKey);
}
}
}