@@ -82,6 +82,47 @@ public void Delete_DeletesFile()
8282 }
8383 }
8484
85+ [ Fact ]
86+ [ Trait ( "Level" , "L0" ) ]
87+ [ Trait ( "Category" , "Common" ) ]
88+ public async void DeleteDirectory_DeleteTargetFileWithASymlink ( )
89+ {
90+ using ( TestHostContext hc = new TestHostContext ( this ) )
91+ {
92+ Tracing trace = hc . GetTrace ( ) ;
93+
94+ // Arrange: Create a directory with a file.
95+ string directory = Path . Combine ( hc . GetDirectory ( WellKnownDirectory . Bin ) , Path . GetRandomFileName ( ) ) ;
96+ string targetFile = Path . Combine ( directory , "somefile" ) ;
97+ string symlink = Path . Combine ( directory , "symlink" ) ;
98+ try
99+ {
100+ Directory . CreateDirectory ( directory ) ;
101+ File . WriteAllText ( path : targetFile , contents : "some contents" ) ;
102+ File . SetAttributes ( targetFile , File . GetAttributes ( targetFile ) | FileAttributes . ReadOnly ) ;
103+
104+ await CreateFileReparsePoint ( context : hc , link : symlink , target : targetFile ) ;
105+
106+ // Act.
107+ IOUtil . DeleteFile ( targetFile ) ;
108+ IOUtil . DeleteDirectory ( directory , CancellationToken . None ) ;
109+
110+ // Assert.
111+ Assert . False ( File . Exists ( targetFile ) ) ;
112+ Assert . False ( File . Exists ( symlink ) ) ;
113+
114+ }
115+ finally
116+ {
117+ // Cleanup.
118+ if ( Directory . Exists ( directory ) )
119+ {
120+ Directory . Delete ( directory , recursive : true ) ;
121+ }
122+ }
123+ }
124+ }
125+
85126 [ Fact ]
86127 [ Trait ( "Level" , "L0" ) ]
87128 [ Trait ( "Category" , "Common" ) ]
@@ -1269,5 +1310,28 @@ public void GetDirectoryName_WindowsStyle()
12691310 }
12701311 }
12711312 }
1313+
1314+ private static async Task CreateFileReparsePoint(IHostContext context, string link, string target)
1315+ {
1316+ string fileName = (TestUtil.IsWindows())
1317+ ? Environment.GetEnvironmentVariable("ComSpec")
1318+ : "/bin/ln";
1319+ string arguments = (TestUtil.IsWindows())
1320+ ? $@"/c ""mklink ""{link}"" ""{target}"""""
1321+ : $@"-s ""{target}"" ""{link}""" ;
1322+
1323+ ArgUtil. File ( fileName , nameof ( fileName ) ) ;
1324+ using ( var processInvoker = new ProcessInvokerWrapper ( ) )
1325+ {
1326+ processInvoker. Initialize ( context ) ;
1327+ await processInvoker. ExecuteAsync (
1328+ workingDirectory : context . GetDirectory ( WellKnownDirectory . Bin ) ,
1329+ fileName : fileName ,
1330+ arguments : arguments ,
1331+ environment : null ,
1332+ requireExitCodeZero : true ,
1333+ cancellationToken : CancellationToken . None ) ;
1334+ }
1335+ }
12721336 }
12731337}
0 commit comments