Skip to content

Commit e7b608f

Browse files
committed
Evict bad bundles from the bundle pool
Currently if there is a bad bundle in the bundle pool it is very hard to get rid of it. Deleting it directly will lead to a file not found exception and the pool is completely broken without deeper knowledge of the user p internal data structures. This now checks if the bundle is currently loaded from the bundle pool and if it is failing evict it from the pool so it can be downloaded fresh on the next request.
1 parent 77b66bd commit e7b608f

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/IUBundleContainer.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,8 @@ private void generateBundle(IInstallableUnit unit, IFileArtifactRepository repo,
507507
if( file == null){
508508
file = repo.getArtifactFile(artifactKey);
509509
if (file != null) {
510-
Map<IFileArtifactRepository, File> repoFile = new ConcurrentHashMap<>();
511-
repoFile.put(repo, file);
512-
P2TargetUtils.fgArtifactKeyRepoFile.putIfAbsent(artifactKey, repoFile);
510+
P2TargetUtils.fgArtifactKeyRepoFile.computeIfAbsent(artifactKey, nil -> new ConcurrentHashMap<>())
511+
.put(repo, file);
513512
}
514513
}
515514
if (file != null) {
@@ -522,6 +521,17 @@ private void generateBundle(IInstallableUnit unit, IFileArtifactRepository repo,
522521
info.setVersion(artifactKey.getVersion().toString());
523522
InvalidTargetBundle invalidTargetBundle = new InvalidTargetBundle(info, e.getStatus());
524523
bundles.put(info, invalidTargetBundle);
524+
if (mapRepoFile != null) {
525+
// remove invalid file from the cache...
526+
mapRepoFile.remove(repo);
527+
}
528+
if (repo.isModifiable() && P2TargetUtils.isBundlePool(repo)) {
529+
try {
530+
repo.removeDescriptor(artifactKey, new NullProgressMonitor());
531+
} catch (RuntimeException ignored) {
532+
// better safe than sorry!
533+
}
534+
}
525535
}
526536
}
527537
}

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/P2TargetUtils.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@
107107

108108
public class P2TargetUtils {
109109

110+
private static final String BUNDLE_POOL_SUFFIX = ".bundle_pool"; //$NON-NLS-1$
111+
110112
private static final String SOURCE_IU_ID = "org.eclipse.pde.core.target.source.bundles"; //$NON-NLS-1$
111113

114+
private static final String BUNDLE_POOL_REPO_NAME = "PDE Target Bundle Pool"; //$NON-NLS-1$
115+
112116
/**
113117
* URI to the local directory where the p2 agent keeps its information.
114118
*/
@@ -125,7 +129,7 @@ public class P2TargetUtils {
125129
* Path to the local directory where the local bundle pool is stored for p2 profile
126130
* based targets.
127131
*/
128-
public static final IPath BUNDLE_POOL = PDECore.getDefault().getStateLocation().append(".bundle_pool"); //$NON-NLS-1$
132+
public static final IPath BUNDLE_POOL = PDECore.getDefault().getStateLocation().append(BUNDLE_POOL_SUFFIX);
129133

130134
/**
131135
* Path to the local directory where install folders are created for p2 profile
@@ -451,11 +455,29 @@ public static IFileArtifactRepository getBundlePool() throws CoreException {
451455
} catch (CoreException e) {
452456
// could not load or there wasn't one, fall through to create
453457
}
454-
String repoName = "PDE Target Bundle Pool"; //$NON-NLS-1$
455-
IArtifactRepository result = manager.createRepository(uri, repoName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
458+
IArtifactRepository result = manager.createRepository(uri, BUNDLE_POOL_REPO_NAME,
459+
IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
456460
return (IFileArtifactRepository) result;
457461
}
458462

463+
public static boolean isBundlePool(IFileArtifactRepository repository) {
464+
if (repository == null) {
465+
return false;
466+
}
467+
URI location = repository.getLocation();
468+
if (location == null) {
469+
return false;
470+
}
471+
if (!"file".equals(location.getScheme())) { //$NON-NLS-1$
472+
return false;
473+
}
474+
String path = location.getPath();
475+
if (path.endsWith("/")) { //$NON-NLS-1$
476+
path = path.substring(0, path.length() - 1);
477+
}
478+
return path.endsWith(BUNDLE_POOL_SUFFIX);
479+
}
480+
459481
/**
460482
* Returns the provisioning engine service.
461483
*

0 commit comments

Comments
 (0)