diff options
author | Alexis Christoforides <alexis@thenull.net> | 2019-07-08 21:43:30 +0300 |
---|---|---|
committer | Alexis Christoforides <alexis@thenull.net> | 2019-07-30 16:11:11 +0300 |
commit | 7715668a23e07252639622f3e7a7b2002a2d47ff (patch) | |
tree | 7c4fbeb35c2de5e4b34f68a2b4af40c0449511a4 /src/System.IO.FileSystem/tests | |
parent | eb5ba09e18f966ac427f8fed02d291534208df2b (diff) |
Allow copying/moving/replacing broken symlinks
Diffstat (limited to 'src/System.IO.FileSystem/tests')
-rw-r--r-- | src/System.IO.FileSystem/tests/File/Copy.cs | 17 | ||||
-rw-r--r-- | src/System.IO.FileSystem/tests/File/Move.cs | 17 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/System.IO.FileSystem/tests/File/Copy.cs b/src/System.IO.FileSystem/tests/File/Copy.cs index 81338ceb91..2cf108e8db 100644 --- a/src/System.IO.FileSystem/tests/File/Copy.cs +++ b/src/System.IO.FileSystem/tests/File/Copy.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using Xunit; +using System.Runtime.InteropServices; namespace System.IO.Tests { @@ -48,6 +49,22 @@ namespace System.IO.Tests Assert.Throws<IOException>(() => Copy(testFile, testFile)); } + [DllImport("libc", SetLastError = true)] + private static extern int symlink(string target, string linkpath); + + [Fact] + [PlatformSpecific(TestPlatforms.AnyUnix)] + public void DanglingSymlinkCopy() + { + string dangling_symlink = GetTestFileName(); + string missing_target = GetTestFileName(); + string dangling_symlink_new_location = GetTestFileName(); + Assert.False(File.Exists(missing_target)); + Assert.Equal(symlink(missing_target, dangling_symlink), 0); + Copy(dangling_symlink, dangling_symlink_new_location); + Assert.True(File.Exists(dangling_symlink_new_location)); // File.Exists returns true for dangling symlinks + } + [Fact] [SkipOnTargetFramework(TargetFrameworkMonikers.Mono, "CoreFX FileStream not yet imported")] public void NonExistentPath() diff --git a/src/System.IO.FileSystem/tests/File/Move.cs b/src/System.IO.FileSystem/tests/File/Move.cs index e9da920edd..6548b4f564 100644 --- a/src/System.IO.FileSystem/tests/File/Move.cs +++ b/src/System.IO.FileSystem/tests/File/Move.cs @@ -4,6 +4,7 @@ using Xunit; using System.Linq; +using System.Runtime.InteropServices; namespace System.IO.Tests { @@ -174,6 +175,22 @@ namespace System.IO.Tests Assert.False(File.Exists(testFileSource.FullName)); } + [DllImport("libc", SetLastError = true)] + private static extern int symlink(string target, string linkpath); + + [Fact] + [PlatformSpecific(TestPlatforms.AnyUnix)] + public void DanglingSymlinkMove() + { + string dangling_symlink = GetTestFileName(); + string missing_target = GetTestFileName(); + string dangling_symlink_new_location = GetTestFileName(); + Assert.False(File.Exists(missing_target)); + Assert.Equal(symlink(missing_target, dangling_symlink), 0); + Move(dangling_symlink, dangling_symlink_new_location); + Assert.True(File.Exists(dangling_symlink_new_location)); // File.Exists returns true for dangling symlinks + } + [Fact] public void FileNameWithSignificantWhitespace() { |