Skip to content

Commit f9d7c30

Browse files
committed
skip dotfiles in history and model folders
for #1112
1 parent ee54a67 commit f9d7c30

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Text2Image/T2IModelHandler.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,18 @@ public void AddAllFromFolder(string pathBase, string folder)
757757
}
758758
Parallel.ForEach(Directory.EnumerateDirectories(actualFolder), subfolder =>
759759
{
760-
string path = $"{prefix}{subfolder.Replace('\\', '/').AfterLast('/')}";
761-
if (path.AfterLast('/') == ".git")
760+
string simpleName = subfolder.Replace('\\', '/').AfterLast('/');
761+
string path = $"{prefix}{simpleName}";
762+
if (simpleName == ".git")
762763
{
763764
Logs.Warning($"You have a .git folder in your {ModelType} model folder '{pathBase}/{path}'! That's not supposed to be there.");
764765
return;
765766
}
767+
if (simpleName.StartsWithFast('.'))
768+
{
769+
Logs.Verbose($"[Model Scan] Skipping hidden folder {subfolder}");
770+
return;
771+
}
766772
try
767773
{
768774
AddAllFromFolder(pathBase, path);
@@ -780,6 +786,11 @@ public void AddAllFromFolder(string pathBase, string folder)
780786
{
781787
string fixedFileName = file.Replace('\\', '/');
782788
string fn = fixedFileName.AfterLast('/');
789+
if (fn.StartsWithFast('.'))
790+
{
791+
Logs.Verbose($"[Model Scan] Skipping hidden file {fixedFileName}");
792+
return;
793+
}
783794
string fullFilename = $"{prefix}{fn}";
784795
if (Models.TryGetValue(fullFilename, out T2IModel existingModel))
785796
{

src/WebAPI/T2IAPI.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ void addDirs(string dir, int subDepth)
536536
IEnumerable<string> subDirs = Directory.EnumerateDirectories(actualPath).Select(Path.GetFileName).OrderDescending();
537537
foreach (string subDir in subDirs)
538538
{
539+
if (subDir.StartsWithFast('.'))
540+
{
541+
continue;
542+
}
539543
string subPath = dir == "" ? subDir : $"{dir}/{subDir}";
540544
if (isAllowed(subPath))
541545
{
@@ -606,7 +610,7 @@ void sortList(List<ImageHistoryHelper> list)
606610
return;
607611
}
608612
List<string> subFiles = [.. Directory.EnumerateFiles(actualPath).Take(localLimit)];
609-
IEnumerable<string> newFileNames = subFiles.Where(isAllowed).Where(f => extensions.Contains(f.AfterLast('.')) && !f.EndsWith(".swarmpreview.jpg") && !f.EndsWith(".swarmpreview.webp")).Select(f => f.Replace('\\', '/'));
613+
IEnumerable<string> newFileNames = subFiles.Select(f => f.Replace('\\', '/')).Where(isAllowed).Where(f => !f.AfterLast('/').StartsWithFast('.') && extensions.Contains(f.AfterLast('.')) && !f.EndsWith(".swarmpreview.jpg") && !f.EndsWith(".swarmpreview.webp"));
610614
List<ImageHistoryHelper> localFiles = [.. newFileNames.Select(f => new ImageHistoryHelper(prefix + f.AfterLast('/'), OutputMetadataTracker.GetMetadataFor(f, root, starNoFolders))).Where(f => f.Metadata is not null)];
611615
int leftOver = Interlocked.Add(ref remaining, -localFiles.Count);
612616
sortList(localFiles);

0 commit comments

Comments
 (0)