Skip to content

Commit

Permalink
fix(): remove windows letter from path
Browse files Browse the repository at this point in the history
  • Loading branch information
Skraye committed Jul 30, 2024
1 parent dd4cae2 commit f9ac2a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/io/kestra/core/storages/Namespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,17 +84,17 @@ default List<NamespaceFile> findAllFilesMatching(List<String> includes, List<Str
*/
InputStream getFileContent(Path path) throws IOException;

default NamespaceFile putFile(Path path, InputStream content) throws IOException {
default NamespaceFile putFile(Path path, InputStream content) throws IOException, URISyntaxException {
return putFile(path, content, Conflicts.OVERWRITE);
}

NamespaceFile putFile(Path path, InputStream content, Conflicts onAlreadyExist) throws IOException;
NamespaceFile putFile(Path path, InputStream content, Conflicts onAlreadyExist) throws IOException, URISyntaxException;

default NamespaceFile putFile(NamespaceFile file, InputStream content) throws IOException {
default NamespaceFile putFile(NamespaceFile file, InputStream content) throws IOException, URISyntaxException {
return putFile(file, content, Conflicts.OVERWRITE);
}

default NamespaceFile putFile(NamespaceFile file, InputStream content, Conflicts onAlreadyExist) throws IOException {
default NamespaceFile putFile(NamespaceFile file, InputStream content, Conflicts onAlreadyExist) throws IOException, URISyntaxException {
return putFile(Path.of(file.path()), content, onAlreadyExist);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f9ac2a2

Please sign in to comment.