1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:42:54 +08:00

Rename max length variable to make sense (it's a filename limit, not path)

This commit is contained in:
Dean Herbert 2023-02-17 13:33:22 +09:00
parent 415220a447
commit 96b1498932
2 changed files with 14 additions and 12 deletions

View File

@ -30,7 +30,7 @@ namespace osu.Game.Tests.Database
const string filename = "normal file name";
var item = new TestPathInfo(filename);
Assert.That(item.Filename.Length < TestLegacyExporter.GetMaxPath(), Is.True);
Assert.That(item.Filename.Length, Is.LessThan(TestLegacyExporter.GetMaxPathLength()));
exportItemAndAssert(item, exportStorage, filename);
}
@ -42,7 +42,7 @@ namespace osu.Game.Tests.Database
const string filename = "normal file name";
var item = new TestPathInfo(filename);
Assert.That(item.Filename.Length < TestLegacyExporter.GetMaxPath(), Is.True);
Assert.That(item.Filename.Length < TestLegacyExporter.GetMaxPathLength(), Is.True);
//Export multiple times
for (int i = 0; i < 10; i++)
@ -60,12 +60,12 @@ namespace osu.Game.Tests.Database
const string fullname =
"some file with super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name";
int expectedLength = TestLegacyExporter.GetMaxPath() - (legacyExporter.GetExtension().Length);
int expectedLength = TestLegacyExporter.GetMaxPathLength() - (legacyExporter.GetExtension().Length);
string expectedName = fullname.Remove(expectedLength);
var item = new TestPathInfo(fullname);
Assert.That(item.Filename.Length > TestLegacyExporter.GetMaxPath(), Is.True);
Assert.That(item.Filename.Length > TestLegacyExporter.GetMaxPathLength(), Is.True);
exportItemAndAssert(item, exportStorage, expectedName);
}
@ -77,12 +77,12 @@ namespace osu.Game.Tests.Database
const string fullname =
"some file with super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name super long name";
int expectedLength = TestLegacyExporter.GetMaxPath() - (legacyExporter.GetExtension().Length);
int expectedLength = TestLegacyExporter.GetMaxPathLength() - (legacyExporter.GetExtension().Length);
string expectedName = fullname.Remove(expectedLength);
var item = new TestPathInfo(fullname);
Assert.That(item.Filename.Length > TestLegacyExporter.GetMaxPath(), Is.True);
Assert.That(item.Filename.Length > TestLegacyExporter.GetMaxPathLength(), Is.True);
//Export multiple times
for (int i = 0; i < 10; i++)
@ -123,7 +123,7 @@ namespace osu.Game.Tests.Database
{
}
public static int GetMaxPath() => MAX_PATH;
public static int GetMaxPathLength() => MAX_FILENAME_LENGTH;
public string GetExtension() => FileExtension;

View File

@ -21,12 +21,14 @@ namespace osu.Game.Database
where TModel : class, IHasNamedFiles
{
/// <summary>
/// Max length of filename (including extension)
/// Max length of filename (including extension).
/// </summary>
/// <remarks>
/// This constant is smaller 256 because <see cref="Storage.CreateFileSafely(string)"/> adds additional "_<see cref="Guid"/>" to the end of the path
/// TODO: WHY? DOCUMENTATION PER PLATFORM LINKS HERE.
///
/// This actual usable length is smaller 256 because <see cref="Storage.CreateFileSafely(string)"/> adds additional "_<see cref="Guid"/>" to the end of the path
/// </remarks>
protected const int MAX_PATH = 255 - (32 + 4 + 2); //max path - (Guid + Guid "D" format chars + Storage.CreateFileSafely chars)
protected const int MAX_FILENAME_LENGTH = 255 - (32 + 4 + 2); //max path - (Guid + Guid "D" format chars + Storage.CreateFileSafely chars)
/// <summary>
/// The file extension for exports (including the leading '.').
@ -60,11 +62,11 @@ namespace osu.Game.Database
string filename = NamingUtils.GetNextBestFilename(existingExports, $"{itemFilename}{FileExtension}");
if (filename.Length > MAX_PATH)
if (filename.Length > MAX_FILENAME_LENGTH)
{
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(filename);
filenameWithoutExtension = filenameWithoutExtension.Remove(MAX_PATH - FileExtension.Length); //Truncating the name to fit the path limit
filenameWithoutExtension = filenameWithoutExtension.Remove(MAX_FILENAME_LENGTH - FileExtension.Length); //Truncating the name to fit the path limit
filename = $"{filenameWithoutExtension}{FileExtension}";
}