diff --git a/core/src/main/java/io/kestra/core/storages/InternalNamespace.java b/core/src/main/java/io/kestra/core/storages/InternalNamespace.java index 4bf7f33dcc..d0826aff0b 100644 --- a/core/src/main/java/io/kestra/core/storages/InternalNamespace.java +++ b/core/src/main/java/io/kestra/core/storages/InternalNamespace.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Path; import java.util.List; import java.util.Objects; @@ -125,13 +126,15 @@ public InputStream getFileContent(final Path path) throws IOException { * {@inheritDoc} **/ @Override - public NamespaceFile putFile(final Path path, final InputStream content, final Conflicts onAlreadyExist) throws IOException { + public NamespaceFile putFile(final Path path, final InputStream content, final Conflicts onAlreadyExist) throws IOException, URISyntaxException { Path namespaceFilesPrefix = NamespaceFile.of(namespace, path).storagePath(); - final boolean exists = storage.exists(tenant, namespaceFilesPrefix.toUri()); + // Remove Windows letter + URI cleanUri = new URI(namespaceFilesPrefix.toUri().toString().replaceFirst("^file:///[a-zA-Z]:", "")); + final boolean exists = storage.exists(tenant, cleanUri); return switch (onAlreadyExist) { case OVERWRITE -> { - URI uri = storage.put(tenant, namespaceFilesPrefix.toUri(), content); + URI uri = storage.put(tenant, cleanUri, content); NamespaceFile namespaceFile = new NamespaceFile(relativize(uri), uri, namespace); if (exists) { logger.debug(String.format( diff --git a/core/src/main/java/io/kestra/core/storages/Namespace.java b/core/src/main/java/io/kestra/core/storages/Namespace.java index c7162d79f3..bf381ba2a9 100644 --- a/core/src/main/java/io/kestra/core/storages/Namespace.java +++ b/core/src/main/java/io/kestra/core/storages/Namespace.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Path; import java.util.List; import java.util.function.Predicate; @@ -83,17 +84,17 @@ default List findAllFilesMatching(List includes, List uri = FileUtils.getURI(file.toString()); // Immediately handle strings that are full URI - if (uri.isPresent()) { - if (runContext.storage().isFileExist(uri.get())) { + try { + + if (uri.isPresent() && runContext.storage().isFileExist(uri.get())) { Path targetFilePath = Path.of(renderedDestination, FileUtils.getFileName(uri.get())); storageNamespace.putFile(targetFilePath, runContext.storage().getFile(uri.get()), conflict); + } else { + regexs.add(file.toString()); } - // else ignore - } else { + } + // If the string is not a valid URI, try to use it as a regex + catch (InvalidPathException | NullPointerException e) { + runContext.logger().debug("File {} is not a valid URI, using it as a regex", file); regexs.add(file.toString()); } } diff --git a/core/src/test/java/io/kestra/core/storages/InternalNamespaceTest.java b/core/src/test/java/io/kestra/core/storages/InternalNamespaceTest.java index e1e605b016..c755d0b162 100644 --- a/core/src/test/java/io/kestra/core/storages/InternalNamespaceTest.java +++ b/core/src/test/java/io/kestra/core/storages/InternalNamespaceTest.java @@ -12,6 +12,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -35,7 +36,7 @@ public void setUp() throws IOException { } @Test - void shouldGetAllNamespaceFiles() throws IOException { + void shouldGetAllNamespaceFiles() throws IOException, URISyntaxException { // Given final String namespaceId = "io.kestra." + IdUtils.create(); final InternalNamespace namespace = new InternalNamespace(logger, null, namespaceId, storageInterface); @@ -54,7 +55,7 @@ void shouldGetAllNamespaceFiles() throws IOException { } @Test - void shouldPutFileGivenNoTenant() throws IOException { + void shouldPutFileGivenNoTenant() throws IOException, URISyntaxException { // Given final String namespaceId = "io.kestra." + IdUtils.create(); final InternalNamespace namespace = new InternalNamespace(logger, null, namespaceId, storageInterface); @@ -71,7 +72,7 @@ void shouldPutFileGivenNoTenant() throws IOException { } @Test - void shouldSucceedPutFileGivenExistingFileForConflictOverwrite() throws IOException { + void shouldSucceedPutFileGivenExistingFileForConflictOverwrite() throws IOException, URISyntaxException { // Given final String namespaceId = "io.kestra." + IdUtils.create(); final InternalNamespace namespace = new InternalNamespace(logger, null, namespaceId, storageInterface); @@ -90,7 +91,7 @@ void shouldSucceedPutFileGivenExistingFileForConflictOverwrite() throws IOExcept } @Test - void shouldFailPutFileGivenExistingFileForError() throws IOException { + void shouldFailPutFileGivenExistingFileForError() throws IOException, URISyntaxException { // Given final String namespaceId = "io.kestra." + IdUtils.create(); final InternalNamespace namespace = new InternalNamespace(logger, null, namespaceId, storageInterface); @@ -107,7 +108,7 @@ void shouldFailPutFileGivenExistingFileForError() throws IOException { } @Test - void shouldIgnorePutFileGivenExistingFileForSkip() throws IOException { + void shouldIgnorePutFileGivenExistingFileForSkip() throws IOException, URISyntaxException { // Given final String namespaceId = "io.kestra." + IdUtils.create(); final InternalNamespace namespace = new InternalNamespace(logger, null, namespaceId, storageInterface); @@ -126,7 +127,7 @@ void shouldIgnorePutFileGivenExistingFileForSkip() throws IOException { } @Test - void shouldFindAllMatchingGivenNoTenant() throws IOException { + void shouldFindAllMatchingGivenNoTenant() throws IOException, URISyntaxException { // Given final String namespaceId = "io.kestra." + IdUtils.create(); final InternalNamespace namespace = new InternalNamespace(logger, null, namespaceId, storageInterface); @@ -153,7 +154,7 @@ void shouldFindAllMatchingGivenNoTenant() throws IOException { } @Test - void shouldFindAllGivenTenant() throws IOException { + void shouldFindAllGivenTenant() throws IOException, URISyntaxException { // Given final String namespaceId = "io.kestra." + IdUtils.create(); final InternalNamespace namespaceTenant1 = new InternalNamespace(logger, "tenant1", namespaceId, storageInterface);