forked from microsoft/OSSGadget
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a folder delete helper (microsoft#297)
- Loading branch information
Showing
72 changed files
with
180 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. Licensed under the MIT License. | ||
|
||
namespace Microsoft.CST.OpenSource.Helpers | ||
{ | ||
using NLog; | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
public static class FileSystemHelper | ||
{ | ||
static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); | ||
|
||
/// <summary> | ||
/// Attempt to delete a directory and its contents with retries. | ||
/// </summary> | ||
/// <param name="path">The directory to delete.</param> | ||
/// <param name="recursive">If true, also delete all the contents of the directory.</param> | ||
/// <param name="attempts">Number of attempts. Minimum 1.</param> | ||
/// <param name="millisecondsDelay">Delay between attempts. Minimum 1.</param> | ||
/// <returns>If the directory was deleted.</returns> | ||
public static bool RetryDeleteDirectory(string path, bool recursive = true, int attempts = 5, int millisecondsDelay = 10) | ||
{ | ||
if (path == null) | ||
return false; | ||
if (attempts < 1) | ||
attempts = 1; | ||
if (millisecondsDelay < 1) | ||
millisecondsDelay = 1; | ||
|
||
for (int i = 0; i < attempts; i++) | ||
{ | ||
try | ||
{ | ||
if (Directory.Exists(path)) | ||
{ | ||
Directory.Delete(path, recursive); | ||
} | ||
if (!Directory.Exists(path)) | ||
{ | ||
return true; | ||
} | ||
} | ||
catch(Exception ex) when (ex is IOException) | ||
{ | ||
Thread.Sleep(millisecondsDelay); | ||
Logger.Debug("Error deleting [{0}], sleeping for {1} seconds.", path, millisecondsDelay); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.