mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 00:53:10 +08:00
Add protection against migrating to a nested folder
This commit is contained in:
parent
75b0ada087
commit
364aa5aa12
@ -220,6 +220,30 @@ namespace osu.Game.Tests.NonVisual
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMigrationToNestedTargetFails()
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestMigrationToSameTargetFails)))
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
|
||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||
|
||||
string subFolder = Path.Combine(customPath, "sub");
|
||||
|
||||
Directory.CreateDirectory(subFolder);
|
||||
|
||||
Assert.Throws<ArgumentException>(() => osu.Migrate(subFolder));
|
||||
}
|
||||
finally
|
||||
{
|
||||
host.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OsuGameBase loadOsu(GameHost host)
|
||||
{
|
||||
var osu = new OsuGameBase();
|
||||
|
@ -51,6 +51,9 @@ namespace osu.Game.IO
|
||||
if (source.FullName == destination.FullName)
|
||||
throw new ArgumentException("Destination provided is already the current location", nameof(newLocation));
|
||||
|
||||
if (destination.FullName.Contains(source.FullName))
|
||||
throw new ArgumentException("Destination provided is inside the source", nameof(newLocation));
|
||||
|
||||
// ensure the new location has no files present, else hard abort
|
||||
if (destination.Exists)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user