Compare commits

..

No commits in common. "32f770c8cedf24eac547b2709fbd10b8c0d77b1b" and "e5eae209b138c67e1bde64adfd9410217f98d296" have entirely different histories.

2 changed files with 6 additions and 20 deletions

View file

@ -28,8 +28,8 @@ public class Utils
}
int hash = id.GetHashCode();
int index = (hash & 0x7FFFFFFF) % _userLocksArray.Length;
return _userLocksArray[index];
if (hash < 0) hash = -hash; // Or use Math.Abs, but hash < 0 logic avoids OverflowException on int.MinValue
return _userLocksArray[hash % _userLocksArray.Length];
}
public static string GetIdFromUsernameWD(string usernameWD)
@ -111,10 +111,6 @@ public class Utils
public static async Task<string> IdFromName(string name)
{
if (name == null || !IsValidUsername(name, out _))
{
return "0";
}
string path = $"{ACCOUNTS_NAME_DIR}/{name.ToLowerInvariant()}";
if (!Fs.Exists(path))
{
@ -292,10 +288,6 @@ public class Utils
public static async Task<byte[]> GetUserPublicStorageEntry(string id, string entry)
{
if (string.IsNullOrEmpty(entry) || entry.Contains("..") || entry.Contains("/") || entry.Contains("\\"))
{
return new byte[] {};
}
string path = $"{ACCOUNTS_DATA_DIR}/{id}/storage/public/{entry}";
if (!Fs.Exists(path))
{

View file

@ -31,8 +31,8 @@ public class Fs
}
int hash = path.GetHashCode();
int index = (hash & 0x7FFFFFFF) % _fileLocksArray.Length;
return _fileLocksArray[index];
if (hash < 0) hash = -hash; // Or use Math.Abs, but hash < 0 logic avoids OverflowException on int.MinValue
return _fileLocksArray[hash % _fileLocksArray.Length];
}
public static void ProcessCacheSpace()
@ -207,11 +207,8 @@ public class Fs
sem1.Wait();
try
{
if (!ReferenceEquals(sem1, sem2))
{
sem2.Wait();
}
try
{
File.Move(path, newPath);
@ -222,13 +219,10 @@ public class Fs
InvalidateDirCacheFor(newPath);
}
finally
{
if (!ReferenceEquals(sem1, sem2))
{
sem2.Release();
}
}
}
finally
{
sem1.Release();