diff --git a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs
index 051b4b332..d4c315e1a 100644
--- a/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs
+++ b/src/Orchard/FileSystems/Media/FileSystemStorageProvider.cs
@@ -158,7 +158,7 @@ namespace Orchard.FileSystems.Media {
catch (Exception ex) {
if (ex.IsFatal()) {
throw;
- }
+ }
throw new ArgumentException(T("The folder could not be created at path: {0}. {1}", path, ex).ToString());
}
}
@@ -186,7 +186,7 @@ namespace Orchard.FileSystems.Media {
CreateFolder(path);
}
catch {
- return false;
+ return false;
}
return true;
@@ -240,17 +240,48 @@ namespace Orchard.FileSystems.Media {
}
///
- /// Deletes a file in the storage provider.
+ /// Deletes a file and profile files in the storage provider.
///
/// The relative path to the file to be deleted.
/// If the file doesn't exist.
public void DeleteFile(string path) {
+
FileInfo fileInfo = new FileInfo(MapStorage(path));
if (!fileInfo.Exists) {
throw new ArgumentException(T("File {0} does not exist", path).ToString());
}
fileInfo.Delete();
+
+ lock (String.Intern(path)) {
+ var ListProfileFileInfo = ListProfiles(path);
+ foreach (var profileFileInfo in ListProfileFileInfo) {
+ if (profileFileInfo.Exists) {
+ profileFileInfo.Delete();
+ }
+ if (profileFileInfo.Directory.Exists && !(profileFileInfo.Directory.EnumerateFiles().Any() || profileFileInfo.Directory.EnumerateDirectories().Any())) {
+ profileFileInfo.Directory.Delete();
+ }
+ }
+ }
+ }
+
+ ///
+ /// Get the List of Profile's files in the storage provider.
+ ///
+ /// The relative path to the file to be deleted.
+ ///
+ private IEnumerable ListProfiles(string path) {
+ var filenameWithExtension = Path.GetFileName(path) ?? "";
+ var urlpath = GetPublicUrl(path);
+ var fileLocation = urlpath.Substring(0, urlpath.Length - filenameWithExtension.Length);
+ var hashpath = fileLocation.GetHashCode().ToString("x").ToLowerInvariant();
+ DirectoryInfo directoryInfo = new DirectoryInfo(MapStorage("_Profiles"));
+ if (!directoryInfo.Exists) {
+ return null;
+ }
+ var fileinfos = directoryInfo.GetFiles(filenameWithExtension, SearchOption.AllDirectories);
+ return fileinfos.Where(x => x.Directory.Name.Equals(hashpath));
}
///