Skip to content

Commit 7bf806f

Browse files
committed
Add logging to new msi validation.
1 parent 10ec611 commit 7bf806f

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

src/Agent/MsiInstaller/InstallerActions/CustomActions.cs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private void DeleteFolder(string path)
264264
{
265265
if (Directory.Exists(path))
266266
{
267-
SaferFileUtils.DeleteDirectoryAndContents(path);
267+
SaferFileUtils.DeleteDirectoryAndContents(path, this);
268268
LogSuccess("Folder deleted at '{0}'.", path);
269269
}
270270
else
@@ -285,7 +285,7 @@ private void DeleteFile(string path)
285285
{
286286
if (File.Exists(path))
287287
{
288-
SaferFileUtils.FileDelete(path);
288+
SaferFileUtils.FileDelete(path, this);
289289
LogSuccess("File deleted at '{0}'.", path);
290290
}
291291
else
@@ -480,7 +480,7 @@ private void MigrateNewRelicXml()
480480
session.Log("Attempting to move file from {0} to {1}.", sourcePath, destinationPath);
481481
try
482482
{
483-
SaferFileUtils.FileCopy(sourcePath, destinationPath);
483+
SaferFileUtils.FileCopy(sourcePath, destinationPath, this);
484484
session.Log("Moved file from {0} to {1}.", sourcePath, destinationPath);
485485
}
486486
catch (IOException)
@@ -543,7 +543,7 @@ private void MigrateCustomInstrumentation()
543543
}
544544
}
545545

546-
private static void CopyFolderContents(string source, string destination)
546+
private void CopyFolderContents(string source, string destination)
547547
{
548548
if (source == null) return;
549549
if (destination == null) return;
@@ -561,7 +561,7 @@ private static void CopyFolderContents(string source, string destination)
561561
// If the subfolder already exists don't try to copy.
562562
if (Directory.Exists(destinationPath)) continue;
563563

564-
SaferFileUtils.DirectoryMove(sourceDirectoryPath, destinationPath);
564+
SaferFileUtils.DirectoryMove(sourceDirectoryPath, destinationPath, this);
565565
}
566566

567567
// Copy all the files in the root of the directory.
@@ -571,8 +571,8 @@ private static void CopyFolderContents(string source, string destination)
571571
string fileName = Path.GetFileName(sourceFilePath);
572572
string destinationPath = destination + fileName;
573573

