Permalink
Browse files

Fail by default when failing to delete some files in DELETE /scm

  • Loading branch information...
davidebbo committed Jan 18, 2013
1 parent 5ffe814 commit 0968f3de128585e87b1eec9aacba81b1a645ab4c
Showing with 21 additions and 18 deletions.
  1. +13 −10 Kudu.Core/Infrastructure/FileSystemHelpers.cs
  2. +8 −8 Kudu.Services/SourceControl/LiveScmController.cs
@@ -8,14 +8,14 @@ namespace Kudu.Core.Infrastructure
{
internal static class FileSystemHelpers
{
- public static void DeleteDirectorySafe(string path)
+ public static void DeleteDirectorySafe(string path, bool ignoreErrors = true)
{
- DeleteFileSystemInfo(new DirectoryInfoWrapper(new DirectoryInfo(path)));
+ DeleteFileSystemInfo(new DirectoryInfoWrapper(new DirectoryInfo(path)), ignoreErrors);
}
- public static void DeleteDirectoryContentsSafe(string path)
+ public static void DeleteDirectoryContentsSafe(string path, bool ignoreErrors = true)
{
- DeleteDirectoryContentsSafe(new DirectoryInfoWrapper(new DirectoryInfo(path)));
+ DeleteDirectoryContentsSafe(new DirectoryInfoWrapper(new DirectoryInfo(path)), ignoreErrors);
}
public static void DeleteIfEmpty(string path)
@@ -69,7 +69,7 @@ internal static bool DeleteFileSafe(IFileSystem fileSystem, string path)
return false;
}
- private static void DeleteFileSystemInfo(FileSystemInfoBase fileSystemInfo)
+ private static void DeleteFileSystemInfo(FileSystemInfoBase fileSystemInfo, bool ignoreErrors)
{
try
{
@@ -80,43 +80,46 @@ private static void DeleteFileSystemInfo(FileSystemInfoBase fileSystemInfo)
}
catch
{
+ if (!ignoreErrors) throw;
}
var directoryInfo = fileSystemInfo as DirectoryInfoBase;
if (directoryInfo != null)
{
- DeleteDirectoryContentsSafe(directoryInfo);
+ DeleteDirectoryContentsSafe(directoryInfo, ignoreErrors);
}
- DoSafeAction(fileSystemInfo.Delete);
+ DoSafeAction(fileSystemInfo.Delete, ignoreErrors);
}
- private static void DeleteDirectoryContentsSafe(DirectoryInfoBase directoryInfo)
+ private static void DeleteDirectoryContentsSafe(DirectoryInfoBase directoryInfo, bool ignoreErrors)
{
try
{
if (directoryInfo.Exists)
{
foreach (var fsi in directoryInfo.GetFileSystemInfos())
{
- DeleteFileSystemInfo(fsi);
+ DeleteFileSystemInfo(fsi, ignoreErrors);
}
}
}
catch
{
+ if (!ignoreErrors) throw;
}
}
- private static void DoSafeAction(Action action)
+ private static void DoSafeAction(Action action, bool ignoreErrors)
{
try
{
OperationManager.Attempt(action);
}
catch
{
+ if (!ignoreErrors) throw;
}
}
@@ -52,49 +52,49 @@ public RepositoryInfo GetRepositoryInfo(HttpRequestMessage request)
/// Delete the repository
/// </summary>
[HttpDelete]
- public void Delete(int deleteWebRoot = 0)
+ public void Delete(int deleteWebRoot = 0, int ignoreErrors = 0)
{
// Fail if a deployment is in progress
_deploymentLock.LockOperation(() =>
{
using (_tracer.Step("Deleting deployment cache"))
{
// Delete the deployment cache
- FileSystemHelpers.DeleteDirectorySafe(_environment.DeploymentCachePath);
+ FileSystemHelpers.DeleteDirectorySafe(_environment.DeploymentCachePath, ignoreErrors != 0);
}
using (_tracer.Step("Deleting repository"))
{
// Delete the repository
- FileSystemHelpers.DeleteDirectorySafe(_environment.RepositoryPath);
+ FileSystemHelpers.DeleteDirectorySafe(_environment.RepositoryPath, ignoreErrors != 0);
}
using (_tracer.Step("Deleting ssh key"))
{
// Delete the ssh key
- FileSystemHelpers.DeleteDirectorySafe(_environment.SSHKeyPath);
+ FileSystemHelpers.DeleteDirectorySafe(_environment.SSHKeyPath, ignoreErrors != 0);
}
if (deleteWebRoot != 0)
{
using (_tracer.Step("Deleting web root"))
{
// Delete the wwwroot folder
- FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.WebRootPath);
+ FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.WebRootPath, ignoreErrors != 0);
}
using (_tracer.Step("Deleting diagnostics"))
{
// Delete the diagnostic log. This is a slight abuse of deleteWebRoot, but the
// real semantic is more to reset the site to a fully clean state
- FileSystemHelpers.DeleteDirectorySafe(_environment.DiagnosticsPath);
+ FileSystemHelpers.DeleteDirectorySafe(_environment.DiagnosticsPath, ignoreErrors != 0);
}
using (_tracer.Step("Deleting Logs"))
{
// Cleanup the trace directories
- FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.TracePath);
- FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.DeploymentTracePath);
+ FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.TracePath, ignoreErrors != 0);
+ FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.DeploymentTracePath, ignoreErrors != 0);
}
}
},

0 comments on commit 0968f3d

Please sign in to comment.