Skip to content

Commit 9425e9d

Browse files
committed
Fix subfolder race condition.
1 parent 3b89405 commit 9425e9d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

xivModdingFramework/Helpers/IOUtil.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -799,17 +799,21 @@ public static byte[] GetImageSharpPixels(Image<Rgba32> img)
799799

800800
public static string GetUniqueSubfolder(string basePath, string prefix = "")
801801
{
802-
var id = 0;
803-
var path = Path.GetFullPath(Path.Combine(basePath, prefix + id.ToString()));
804-
while (Directory.Exists(path))
802+
lock (_SubfolderLock)
805803
{
806-
id++;
807-
path = Path.GetFullPath(Path.Combine(basePath, prefix + id.ToString()));
804+
var id = 0;
805+
var path = Path.GetFullPath(Path.Combine(basePath, prefix + id.ToString()));
806+
while (Directory.Exists(path))
807+
{
808+
id++;
809+
path = Path.GetFullPath(Path.Combine(basePath, prefix + id.ToString()));
810+
}
811+
Directory.CreateDirectory(path);
812+
return path;
808813
}
809-
Directory.CreateDirectory(path);
810-
811-
return path;
812814
}
815+
816+
public static object _SubfolderLock = new object();
813817
public static string GetFrameworkTempSubfolder(string prefix = "")
814818
{
815819
var basePath = GetFrameworkTempFolder();

0 commit comments

Comments
 (0)