incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r693808 - in /incubator/sling/trunk/extensions/jcrinstall/src: main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/
Date Wed, 10 Sep 2008 12:06:48 GMT
Author: bdelacretaz
Date: Wed Sep 10 05:06:48 2008
New Revision: 693808

URL: http://svn.apache.org/viewvc?rev=693808&view=rev
Log:
SLING-646 - restrict valid resource filenames to avoid picking up temporary files

Added:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java
  (contents, props changed)
      - copied, changed from r693733, incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java
Removed:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java
Modified:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolderCreationListener.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java

Copied: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java
(from r693733, incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java?p2=incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java&p1=incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java&r1=693733&r2=693808&rev=693808&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java
Wed Sep 10 05:06:48 2008
@@ -21,11 +21,11 @@
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
-/** Decide if a folder has a suitable name to be watched */ 
-class FolderNameFilter {
+/** Simple regexp-based filter for folder and file names */ 
+class RegexpFilter {
     private final Pattern pattern;
     
-    FolderNameFilter(String regexp) throws PatternSyntaxException {
+    RegexpFilter(String regexp) throws PatternSyntaxException {
         pattern = Pattern.compile(regexp);
     }
     

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RegexpFilter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=693808&r1=693807&r2=693808&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
Wed Sep 10 05:06:48 2008
@@ -44,8 +44,8 @@
 public class RepositoryObserver {
 
     private Set<WatchedFolder> folders;
-    
-    private FolderNameFilter folderNameFilter;
+    private RegexpFilter folderNameFilter;
+    private RegexpFilter filenameFilter;
     
     /** @scr.reference */
     private OsgiController osgiController;
@@ -60,8 +60,9 @@
     /** Default set of root folders to watch */
     public static String[] DEFAULT_ROOTS = {"/libs", "/apps"};
     
-    /** Default regexp for watched folders */
+    /** Default regexp for watched folders and filenames */
     public static final String DEFAULT_FOLDER_NAME_REGEXP = ".*/install$";
+    public static final String DEFAULT_FILENAME_REGEXP = "[a-zA-Z0-9].*\\.[a-zA-Z][a-zA-Z][a-zA-Z]?";
     
     /** Scan delay for watched folders */
     private final long scanDelayMsec = 1000L;
@@ -75,7 +76,8 @@
     	
     	// TODO make this configurable
     	final String [] roots = DEFAULT_ROOTS; 
-    	folderNameFilter = new FolderNameFilter(DEFAULT_FOLDER_NAME_REGEXP);
+    	folderNameFilter = new RegexpFilter(DEFAULT_FOLDER_NAME_REGEXP);
+    	filenameFilter = new RegexpFilter(DEFAULT_FILENAME_REGEXP);
     	
         // Listen for any new WatchedFolders created after activation
         session = repository.loginAdministrative(repository.getDefaultWorkspace());
@@ -135,7 +137,7 @@
     		final Set<String> paths = w.getAndClearPaths();
     		if(paths != null) {
     			for(String path : paths) {
-    				folders.add(new WatchedFolder(repository, path, osgiController, scanDelayMsec));
+    				folders.add(new WatchedFolder(repository, path, osgiController, filenameFilter, scanDelayMsec));
     			}
     		}
     	}
@@ -172,7 +174,7 @@
     void findWatchedFolders(Node n, Set<WatchedFolder> setToUpdate) throws RepositoryException

     {
         if (folderNameFilter.accept(n.getPath())) {
-            setToUpdate.add(new WatchedFolder(repository, n.getPath(), osgiController, scanDelayMsec));
+            setToUpdate.add(new WatchedFolder(repository, n.getPath(), osgiController, filenameFilter,
scanDelayMsec));
         }
         final NodeIterator it = n.getNodes();
         while (it.hasNext()) {

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java?rev=693808&r1=693807&r2=693808&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
Wed Sep 10 05:06:48 2008
@@ -45,6 +45,7 @@
     private final OsgiController controller;
     private long nextScan;
     private final Session session;
+    private final RegexpFilter filenameFilter;
     protected static final Logger log = LoggerFactory.getLogger(WatchedFolder.class);
     
     /**
@@ -53,9 +54,11 @@
      */
     private final long scanDelayMsec;
 
-    WatchedFolder(SlingRepository repository, String path, OsgiController ctrl, long scanDelayMsec)
throws RepositoryException {
+    WatchedFolder(SlingRepository repository, String path, OsgiController ctrl, 
+            RegexpFilter filenameFilter, long scanDelayMsec) throws RepositoryException {
         this.path = path;
         this.controller = ctrl;
+        this.filenameFilter = filenameFilter;
         this.scanDelayMsec = scanDelayMsec;
         session = repository.loginAdministrative(repository.getDefaultWorkspace());
         
@@ -147,8 +150,13 @@
         	final FileDataProvider dp = new FileDataProvider(n);
         	if(!dp.isFile()) {
         		log.debug("Node {} does not seem to be a file, ignored", n.getPath());
+        	} else if(!filenameFilter.accept(n.getName())) {
+        	    if(log.isDebugEnabled()) {
+                    log.debug("Node " + n.getPath() + " with name " + n.getName() + " ignored
due to " + filenameFilter);
+        	    }
+        	} else {
+        	    installOrUpdate(n.getPath(), dp.getInputStream(), dp.getLastModified());
         	}
-        	installOrUpdate(n.getPath(), dp.getInputStream(), dp.getLastModified());
         }
     }
     

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolderCreationListener.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolderCreationListener.java?rev=693808&r1=693807&r2=693808&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolderCreationListener.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolderCreationListener.java
Wed Sep 10 05:06:48 2008
@@ -34,10 +34,10 @@
  */
 class WatchedFolderCreationListener implements EventListener {
     protected final Logger log = LoggerFactory.getLogger(this.getClass());
-    private final FolderNameFilter folderNameFilter;
+    private final RegexpFilter folderNameFilter;
     private Set<String> paths = new HashSet<String>();
     
-    WatchedFolderCreationListener(FolderNameFilter fnf) {
+    WatchedFolderCreationListener(RegexpFilter fnf) {
     	folderNameFilter = fnf;
 	}
     

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java?rev=693808&r1=693807&r2=693808&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
Wed Sep 10 05:06:48 2008
@@ -169,6 +169,49 @@
         mockery.assertIsSatisfied();
     }
     
+    public void testIgnoredFilenames() throws Exception {
+        contentHelper.setupContent();
+        
+        final String [] resources = {
+                "/libs/foo/bar/install/dummy.jar",
+                "/libs/foo/bar/install/dummy.cfg",
+                "/libs/foo/bar/install/dummy.dp"
+        };
+        
+        final String [] ignored  = {
+                "/libs/foo/bar/install/_dummy.jar",
+                "/libs/foo/bar/install/.dummy.cfg",
+                "/libs/foo/bar/install/dummy.longextension"
+        };
+        
+        final InputStream data = new ByteArrayInputStream("hello".getBytes());
+        final long lastModifiedA = System.currentTimeMillis();
+        final Set<String> installedUri = new HashSet<String>();
+        final OsgiController c = mockery.mock(OsgiController.class);
+        
+        mockery.checking(new Expectations() {{
+            allowing(c).getInstalledUris(); will(returnValue(installedUri));
+            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

+            one(c).installOrUpdate(with(equal(resources[0])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            one(c).installOrUpdate(with(equal(resources[1])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+            one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
+        }});
+        
+        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c);
+        ro.activate(null);
+        
+        for(String file : resources) {
+            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+        }
+        for(String file : ignored) {
+            contentHelper.createOrUpdateFile(file, data, lastModifiedA);
+        }
+        eventHelper.waitForEvents(5000L);
+        
+        ro.runOneCycle();
+        mockery.assertIsSatisfied();
+   }
+    
     public void testInitialDeletions() throws Exception {
         contentHelper.setupContent();
         



Mime
View raw message