Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

31 changes: 14 additions & 17 deletions application/src/main/java/run/halo/app/infra/utils/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package run.halo.app.infra.utils;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.springframework.core.io.buffer.DataBufferUtils.subscriberInputStream;
import static org.springframework.util.FileSystemUtils.deleteRecursively;
import static run.halo.app.infra.utils.DataBufferUtils.toInputStream;

import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -51,18 +51,15 @@ public static Mono<Void> unzip(Publisher<DataBuffer> content, @NonNull Path targ

public static Mono<Void> unzip(Publisher<DataBuffer> content, @NonNull Path targetPath,
Scheduler scheduler) {
return Mono.usingWhen(
toInputStream(content, scheduler),
is -> {
try (var zis = new ZipInputStream(is)) {
unzip(zis, targetPath);
return Mono.empty();
} catch (IOException e) {
return Mono.error(e);
}
},
is -> Mono.fromRunnable(() -> closeQuietly(is))
);
return Mono.fromCallable(() -> {
try (var is = subscriberInputStream(content, 1);
var zis = new ZipInputStream(is)) {
log.debug("Unzipping to target path: {}", targetPath);
unzip(zis, targetPath);
log.debug("Unzipped to target path: {}", targetPath);
}
return null;
}).subscribeOn(scheduler).then();
}

public static void unzip(@NonNull ZipInputStream zis, @NonNull Path targetPath)
Expand Down Expand Up @@ -195,7 +192,7 @@ public static void closeQuietly(final Closeable closeable) {
* the given {@code consumer}.
*
* @param closeable The resource to close, may be null.
* @param consumer Consumes the IOException thrown by {@link Closeable#close()}.
* @param consumer Consumes the IOException thrown by {@link Closeable#close()}.
*/
public static void closeQuietly(final Closeable closeable,
final Consumer<IOException> consumer) {
Expand All @@ -213,7 +210,7 @@ public static void closeQuietly(final Closeable closeable,
/**
* Checks directory traversal vulnerability.
*
* @param parentPath parent path must not be null.
* @param parentPath parent path must not be null.
* @param pathToCheck path to check must not be null
*/
public static void checkDirectoryTraversal(@NonNull Path parentPath,
Expand All @@ -232,7 +229,7 @@ public static void checkDirectoryTraversal(@NonNull Path parentPath,
/**
* Checks directory traversal vulnerability.
*
* @param parentPath parent path must not be null.
* @param parentPath parent path must not be null.
* @param pathToCheck path to check must not be null
*/
public static void checkDirectoryTraversal(@NonNull String parentPath,
Expand All @@ -243,7 +240,7 @@ public static void checkDirectoryTraversal(@NonNull String parentPath,
/**
* Checks directory traversal vulnerability.
*
* @param parentPath parent path must not be null.
* @param parentPath parent path must not be null.
* @param pathToCheck path to check must not be null
*/
public static void checkDirectoryTraversal(@NonNull Path parentPath,
Expand Down
Loading