]> source.dussan.org Git - archiva.git/commitdiff
Change configuration to handle windows path restriction
authorEric Barboni <skygo@apache.org>
Mon, 17 Feb 2020 14:25:42 +0000 (15:25 +0100)
committerMartin <m.stockhammer@web.de>
Mon, 17 Feb 2020 21:49:18 +0000 (22:49 +0100)
archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/util/PathMatcher.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java

index 97777d051a438826378ca5b9e3d7744e3fb86aed..11ae70569aa959f88d54cebe0b66b7a14e20ccc8 100644 (file)
@@ -46,6 +46,7 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.IOException;
 import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.*;
@@ -553,10 +554,9 @@ public class DefaultArchivaConfiguration
      * @param contents the contents to write.
      * @return true if write successful.
      */
-    private boolean writeFile(String filetype, String path, String contents, boolean createDirs) {
-        Path file = Paths.get(path);
-
+    private boolean writeFile(String filetype, String path, String contents, boolean createDirs) {                
         try {
+            Path file = Paths.get(path);
             // Check parent directory (if it is declared)
             final Path parent = file.getParent();
             if (parent != null) {
@@ -574,6 +574,9 @@ public class DefaultArchivaConfiguration
         } catch (IOException e) {
             log.error("Unable to create {} file: {}", filetype, e.getMessage(), e);
             return false;
+        } catch (InvalidPathException ipe) {
+            log.error("Unable to read {} file: {}", path, ipe.getMessage(), ipe);
+            return false;
         }
     }
 
index 2e77b38a0d9ef066b231bef1cf068803794a8d27..11e5ed51961af4b9f42a7b3574f6ec7a24c0a7d7 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.archiva.configuration.util;
  */
 
 import java.io.File;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
@@ -226,8 +227,8 @@ public class PathMatcher
      *         or <code>false</code> otherwise.
      */
     public static boolean matchPath(String pattern, String str) {
-        String[] patDirs = tokenizePathAsArray(pattern);
-        return matchPath(patDirs, tokenizePathAsArray(str), true);
+        String[] patDirs = tokenizePathAsArray( pattern, false );
+        return matchPath(patDirs, tokenizePathAsArray( str, true ), true);
     }
 
     /**
@@ -248,20 +249,30 @@ public class PathMatcher
      */
     public static boolean matchPath(String pattern, String str,
                                     boolean isCaseSensitive) {
-        String[] patDirs = tokenizePathAsArray(pattern);
-        return matchPath(patDirs, tokenizePathAsArray(str), isCaseSensitive);
+        String[] patDirs = tokenizePathAsArray( pattern, false );
+        return matchPath(patDirs, tokenizePathAsArray( str, false ), isCaseSensitive);
     }
 
-
-    static String[] tokenizePathAsArray(String path) {
+    /**
+     * 
+     * @param path
+     * @param osspecific
+     * @return
+     */
+    static String[] tokenizePathAsArray(String path, boolean osSpecific) {
         Path root = null;
-        Path fsPath = Paths.get( path );
-
-        if ( fsPath.isAbsolute()) {
-            root = fsPath.getRoot( );
-            path = root.relativize( fsPath ).toString();
+        try 
+        {
+            Path fsPath = Paths.get( path );
+            if ( fsPath.isAbsolute() ) {
+                root = fsPath.getRoot();
+                path = root.relativize( fsPath ).toString();
+            }
+        } catch (InvalidPathException ipe ) 
+        {
+            // invalid path, windauze hate **/* 
         }
-        char sep = File.separatorChar;
+        char sep = osSpecific ? File.separatorChar : '/';
         int start = 0;
         int len = path.length();
         int count = 0;
index 625c4574a5230692a4582fd03142c73b0ee14705..8dfcdb22d757f9e516ee477c6aa0cc2bedfca248 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.archiva.consumers.core.repository;
  * under the License.
  */
 
+import java.io.File;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
@@ -163,7 +164,8 @@ public abstract class AbstractRepositoryPurgeTest
         atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER) );
         String path = AbstractRepositoryPurgeTest.fixPath(
             basePath.resolve( repoId ).toAbsolutePath().toString() );
-        config.setLocation( new URI( path ) );
+        File file = new File( path );
+        config.setLocation( file.toURI() );
         atf.setDeleteReleasedSnapshots( true );
         atf.setRetentionCount( TEST_RETENTION_COUNT );