예제 #1
0
 internal static void DeleteFileSafe(string path, Func <Stream> streamFactory, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem)
 {
     // Only delete the file if it exists and the checksum is the same
     if (msBuildNuGetProjectSystem.FileExistsInProject(path))
     {
         var fullPath = Path.Combine(msBuildNuGetProjectSystem.ProjectFullPath, path);
         if (FileSystemUtility.ContentEquals(fullPath, streamFactory))
         {
             PerformSafeAction(() => msBuildNuGetProjectSystem.RemoveFile(path), msBuildNuGetProjectSystem.NuGetProjectContext);
         }
         else
         {
             // This package installed a file that was modified so warn the user
             msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileModified, fullPath);
         }
     }
 }
예제 #2
0
        public static void DeleteDirectory(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem, string path, bool recursive)
        {
            var fullPath = Path.Combine(msBuildNuGetProjectSystem.ProjectFullPath, path);

            if (!Directory.Exists(fullPath))
            {
                return;
            }

            // Only delete this folder if it is empty and we didn't specify that we want to recurse
            if (!recursive && (GetFiles(msBuildNuGetProjectSystem, path, "*.*", recursive).Any() || GetDirectories(msBuildNuGetProjectSystem, path).Any()))
            {
                msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_DirectoryNotEmpty, path);
                return;
            }
            msBuildNuGetProjectSystem.DeleteDirectory(path, recursive);

            // Workaround for update-package TFS issue. If we're bound to TFS, do not try and delete directories.
            var sourceControlManager = SourceControlUtility.GetSourceControlManager(msBuildNuGetProjectSystem.NuGetProjectContext);

            if (sourceControlManager != null)
            {
                // Source control bound, do not delete
                return;
            }

            try
            {
                Directory.Delete(fullPath, recursive);

                // The directory is not guaranteed to be gone since there could be
                // other open handles. Wait, up to half a second, until the directory is gone.
                for (int i = 0; Directory.Exists(fullPath) && i < 5; ++i)
                {
                    System.Threading.Thread.Sleep(100);
                }
                msBuildNuGetProjectSystem.RemoveFile(path);

                msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_RemovedFolder, fullPath);
            }
            catch (DirectoryNotFoundException)
            {
            }
        }
        public static void DeleteDirectory(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem, string path, bool recursive)
        {
            var fullPath = Path.Combine(msBuildNuGetProjectSystem.ProjectFullPath, path);
            if (!Directory.Exists(fullPath))
            {
                return;
            }

            // Only delete this folder if it is empty and we didn't specify that we want to recurse
            if (!recursive && (GetFiles(msBuildNuGetProjectSystem, path, "*.*", recursive).Any() || GetDirectories(msBuildNuGetProjectSystem, path).Any()))
            {
                msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_DirectoryNotEmpty, path);
                return;
            }
            msBuildNuGetProjectSystem.DeleteDirectory(path, recursive);

            // Workaround for update-package TFS issue. If we're bound to TFS, do not try and delete directories.
            var sourceControlManager = SourceControlUtility.GetSourceControlManager(msBuildNuGetProjectSystem.NuGetProjectContext);
            if(sourceControlManager != null)
            {
                // Source control bound, do not delete
                return;
            }

            try
            {
                Directory.Delete(fullPath, recursive);

                // The directory is not guaranteed to be gone since there could be
                // other open handles. Wait, up to half a second, until the directory is gone.
                for (int i = 0; Directory.Exists(fullPath) && i < 5; ++i)
                {
                    System.Threading.Thread.Sleep(100);
                }
                msBuildNuGetProjectSystem.RemoveFile(path);

                msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_RemovedFolder, fullPath);
            }
            catch (DirectoryNotFoundException)
            {
            }
        }
 public static void DeleteFileSafe(string path, Func<Stream> streamFactory, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem)
 {
     // Only delete the file if it exists and the checksum is the same
     if (msBuildNuGetProjectSystem.FileExistsInProject(path))
     {
         var fullPath = Path.Combine(msBuildNuGetProjectSystem.ProjectFullPath, path);
         if (FileSystemUtility.ContentEquals(fullPath, streamFactory))
         {
             PerformSafeAction(() => msBuildNuGetProjectSystem.RemoveFile(path), msBuildNuGetProjectSystem.NuGetProjectContext);
         }
         else
         {
             // This package installed a file that was modified so warn the user
             msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileModified, fullPath);
         }
     }
 }