integer so unsafe!!! i need HEX!
This commit is contained in:
parent
e33554f369
commit
91c526a35f
2 changed files with 20 additions and 6 deletions
|
|
@ -28,8 +28,8 @@ public class Utils
|
||||||
}
|
}
|
||||||
|
|
||||||
int hash = id.GetHashCode();
|
int hash = id.GetHashCode();
|
||||||
if (hash < 0) hash = -hash; // Or use Math.Abs, but hash < 0 logic avoids OverflowException on int.MinValue
|
int index = (hash & 0x7FFFFFFF) % _userLocksArray.Length;
|
||||||
return _userLocksArray[hash % _userLocksArray.Length];
|
return _userLocksArray[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetIdFromUsernameWD(string usernameWD)
|
public static string GetIdFromUsernameWD(string usernameWD)
|
||||||
|
|
@ -111,6 +111,10 @@ public class Utils
|
||||||
|
|
||||||
public static async Task<string> IdFromName(string name)
|
public static async Task<string> IdFromName(string name)
|
||||||
{
|
{
|
||||||
|
if (name == null || !IsValidUsername(name, out _))
|
||||||
|
{
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
string path = $"{ACCOUNTS_NAME_DIR}/{name.ToLowerInvariant()}";
|
string path = $"{ACCOUNTS_NAME_DIR}/{name.ToLowerInvariant()}";
|
||||||
if (!Fs.Exists(path))
|
if (!Fs.Exists(path))
|
||||||
{
|
{
|
||||||
|
|
@ -288,6 +292,10 @@ public class Utils
|
||||||
|
|
||||||
public static async Task<byte[]> GetUserPublicStorageEntry(string id, string entry)
|
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}";
|
string path = $"{ACCOUNTS_DATA_DIR}/{id}/storage/public/{entry}";
|
||||||
if (!Fs.Exists(path))
|
if (!Fs.Exists(path))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ public class Fs
|
||||||
}
|
}
|
||||||
|
|
||||||
int hash = path.GetHashCode();
|
int hash = path.GetHashCode();
|
||||||
if (hash < 0) hash = -hash; // Or use Math.Abs, but hash < 0 logic avoids OverflowException on int.MinValue
|
int index = (hash & 0x7FFFFFFF) % _fileLocksArray.Length;
|
||||||
return _fileLocksArray[hash % _fileLocksArray.Length];
|
return _fileLocksArray[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ProcessCacheSpace()
|
public static void ProcessCacheSpace()
|
||||||
|
|
@ -207,8 +207,11 @@ public class Fs
|
||||||
|
|
||||||
sem1.Wait();
|
sem1.Wait();
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if (!ReferenceEquals(sem1, sem2))
|
||||||
{
|
{
|
||||||
sem2.Wait();
|
sem2.Wait();
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Move(path, newPath);
|
File.Move(path, newPath);
|
||||||
|
|
@ -219,10 +222,13 @@ public class Fs
|
||||||
InvalidateDirCacheFor(newPath);
|
InvalidateDirCacheFor(newPath);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
{
|
||||||
|
if (!ReferenceEquals(sem1, sem2))
|
||||||
{
|
{
|
||||||
sem2.Release();
|
sem2.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
sem1.Release();
|
sem1.Release();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue