feat: ensure .venv and archive folders are ignored during model scanning and cleanup
This commit is contained in:
@@ -1298,6 +1298,10 @@ public class Main extends JFrame {
|
||||
|
||||
List<Path> allFiles = Files.walk(root.toPath())
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(p -> {
|
||||
String relPath = root.toPath().relativize(p).toString().toLowerCase();
|
||||
return !relPath.contains(".venv") && !relPath.contains("archive");
|
||||
})
|
||||
.filter(p -> {
|
||||
String n = p.getFileName().toString().toLowerCase();
|
||||
return n.endsWith(".safetensors") || n.endsWith(".sft") || n.endsWith(".ckpt") || n.endsWith(".pth") || n.endsWith(".pt") || n.endsWith(".bin");
|
||||
|
||||
@@ -44,6 +44,7 @@ public class CleanupService implements ICleanupService {
|
||||
try (Stream<Path> walk = Files.walk(root)) {
|
||||
List<Path> candidates = walk.filter(Files::isRegularFile)
|
||||
.filter(this::isSupportedModel)
|
||||
.filter(p -> !isIgnored(p, root))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (Path p : candidates) {
|
||||
@@ -67,6 +68,22 @@ public class CleanupService implements ICleanupService {
|
||||
return unused;
|
||||
}
|
||||
|
||||
private boolean isIgnored(Path path, Path rootPath) {
|
||||
int rootCount = rootPath.getNameCount();
|
||||
for (int i = rootCount; i < path.getNameCount(); i++) {
|
||||
String part = path.getName(i).toString().toLowerCase();
|
||||
if (part.equals("archive") || part.equals(".venv")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isSupportedModel(Path p) {
|
||||
String n = p.getFileName().toString().toLowerCase();
|
||||
return n.endsWith(".safetensors") || n.endsWith(".ckpt") || n.endsWith(".pt") || n.endsWith(".pth") || n.endsWith(".bin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void archiveModels(List<ModelInfo> models, BiConsumer<Integer, String> onStatusUpdate, Runnable onFinished) {
|
||||
new Thread(() -> {
|
||||
@@ -85,11 +102,6 @@ public class CleanupService implements ICleanupService {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private boolean isSupportedModel(Path p) {
|
||||
String n = p.getFileName().toString().toLowerCase();
|
||||
return n.endsWith(".safetensors") || n.endsWith(".ckpt") || n.endsWith(".pt") || n.endsWith(".pth") || n.endsWith(".bin");
|
||||
}
|
||||
|
||||
private ModelInfo createInfo(Path p, Path root, BasicFileAttributes attrs) {
|
||||
ModelInfo info = new ModelInfo();
|
||||
info.setName(p.getFileName().toString());
|
||||
|
||||
@@ -53,7 +53,7 @@ public class LocalModelScanner {
|
||||
List<Path> files = walk
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(this::isSupportedModelFile)
|
||||
.filter(p -> !isArchived(p, rootPath))
|
||||
.filter(p -> !isIgnored(p, rootPath))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (Path file : files) {
|
||||
@@ -91,7 +91,7 @@ public class LocalModelScanner {
|
||||
|
||||
try (Stream<Path> walk = Files.walk(root)) {
|
||||
List<Path> matches = walk.filter(Files::isRegularFile)
|
||||
.filter(p -> !isArchived(p, root))
|
||||
.filter(p -> !isIgnored(p, root))
|
||||
.filter(p -> p.getFileName().toString().equalsIgnoreCase(filename))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -119,7 +119,7 @@ public class LocalModelScanner {
|
||||
return name.endsWith(".safetensors") || name.endsWith(".ckpt") || name.endsWith(".pt");
|
||||
}
|
||||
|
||||
private boolean isArchived(Path path, Path rootPath) {
|
||||
private boolean isIgnored(Path path, Path rootPath) {
|
||||
// 1. If we are already searching inside an archive folder (e.g. E:\Archive),
|
||||
// we should not filter out anything based on the "archive" name.
|
||||
String rootName = rootPath.getFileName() != null ? rootPath.getFileName().toString().toLowerCase() : "";
|
||||
@@ -138,10 +138,11 @@ public class LocalModelScanner {
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
// 3. Fallback: ignore any subfolder named "archive"
|
||||
// 3. Fallback: ignore any subfolder named "archive" or ".venv"
|
||||
int rootCount = rootPath.getNameCount();
|
||||
for (int i = rootCount; i < path.getNameCount(); i++) {
|
||||
if (path.getName(i).toString().equalsIgnoreCase("archive")) {
|
||||
String part = path.getName(i).toString().toLowerCase();
|
||||
if (part.equals("archive") || part.equals(".venv")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user