[gedit-code-assistance] Write temporary files to ~/.cache
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-code-assistance] Write temporary files to ~/.cache
- Date: Sat, 9 Nov 2013 12:13:31 +0000 (UTC)
commit baec9fe57520aced51b47c17b0fceab86dec4858
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sat Nov 9 13:13:23 2013 +0100
Write temporary files to ~/.cache
This also makes sure that the directory is protected the first time.
src/gca-document.vala | 33 ++++++++++++++++++++++++++++-----
1 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/src/gca-document.vala b/src/gca-document.vala
index 6eb6cce..8d934bf 100644
--- a/src/gca-document.vala
+++ b/src/gca-document.vala
@@ -37,6 +37,8 @@ public class Document : Object
public signal void location_changed(File? previous_location);
public signal void changed();
+ private static bool s_needs_tmp_chmod = true;
+
public Gedit.Document document
{
get { return d_document; }
@@ -236,11 +238,32 @@ public class Document : Object
filename = "gca-unsaved-XXXXXX";
}
- FileIOStream stream;
- File f;
+ var cdir = Environment.get_user_cache_dir();
+ var tmpdir = Path.build_filename(cdir, "gedit", "plugins", "codeassistance");
+ var f = File.new_for_path(tmpdir);
+
+ try
+ {
+ f.make_directory_with_parents();
+ }
+ catch (IOError e)
+ {
+ if (!(e is IOError.EXISTS))
+ {
+ throw e;
+ }
+ }
+
+ if (s_needs_tmp_chmod)
+ {
+ FileUtils.chmod(tmpdir, 0700);
+ s_needs_tmp_chmod = false;
+ }
+
+ var tmpfilename = Path.build_filename(tmpdir, filename);
+ var tmpfile = FileUtils.mkstemp(tmpfilename);
- f = File.new_tmp(filename, out stream);
- var ostream = stream.output_stream;
+ var ostream = new UnixOutputStream(tmpfile, true);
try
{
@@ -262,7 +285,7 @@ public class Document : Object
}
ostream.close();
- d_unsaved_file = f;
+ d_unsaved_file = File.new_for_path(tmpfilename);
return d_unsaved_file.get_path();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]