Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@ -14,6 +14,8 @@ using System;
using System.IO;
using System.Globalization;
using System.Threading;
using System.Runtime.InteropServices;
using NUnit.Framework;
@ -2680,5 +2682,53 @@ namespace MonoTests.System.IO
MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true);
MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true);
}
[DllImport ("libc", SetLastError=true)]
public static extern int symlink (string oldpath, string newpath);
[Test]
public void SymLinkLoop ()
{
if (!RunningOnUnix)
Assert.Ignore ("Symlink are hard on windows");
var name1 = Path.GetRandomFileName ();
var name2 = Path.GetRandomFileName ();
var path1 = Path.Combine (Path.GetTempPath (), name1);
var path2 = Path.Combine (Path.GetTempPath (), name2);
File.Delete (path1);
File.Delete (path2);
try {
symlink (path1, path2);
symlink (path2, path1);
Assert.IsTrue (File.Exists (path1), "File.Exists must return true for path1 symlink loop");
Assert.IsTrue (File.Exists (path2), "File.Exists must return true for path2 symlink loop");
try {
using (var f = File.Open (path1, FileMode.Open, FileAccess.Read)) {
Assert.Fail ("File.Open must throw for symlink loops");
}
} catch (IOException ex) {
Assert.AreEqual (0x80070781u, (uint)ex.HResult, "Ensure HRESULT is correct");
}
File.Delete (path1); //Delete must not throw and must work
Assert.IsFalse (File.Exists (path1), "File.Delete must delete symlink loops");
} finally {
try {
File.Delete (path1);
File.Delete (path2);
} catch (IOException) {
//Don't double fault any exception from the tests.
}
}
}
}
}