mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 15:27:20 +08:00
Reduce the allowed length by 5 to account for (99) suffix. Move truncating logic to GetFilename
. Update tests.
This commit is contained in:
parent
5fa75805cc
commit
90aa4288d0
@ -46,7 +46,7 @@ namespace osu.Game.Tests.Database
|
||||
Assert.That(item.Filename.Length, Is.LessThan(TestLegacyExporter.MAX_FILENAME_LENGTH));
|
||||
|
||||
//Export multiple times
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
string expectedFileName = i == 0 ? short_filename : $"{short_filename} ({i})";
|
||||
exportItemAndAssert(item, expectedFileName);
|
||||
@ -76,8 +76,11 @@ namespace osu.Game.Tests.Database
|
||||
Assert.That(item.Filename.Length, Is.GreaterThan(TestLegacyExporter.MAX_FILENAME_LENGTH));
|
||||
|
||||
//Export multiple times
|
||||
for (int i = 0; i < 10; i++)
|
||||
exportItemAndAssert(item, expectedName);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
string expectedFilename = i == 0 ? expectedName : $"{expectedName} ({i})";
|
||||
exportItemAndAssert(item, expectedFilename);
|
||||
}
|
||||
}
|
||||
|
||||
private void exportItemAndAssert(IHasNamedFiles item, string expectedName)
|
||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Database
|
||||
/// For more information see <see href="https://www.ibm.com/docs/en/spectrum-protect/8.1.9?topic=parameters-file-specification-syntax">file specification syntax</see>, <seealso href="https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits">file systems limitations</seealso>
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public const int MAX_FILENAME_LENGTH = 255 - (32 + 4 + 2); //max path - (Guid + Guid "D" format chars + Storage.CreateFileSafely chars)
|
||||
public const int MAX_FILENAME_LENGTH = 255 - (32 + 4 + 2 + 5); //max path - (Guid + Guid "D" format chars + Storage.CreateFileSafely chars + account for ' (99)' suffix)
|
||||
|
||||
/// <summary>
|
||||
/// The file extension for exports (including the leading '.').
|
||||
@ -48,7 +48,15 @@ namespace osu.Game.Database
|
||||
UserFileStorage = storage.GetStorageForDirectory(@"files");
|
||||
}
|
||||
|
||||
protected virtual string GetFilename(TModel item) => item.GetDisplayString();
|
||||
protected virtual string GetFilename(TModel item)
|
||||
{
|
||||
string filename = item.GetDisplayString();
|
||||
|
||||
if (filename.Length > MAX_FILENAME_LENGTH - FileExtension.Length)
|
||||
return filename.Remove(MAX_FILENAME_LENGTH - FileExtension.Length);
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports an item to a legacy (.zip based) package.
|
||||
@ -65,14 +73,6 @@ namespace osu.Game.Database
|
||||
|
||||
string filename = NamingUtils.GetNextBestFilename(existingExports, $"{itemFilename}{FileExtension}");
|
||||
|
||||
if (filename.Length > MAX_FILENAME_LENGTH)
|
||||
{
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(filename);
|
||||
|
||||
filenameWithoutExtension = filenameWithoutExtension.Remove(MAX_FILENAME_LENGTH - FileExtension.Length);
|
||||
filename = $"{filenameWithoutExtension}{FileExtension}";
|
||||
}
|
||||
|
||||
using (var stream = exportStorage.CreateFileSafely(filename))
|
||||
ExportModelTo(item, stream);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user