Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42B8E97DC for ; Thu, 9 Feb 2012 10:00:56 +0000 (UTC) Received: (qmail 66208 invoked by uid 500); 9 Feb 2012 10:00:55 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 66142 invoked by uid 500); 9 Feb 2012 10:00:49 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 66031 invoked by uid 99); 9 Feb 2012 10:00:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Feb 2012 10:00:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Feb 2012 10:00:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6033623889C5; Thu, 9 Feb 2012 10:00:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1242256 - /sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java Date: Thu, 09 Feb 2012 10:00:23 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120209100023.6033623889C5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Thu Feb 9 10:00:22 2012 New Revision: 1242256 URL: http://svn.apache.org/viewvc?rev=1242256&view=rev Log: SLING-2407 : Configuration write back handles delete too aggressive Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java?rev=1242256&r1=1242255&r2=1242256&view=diff ============================================================================== --- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java (original) +++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java Thu Feb 9 10:00:22 2012 @@ -552,24 +552,54 @@ public class JcrInstaller implements Eve } final int pos = url.indexOf(':'); final String path = url.substring(pos + 1); - // remove - logger.debug("Removal of {}", path); - Session session = null; - try { - session = this.repository.loginAdministrative(null); - if ( session.itemExists(path) ) { - session.getItem(path).remove(); - session.save(); - } - } catch (final RepositoryException re) { - logger.error("Unable to remove resource from " + path, re); + + // check path (SLING-2407) + // 0. Check protocol + if ( !url.startsWith(URL_SCHEME) ) { + logger.debug("Not removing unmanaged artifact from repository: {}", url); return null; - } finally { - if ( session != null ) { - session.logout(); + } + // 1. Is this a system configuration then don't delete + final String[] rootPaths = this.folderNameFilter.getRootPaths(); + final String systemConfigRootPath = rootPaths[rootPaths.length - 1]; + if ( path.startsWith(systemConfigRootPath) ) { + logger.debug("Not removing system artifact from repository at {}", path); + return null; + } + // 2. Is this configuration provisioned by us + boolean found = false; + int lastSlash = path.lastIndexOf('/'); + while (!found && lastSlash > 1) { + final String prefix = path.substring(0, lastSlash); + if ( this.folderNameFilter.getPriority(prefix) != -1 ) { + found = true; + } else { + lastSlash = prefix.lastIndexOf('/'); + } + } + if ( found ) { + // remove + logger.debug("Removing artifact at {}", path); + Session session = null; + try { + session = this.repository.loginAdministrative(null); + if ( session.itemExists(path) ) { + session.getItem(path).remove(); + session.save(); + } + } catch (final RepositoryException re) { + logger.error("Unable to remove resource from " + path, re); + return null; + } finally { + if ( session != null ) { + session.logout(); + } } + return new UpdateResult(url); } - return new UpdateResult(url); + // not provisioned by us + logger.debug("Not removing unmanaged artifact from repository at {}", path); + return null; } /**