Skip to content

Commit 546d569

Browse files
authored
Merge pull request #234 from toolstack/fix-sym-links
Rewrite logic for saving notes to replace contents...
2 parents b012281 + 522019a commit 546d569

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

lib/util/file_utils.vala

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,25 @@ namespace FileUtils {
33
public void save_to (File file, string text) {
44
try {
55
if (file.query_exists ()) {
6+
// If the file already exists check to see if anything has changed, if not, bail.
67
string etag_out;
78
uint8[] text_data = {};
89
file.load_contents (null, out text_data, out etag_out);
910
if (text == (string) text_data) {
1011
return;
1112
}
12-
file.delete ();
13-
}
14-
// Let's make sure the directory exists we're trying to save to.
15-
// If it doesn't, create it.
16-
var path = file.get_parent ().get_parse_name ();
17-
var dir = File.new_for_path (path);
18-
if (!dir.query_exists ()) {
19-
dir.make_directory_with_parents ();
20-
}
21-
var data_stream = new DataOutputStream (
22-
file.create (FileCreateFlags.REPLACE_DESTINATION)
23-
);
24-
uint8[] data = text.data;
25-
var l = data.length;
26-
long written = 0;
27-
while (written < l) {
28-
written += data_stream.write (data[written:data.length]);
13+
} else {
14+
// Let's make sure the directory exists we're trying to save to.
15+
// If it doesn't, create it.
16+
var path = file.get_parent ().get_parse_name ();
17+
var dir = File.new_for_path (path);
18+
if (!dir.query_exists ()) {
19+
dir.make_directory_with_parents ();
20+
}
2921
}
22+
23+
// Write the text out to the file.
24+
file.replace_contents (text.data, null, false, FileCreateFlags.NONE, null);
3025
} catch (Error e) {
3126
error (e.message);
3227
}

0 commit comments

Comments
 (0)