#18832: Overwrite files when unzipping a media folder

Work Item: 18832

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-09-19 17:20:58 -07:00
parent acdd97a35d
commit e33eb89e80

View File

@@ -310,8 +310,20 @@ namespace Orchard.Media.Services {
// skip disallowed files
if (FileAllowed(entry.FileName, false)) {
string fullFileName = _storageProvider.Combine(targetFolder, entry.FileName);
using (var stream = entry.OpenReader()) {
_storageProvider.TrySaveStream(fullFileName, stream);
// the call will return false if the file already exists
if (!_storageProvider.TrySaveStream(fullFileName, stream)) {
// try to delete the file and save again
try {
_storageProvider.DeleteFile(fullFileName);
_storageProvider.TrySaveStream(fullFileName, stream);
}
catch (ArgumentException) {
// ignore the exception as the file doesn't exist
}
}
}
}
}