33 lines
1.1 KiB
Java
33 lines
1.1 KiB
Java
package io.gitlab.jfronny.resclone.processors;
|
|
|
|
import io.gitlab.jfronny.resclone.io.PathPruneVisitor;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.DirectoryStream;
|
|
import java.nio.file.FileSystem;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
public class RemoveEmptyProcessor extends PackProcessor {
|
|
|
|
@Override
|
|
public void process(FileSystem p) throws Exception {
|
|
if (Files.exists(p.getPath("/assets"))) {
|
|
try {
|
|
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
|
if (Files.isDirectory(s)) {
|
|
try (DirectoryStream<Path> paths = Files.newDirectoryStream(s)) {
|
|
return !paths.iterator().hasNext();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return false;
|
|
}));
|
|
} catch (Throwable e) {
|
|
throw new Exception("Failed to prune empty directories", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
} |