in src/main/java/org/apache/sling/jcr/contentloader/internal/BundleContentLoader.java [701:765]
private void uninstallContent(final Session defaultSession, final Bundle bundle, final String[] uninstallPaths) {
final Map<String, Session> createdSessions = new HashMap<>();
try {
log.debug("Uninstalling initial content from bundle {}", bundle.getSymbolicName());
if (uninstallPaths != null && uninstallPaths.length > 0) {
for (String path : uninstallPaths) {
if (!pathFilter.test(path)) {
log.debug("Path {} excluded by configuration", path);
continue;
}
final Session targetSession;
final int wsSepPos = path.indexOf(":/");
if (wsSepPos != -1) {
final String workspaceName = path.substring(0, wsSepPos);
path = path.substring(wsSepPos + 1);
if (workspaceName.equals(defaultSession.getWorkspace().getName())) {
targetSession = defaultSession;
} else if (createdSessions.containsKey(workspaceName)) {
targetSession = createdSessions.get(workspaceName);
} else {
targetSession = createSession(workspaceName);
createdSessions.put(workspaceName, targetSession);
}
} else {
targetSession = defaultSession;
}
if (targetSession.itemExists(path)) {
targetSession.getItem(path).remove();
}
}
// persist modifications now
defaultSession.save();
for (Session session : createdSessions.values()) {
session.save();
}
}
log.debug("Done uninstalling initial content from bundle {}", bundle.getSymbolicName());
} catch (RepositoryException re) {
log.error("Unable to uninstall initial content from bundle " + bundle.getSymbolicName(), re);
} finally {
try {
if (defaultSession.hasPendingChanges()) {
defaultSession.refresh(false);
}
for (Session session : createdSessions.values()) {
if (session.hasPendingChanges()) {
session.refresh(false);
}
}
} catch (RepositoryException re) {
log.warn("Failure to rollback uninstalling initial content for bundle {}", bundle.getSymbolicName(),
re);
}
for (Session session : createdSessions.values()) {
session.logout();
}
}
}