[Fixes #6323] Rename media folder fails with Azure Media Storage (#7670)

Fixes #6323
This commit is contained in:
Thierry Fleury
2017-05-04 21:17:39 +02:00
committed by Sébastien Ros
parent 99e76e8af7
commit 6e95dc9d92
2 changed files with 6 additions and 4 deletions

View File

@@ -239,7 +239,8 @@ namespace Orchard.Azure.Services.FileSystems {
}
if (blob is CloudBlobDirectory) {
string foldername = blob.Uri.Segments.Last();
var blobDir = (CloudBlobDirectory)blob;
string foldername = blobDir.Prefix.Substring(blobDir.Parent.Prefix.Length);
string source = String.Concat(path, foldername);
string destination = String.Concat(newPath, foldername);
RenameFolder(source, destination);

View File

@@ -328,15 +328,16 @@ namespace Orchard.MediaLibrary.Services {
Argument.ThrowIfNullOrEmpty(newFolderName, "newFolderName");
try {
var segments = folderPath.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).ToArray();
var newFolderPath = String.Join(Path.DirectorySeparatorChar.ToString(), segments.Take(segments.Length - 1).Union(new[] { newFolderName }));
var parentIndex = folderPath.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
var parentPath = parentIndex > 0 ? folderPath.Substring(0, parentIndex) : String.Empty;
var newFolderPath = _storageProvider.Combine(parentPath, newFolderName);
var mediaParts = BuildGetMediaContentItemsQuery(_orchardServices.ContentManager, folderPath, true).List();
foreach (var mediaPart in mediaParts) {
mediaPart.FolderPath = newFolderPath + mediaPart.FolderPath.Substring(folderPath.Length);
}
_storageProvider.RenameFolder(folderPath, _storageProvider.Combine(Path.GetDirectoryName(folderPath), newFolderName));
_storageProvider.RenameFolder(folderPath, newFolderPath);
}
catch (Exception) {
_orchardServices.TransactionManager.Cancel();