@@ -264,7 +264,7 @@ private void DeleteFolder(string path)
264
264
{
265
265
if ( Directory . Exists ( path ) )
266
266
{
267
- SaferFileUtils . DeleteDirectoryAndContents ( path ) ;
267
+ SaferFileUtils . DeleteDirectoryAndContents ( path , this ) ;
268
268
LogSuccess ( "Folder deleted at '{0}'." , path ) ;
269
269
}
270
270
else
@@ -285,7 +285,7 @@ private void DeleteFile(string path)
285
285
{
286
286
if ( File . Exists ( path ) )
287
287
{
288
- SaferFileUtils . FileDelete ( path ) ;
288
+ SaferFileUtils . FileDelete ( path , this ) ;
289
289
LogSuccess ( "File deleted at '{0}'." , path ) ;
290
290
}
291
291
else
@@ -480,7 +480,7 @@ private void MigrateNewRelicXml()
480
480
session . Log ( "Attempting to move file from {0} to {1}." , sourcePath , destinationPath ) ;
481
481
try
482
482
{
483
- SaferFileUtils . FileCopy ( sourcePath , destinationPath ) ;
483
+ SaferFileUtils . FileCopy ( sourcePath , destinationPath , this ) ;
484
484
session . Log ( "Moved file from {0} to {1}." , sourcePath , destinationPath ) ;
485
485
}
486
486
catch ( IOException )
@@ -543,7 +543,7 @@ private void MigrateCustomInstrumentation()
543
543
}
544
544
}
545
545
546
- private static void CopyFolderContents ( string source , string destination )
546
+ private void CopyFolderContents ( string source , string destination )
547
547
{
548
548
if ( source == null ) return ;
549
549
if ( destination == null ) return ;
@@ -561,7 +561,7 @@ private static void CopyFolderContents(string source, string destination)
561
561
// If the subfolder already exists don't try to copy.
562
562
if ( Directory . Exists ( destinationPath ) ) continue ;
563
563
564
- SaferFileUtils . DirectoryMove ( sourceDirectoryPath , destinationPath ) ;
564
+ SaferFileUtils . DirectoryMove ( sourceDirectoryPath , destinationPath , this ) ;
565
565
}
566
566
567
567
// Copy all the files in the root of the directory.
@@ -571,8 +571,8 @@ private static void CopyFolderContents(string source, string destination)
571
571
string fileName = Path . GetFileName ( sourceFilePath ) ;
572
572
string destinationPath = destination + fileName ;
573
573
574
- SaferFileUtils . FileCopy ( sourceFilePath , destinationPath , true ) ;
575
- SaferFileUtils . FileDelete ( sourceFilePath ) ;
574
+ SaferFileUtils . FileCopy ( sourceFilePath , destinationPath , true , this ) ;
575
+ SaferFileUtils . FileDelete ( sourceFilePath , this ) ;
576
576
}
577
577
}
578
578
}
@@ -587,57 +587,62 @@ private static void CopyFolderContents(string source, string destination)
587
587
/// </summary>
588
588
internal static class SaferFileUtils
589
589
{
590
- internal static void FileCopy ( string source , string destination )
590
+ internal static void FileCopy ( string source , string destination , MySession logger )
591
591
{
592
- if ( ! FileIsSafeToUse ( source ) )
592
+ if ( ! FileIsSafeToUse ( source , logger ) )
593
593
{
594
+ logger . Log ( "{0} was not copied." , source ) ;
594
595
return ;
595
596
}
596
597
597
598
File . Copy ( source , destination ) ;
598
599
}
599
600
600
- internal static void FileCopy ( string source , string destination , bool overwrite )
601
+ internal static void FileCopy ( string source , string destination , bool overwrite , MySession logger )
601
602
{
602
- if ( ! FileIsSafeToUse ( source ) )
603
+ if ( ! FileIsSafeToUse ( source , logger ) )
603
604
{
605
+ logger . Log ( "{0} was not copied." , source ) ;
604
606
return ;
605
607
}
606
608
607
609
File . Copy ( source , destination , overwrite ) ;
608
610
}
609
611
610
- internal static void FileDelete ( string fileNameAndPath )
612
+ internal static void FileDelete ( string fileNameAndPath , MySession logger )
611
613
{
612
- if ( ! FileIsSafeToUse ( fileNameAndPath ) )
614
+ if ( ! FileIsSafeToUse ( fileNameAndPath , logger ) )
613
615
{
616
+ logger . Log ( "{0} was not deleted." , fileNameAndPath ) ;
614
617
return ;
615
618
}
616
619
617
620
File . Delete ( fileNameAndPath ) ;
618
621
}
619
622
620
- internal static void DeleteDirectoryAndContents ( string path )
623
+ internal static void DeleteDirectoryAndContents ( string path , MySession logger )
621
624
{
622
- if ( ! DirectoryIsSafeToUse ( path ) )
625
+ if ( ! DirectoryIsSafeToUse ( path , logger ) )
623
626
{
627
+ logger . Log ( "{0} was not deleted." , path ) ;
624
628
return ;
625
629
}
626
630
627
631
Directory . Delete ( path , true ) ;
628
632
}
629
633
630
- internal static void DirectoryMove ( string source , string destination )
634
+ internal static void DirectoryMove ( string source , string destination , MySession logger )
631
635
{
632
- if ( ! DirectoryIsSafeToUse ( source ) )
636
+ if ( ! DirectoryIsSafeToUse ( source , logger ) )
633
637
{
638
+ logger . Log ( "{0} was not moved." , source ) ;
634
639
return ;
635
640
}
636
641
637
642
Directory . Move ( source , destination ) ;
638
643
}
639
644
640
- private static bool FileIsSafeToUse ( string fileNameAndPath )
645
+ private static bool FileIsSafeToUse ( string fileNameAndPath , MySession logger )
641
646
{
642
647
if ( ! File . Exists ( fileNameAndPath ) )
643
648
{
@@ -646,46 +651,46 @@ private static bool FileIsSafeToUse(string fileNameAndPath)
646
651
647
652
var fileInfo = new FileInfo ( fileNameAndPath ) ;
648
653
649
- if ( FileSystemReportsAReparsePoint ( fileInfo ) )
654
+ if ( FileSystemReportsAReparsePoint ( fileInfo , logger ) )
650
655
{
651
656
return false ;
652
657
}
653
658
654
659
for ( var directory = fileInfo . Directory ; directory != null ; directory = directory . Parent )
655
660
{
656
- if ( FileSystemReportsAReparsePoint ( directory ) )
661
+ if ( FileSystemReportsAReparsePoint ( directory , logger ) )
657
662
{
658
663
return false ;
659
664
}
660
665
}
661
666
662
- return DirectoryAndParentsAreSafe ( fileInfo . Directory ) ;
667
+ return DirectoryAndParentsAreSafe ( fileInfo . Directory , logger ) ;
663
668
}
664
669
665
- private static bool DirectoryIsSafeToUse ( string path )
670
+ private static bool DirectoryIsSafeToUse ( string path , MySession logger )
666
671
{
667
672
if ( ! Directory . Exists ( path ) )
668
673
{
669
674
return false ;
670
675
}
671
676
672
677
var directory = new DirectoryInfo ( path ) ;
673
- if ( ! DirectoryAndParentsAreSafe ( directory ) )
678
+ if ( ! DirectoryAndParentsAreSafe ( directory , logger ) )
674
679
{
675
680
return false ;
676
681
}
677
682
678
683
foreach ( var childDirectory in directory . GetDirectories ( "*" , SearchOption . AllDirectories ) )
679
684
{
680
- if ( FileSystemReportsAReparsePoint ( childDirectory ) )
685
+ if ( FileSystemReportsAReparsePoint ( childDirectory , logger ) )
681
686
{
682
687
return false ;
683
688
}
684
689
}
685
690
686
691
foreach ( var childFile in directory . GetFiles ( "*" , SearchOption . AllDirectories ) )
687
692
{
688
- if ( FileSystemReportsAReparsePoint ( childFile ) )
693
+ if ( FileSystemReportsAReparsePoint ( childFile , logger ) )
689
694
{
690
695
return false ;
691
696
}
@@ -694,11 +699,11 @@ private static bool DirectoryIsSafeToUse(string path)
694
699
return true ;
695
700
}
696
701
697
- private static bool DirectoryAndParentsAreSafe ( DirectoryInfo directoryToCheck )
702
+ private static bool DirectoryAndParentsAreSafe ( DirectoryInfo directoryToCheck , MySession logger )
698
703
{
699
704
for ( var directory = directoryToCheck ; directory != null ; directory = directory . Parent )
700
705
{
701
- if ( FileSystemReportsAReparsePoint ( directory ) )
706
+ if ( FileSystemReportsAReparsePoint ( directory , logger ) )
702
707
{
703
708
return false ;
704
709
}
@@ -707,9 +712,15 @@ private static bool DirectoryAndParentsAreSafe(DirectoryInfo directoryToCheck)
707
712
return true ;
708
713
}
709
714
710
- private static bool FileSystemReportsAReparsePoint ( FileSystemInfo fsInfo )
715
+ private static bool FileSystemReportsAReparsePoint ( FileSystemInfo fsInfo , MySession logger )
711
716
{
712
- return ( fsInfo . Attributes & System . IO . FileAttributes . ReparsePoint ) != 0 ;
717
+ if ( ( fsInfo . Attributes & System . IO . FileAttributes . ReparsePoint ) != 0 )
718
+ {
719
+ logger . Log ( "Reparse point detected for {0}." , fsInfo . FullName ) ;
720
+ return true ;
721
+ }
722
+
723
+ return false ;
713
724
}
714
725
}
715
726
}
0 commit comments