roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r470047 - in /incubator/roller/trunk/src/org/apache/roller/business: FileManagerImpl.java ThemeManagerImpl.java
Date Wed, 01 Nov 2006 19:36:29 GMT
Author: agilliland
Date: Wed Nov  1 11:36:29 2006
New Revision: 470047

URL: http://svn.apache.org/viewvc?view=rev&rev=470047
Log:
fixing a bug when importing theme resources to paths in subdirectories.


Modified:
    incubator/roller/trunk/src/org/apache/roller/business/FileManagerImpl.java
    incubator/roller/trunk/src/org/apache/roller/business/ThemeManagerImpl.java

Modified: incubator/roller/trunk/src/org/apache/roller/business/FileManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/FileManagerImpl.java?view=diff&rev=470047&r1=470046&r2=470047
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/FileManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/FileManagerImpl.java Wed Nov  1
11:36:29 2006
@@ -150,15 +150,20 @@
                          InputStream is)
             throws FileNotFoundException, FilePathException, FileIOException {
         
+        String savePath = path;
+        if(path.startsWith("/")) {
+            savePath = path.substring(1);
+        }
+        
         // make sure we are allowed to save this file
         RollerMessages msgs = new RollerMessages();
-        if (!canSave(weblog, path, contentType, size, msgs)) {
+        if (!canSave(weblog, savePath, contentType, size, msgs)) {
             throw new FileIOException(msgs.toString());
         }
         
         // make sure uploads area exists for this weblog
         File dirPath = this.getRealFile(weblog, null);
-        File saveFile = new File(dirPath.getAbsolutePath() + File.separator + path);
+        File saveFile = new File(dirPath.getAbsolutePath() + File.separator + savePath);
         
         byte[] buffer = new byte[8192];
         int bytesRead = 0;
@@ -192,13 +197,18 @@
         // get path to weblog's uploads area
         File weblogDir = this.getRealFile(weblog, null);
         
-        if(path != null && path.indexOf('/') != -1) {
+        String savePath = path;
+        if(path.startsWith("/")) {
+            savePath = path.substring(1);
+        }
+        
+        if(savePath != null && savePath.indexOf('/') != -1) {
             throw new FilePathException("Invalid path ["+path+"], "+
                         "trying to use nested directories.");
         }
         
         // now construct path to new directory
-        File dir = new File(weblogDir.getAbsolutePath() + File.separator + path);
+        File dir = new File(weblogDir.getAbsolutePath() + File.separator + savePath);
         
         // check if it already exists
         if(dir.exists() && dir.isDirectory() && dir.canRead()) {

Modified: incubator/roller/trunk/src/org/apache/roller/business/ThemeManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/ThemeManagerImpl.java?view=diff&rev=470047&r1=470046&r2=470047
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/ThemeManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/ThemeManagerImpl.java Wed Nov  1
11:36:29 2006
@@ -228,6 +228,11 @@
                 String path = resourceFile.getAbsolutePath().substring(
                         this.themeDir.length()+theme.getName().length()+1);
                 
+                // make sure path isn't prefixed with a /
+                if(path.startsWith("/")) {
+                    path = path.substring(1);
+                }
+                
                 log.debug("Importing resource "+resourceFile.getAbsolutePath()+" to "+path);
                 
                 try {



Mime
View raw message