Lucene index settings lock file (#7897)

Fixes #7890
This commit is contained in:
GiuseppeMusso-Laser
2017-11-30 21:10:55 +01:00
committed by Sébastien Ros
parent 59dc2bab85
commit 2821e362a0

View File

@@ -113,11 +113,34 @@ namespace Orchard.FileSystems.AppData {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
public void CreateFile(string path, string content) {
using (var stream = CreateFile(path)) {
using (var tw = new StreamWriter(stream)) {
tw.Write(content);
var filePath = CombineToPhysicalPath(path);
var folderPath = Path.GetDirectoryName(filePath);
if (!Directory.Exists(folderPath)) {
Directory.CreateDirectory(folderPath);
}
// for existing files, just overwrite
if (File.Exists(filePath)) {
File.WriteAllText(filePath, content);
} else {
WriteAllTextWithTempFileAndMove(filePath, content);
}
}
private static void WriteAllTextWithTempFileAndMove(string path, string content) {
// generate a temp file
var tempPath = Path.GetTempFileName();
// write the data to a temp file
using (var tempFile = File.Create(tempPath, 4096, FileOptions.WriteThrough)) {
using (var writer = new StreamWriter(tempFile)) {
writer.Write(content);
}
}
// move to destination
// will throw exception if destination exists
File.Move(tempPath, path);
}
public Stream CreateFile(string path) {