Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class MaxPathTests : BaseTest
[SetUp]
public void Setup ()
{
if (!IsWindows) {
Assert.Ignore ("MAX_PATH only applies on Windows");
if (LongPathsSupported) {
Assert.Ignore ("This environment supports long paths");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public void ReadonlyFile ()
[Test]
public void LongPath ()
{
if (!IsWindows) {
Assert.Ignore ("MAX_PATH only applies on Windows");
if (LongPathsSupported) {
Assert.Ignore ("This environment supports long paths");
}
var file = NewFile (fileName: "foo".PadRight (250, 'N'));
var file = NewFile (fileName: "foo".PadRight (MaxFileName, 'N'));
var task = CreateTask ();
Assert.IsTrue (task.Execute (), "task.Execute() should have succeeded.");
Assert.AreEqual (1, task.RemovedDirectories.Length, "Changes should have been made.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ public static string AndroidNdkPath {
}
}

/// <summary>
/// Windows can only create a file of 255 characters: This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters).
/// See: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
/// </summary>
public const int MaxFileName = 255;

static Lazy<bool> longPaths = new Lazy<bool> (() => {
if (!TestEnvironment.IsWindows) {
return true;
}
var path = Path.Combine (Path.GetTempPath (), "foo".PadRight (MaxFileName, 'N'));
try {
File.WriteAllText (path, "");
return true;
} catch {
return false;
} finally {
// If the file exists, we should be able to delete it
if (File.Exists (path)) {
File.Delete (path);
}
}
});

public static bool LongPathsSupported => longPaths.Value;

protected static void WaitFor(int milliseconds)
{
var pause = new ManualResetEvent(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void CopyIfChanged_NoExist ()
public void CopyIfChanged_LongPath ()
{
var src = NewFile (contents: "foo");
var dest = NewFile (contents: "bar", fileName: "bar".PadRight (250, 'N'));
var dest = NewFile (contents: "bar", fileName: "bar".PadRight (MaxFileName, 'N'));
dest = Files.ToLongPath (dest);
Assert.IsTrue (Files.CopyIfChanged (src, dest), "Changes should have occurred");
FileAssert.AreEqual (src, dest);
Expand Down Expand Up @@ -142,7 +142,7 @@ public void CopyIfStringChanged_NoExist ()
[Test]
public void CopyIfStringChanged_LongPath ()
{
var dest = NewFile (fileName: "bar".PadRight (250, 'N'));
var dest = NewFile (fileName: "bar".PadRight (MaxFileName, 'N'));
dest = Files.ToLongPath (dest);
Assert.IsTrue (Files.CopyIfStringChanged ("foo", dest), "Changes should have occurred");
FileAssert.Exists (dest);
Expand Down Expand Up @@ -192,7 +192,7 @@ public void CopyIfStreamChanged_NoChanges ()
public void CopyIfStreamChanged_LongPath ()
{
using (var src = NewStream ("foo")) {
var dest = NewFile (fileName: "bar".PadRight (250, 'N'));
var dest = NewFile (fileName: "bar".PadRight (MaxFileName, 'N'));
dest = Files.ToLongPath (dest);
Assert.IsTrue (Files.CopyIfStreamChanged (src, dest), "Changes should have occurred");
FileAssert.Exists (dest);
Expand Down