Skip to content

Commit

Permalink
fix(core): Namespace file changes for git tasks (#5784)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skraye authored Nov 5, 2024
1 parent 681466c commit b79b1cb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ public URI createDirectory(Path path) throws IOException {
**/
@Override
public boolean delete(Path path) throws IOException {
return storage.delete(tenant, NamespaceFile.of(namespace, path).storagePath().toUri());
return storage.delete(tenant, URI.create(path.toString().replace("\\","/")));
}
}
12 changes: 9 additions & 3 deletions core/src/main/java/io/kestra/core/utils/WindowsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@

public class WindowsUtils {

public static String windowsToUnixPath(String path){
public static String windowsToUnixPath(String path, boolean startWithSlash) {
Matcher matcher = java.util.regex.Pattern.compile("([A-Za-z]:)").matcher(path);
String unixPath = matcher.replaceAll(m -> m.group().toLowerCase());

unixPath = unixPath
.replace("\\", "/")
.replace(":", "");
if (!unixPath.startsWith("/")) {
if (!unixPath.startsWith("/") && startWithSlash) {
unixPath = "/" + unixPath;
}
return unixPath;
}

public static String windowsToUnixPath(String path) {
return windowsToUnixPath(path, true);
}

public static URI windowsToUnixURI(URI uri) {
return URI.create(windowsToUnixPath(uri.toString()));

return URI.create(windowsToUnixPath(uri.toString(), false));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.slf4j.Logger;

import java.net.URI;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -103,7 +104,7 @@ public Output run(RunContext runContext) throws Exception {
long count = matched
.stream()
.map(Rethrow.throwFunction(file -> {
if (namespace.delete(file)) {
if (namespace.delete(NamespaceFile.of(renderedNamespace, Path.of(file.path().replace("\\","/"))).storagePath())) {
logger.debug(String.format("Deleted %s", (file.path())));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.kestra.core.storages.StorageInterface;
import io.kestra.core.tenant.TenantService;
import io.kestra.core.utils.Rethrow;
import io.kestra.core.utils.WindowsUtils;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
Expand Down

0 comments on commit b79b1cb

Please sign in to comment.