diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2013-08-13 14:41:26 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2013-08-13 14:41:26 +0400 |
commit | cd7664496cf3b205f10b25acac146499f6c82b36 (patch) | |
tree | df0e05eb0c750a0a1d702000d259787ec0f5a941 /main/src/core/Mono.Texteditor | |
parent | 414b8686841f9b4c646b0f693130252a627e88a2 (diff) |
[TextEditor] Text file utility save function now works when the file
to write is accessible, but path isn't.
Diffstat (limited to 'main/src/core/Mono.Texteditor')
-rw-r--r-- | main/src/core/Mono.Texteditor/Mono.TextEditor.Utils/TextFileUtility.cs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor.Utils/TextFileUtility.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor.Utils/TextFileUtility.cs index 5b9a577a2a..fe08149dd1 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor.Utils/TextFileUtility.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor.Utils/TextFileUtility.cs @@ -202,7 +202,7 @@ namespace Mono.TextEditor.Utils if (encoding == null) throw new ArgumentNullException ("encoding"); - string tmpPath = Path.Combine (Path.GetDirectoryName (fileName), ".#" + Path.GetFileName (fileName)); + string tmpPath = Path.GetTempFileName (); using (var stream = new FileStream (tmpPath, FileMode.Create, FileAccess.Write, FileShare.Write)) { if (hadBom) { var bom = encoding.GetPreamble (); @@ -212,7 +212,16 @@ namespace Mono.TextEditor.Utils byte[] bytes = encoding.GetBytes (text); stream.Write (bytes, 0, bytes.Length); } - SystemRename (tmpPath, fileName); + try { + SystemRename (tmpPath, fileName); + } catch (Exception) { + try { + System.IO.File.Delete (tmpPath); + } catch { + // nothing + } + throw; + } } /// <summary> |