574-
SaferFileUtils.FileCopy(sourceFilePath, destinationPath, true);
575-
SaferFileUtils.FileDelete(sourceFilePath);
574+
SaferFileUtils.FileCopy(sourceFilePath, destinationPath, true, this);
575+
SaferFileUtils.FileDelete(sourceFilePath, this);
576576
}
577577
}
578578
}
@@ -587,57 +587,62 @@ private static void CopyFolderContents(string source, string destination)
587587
/// </summary>
588588
internal static class SaferFileUtils
589589
{
590-
internal static void FileCopy(string source, string destination)
590+
internal static void FileCopy(string source, string destination, MySession logger)
591591
{
592-
if (!FileIsSafeToUse(source))
592+
if (!FileIsSafeToUse(source, logger))
593593
{
594+
logger.Log("{0} was not copied.", source);
594595
return;
595596
}
596597

597598
File.Copy(source, destination);
598599
}
599600

600-
internal static void FileCopy(string source, string destination, bool overwrite)
601+
internal static void FileCopy(string source, string destination, bool overwrite, MySession logger)
601602
{
602-
if (!FileIsSafeToUse(source))
603+
if (!FileIsSafeToUse(source, logger))
603604
{
605+
logger.Log("{0} was not copied.", source);
604606
return;
605607
}
606608

607609
File.Copy(source, destination, overwrite);
608610
}
609611

610-
internal static void FileDelete(string fileNameAndPath)
612+
internal static void FileDelete(string fileNameAndPath, MySession logger)
611613
{
612-
if (!FileIsSafeToUse(fileNameAndPath))
614+
if (!FileIsSafeToUse(fileNameAndPath, logger))
613615
{
616+
logger.Log("{0} was not deleted.", fileNameAndPath);
614617
return;
615618
}
616619

617620
File.Delete(fileNameAndPath);
618621
}
619622

620-
internal static void DeleteDirectoryAndContents(string path)
623+
internal static void DeleteDirectoryAndContents(string path, MySession logger)
621624
{
622-
if (!DirectoryIsSafeToUse(path))
625+
if (!DirectoryIsSafeToUse(path, logger))
623626
{
627+
logger.Log("{0} was not deleted.", path);
624628
return;
625629
}
626630

627631
Directory.Delete(path, true);
628632
}
629633

630-
internal static void DirectoryMove(string source, string destination)
634+
internal static void DirectoryMove(string source, string destination, MySession logger)
631635
{
632-
if (!DirectoryIsSafeToUse(source))
636+
if (!DirectoryIsSafeToUse(source, logger))
633637
{
638+
logger.Log("{0} was not moved.", source);
634639
return;
635640
}
636641

637642
Directory.Move(source, destination);
638643
}
639644

640-
private static bool FileIsSafeToUse(string fileNameAndPath)
645+
private static bool FileIsSafeToUse(string fileNameAndPath, MySession logger)
641646
{
642647
if (!File.Exists(fileNameAndPath))
643648
{
@@ -646,46 +651,46 @@ private static bool FileIsSafeToUse(string fileNameAndPath)
646651

647652
var fileInfo = new FileInfo(fileNameAndPath);
648653

649-
if (FileSystemReportsAReparsePoint(fileInfo))
654+
if (FileSystemReportsAReparsePoint(fileInfo, logger))
650655
{
651656
return false;
652657
}
653658

654659
for (var directory = fileInfo.Directory; directory != null; directory = directory.Parent)
655660
{
656-
if (FileSystemReportsAReparsePoint(directory))
661+
if (FileSystemReportsAReparsePoint(directory, logger))
657662
{
658663
return false;
659664
}
660665
}
661666

662-
return DirectoryAndParentsAreSafe(fileInfo.Directory);
667+
return DirectoryAndParentsAreSafe(fileInfo.Directory, logger);
663668
}
664669

665-
private static bool DirectoryIsSafeToUse(string path)
670+
private static bool DirectoryIsSafeToUse(string path, MySession logger)
666671
{
667672
if (!Directory.Exists(path))
668673
{
669674
return false;
670675
}
671676

672677
var directory = new DirectoryInfo(path);
673-
if (!DirectoryAndParentsAreSafe(directory))
678+
if (!DirectoryAndParentsAreSafe(directory, logger))
674679
{
675680
return false;
676681
}
677682

678683
foreach (var childDirectory in directory.GetDirectories("*", SearchOption.AllDirectories))
679684
{
680-
if (FileSystemReportsAReparsePoint(childDirectory))
685+
if (FileSystemReportsAReparsePoint(childDirectory, logger))
681686
{
682687
return false;
683688
}
684689
}
685690

686691
foreach (var childFile in directory.GetFiles("*", SearchOption.AllDirectories))
687692
{
688-
if (FileSystemReportsAReparsePoint(childFile))
693+
if (FileSystemReportsAReparsePoint(childFile, logger))
689694
{
690695
return false;
691696
}
@@ -694,11 +699,11 @@ private static bool DirectoryIsSafeToUse(string path)
694699
return true;
695700
}
696701

697-
private static bool DirectoryAndParentsAreSafe(DirectoryInfo directoryToCheck)
702+
private static bool DirectoryAndParentsAreSafe(DirectoryInfo directoryToCheck, MySession logger)
698703
{
699704
for (var directory = directoryToCheck; directory != null; directory = directory.Parent)
700705
{
701-
if (FileSystemReportsAReparsePoint(directory))
706+
if (FileSystemReportsAReparsePoint(directory, logger))
702707
{
703708
return false;
704709
}
@@ -707,9 +712,15 @@ private static bool DirectoryAndParentsAreSafe(DirectoryInfo directoryToCheck)
707712
return true;
708713
}
709714

710-
private static bool FileSystemReportsAReparsePoint(FileSystemInfo fsInfo)
715+
private static bool FileSystemReportsAReparsePoint(FileSystemInfo fsInfo, MySession logger)
711716
{
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;
713724
}
714725
}
715726
}

0 commit comments

Comments
 (0)