Merge lp:~darcy-develin/scratch/upstream-fix-1038291 into lp:~elementary-apps/scratch/scratch

Proposed by Darcy Luís Neves Brás da Silva
Status: Merged
Approved by: Mario Guerriero
Approved revision: 874
Merged at revision: 873
Proposed branch: lp:~darcy-develin/scratch/upstream-fix-1038291
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 81 lines (+27/-25)
1 file modified
src/Services/Document.vala (+27/-25)
To merge this branch: bzr merge lp:~darcy-develin/scratch/upstream-fix-1038291
Reviewer Review Type Date Requested Status
elementary Apps team Pending
Review via email: mp+124504@code.launchpad.net

Description of the change

fixes bug #1038291, and cleanup can_write function to,
        enforce control flow trough writable variable,
        allow writting on first edit files that don't
        exist.
        PS: filename == null is being allowed because
        the program still relies on this, needs fixing

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Services/Document.vala'
2--- src/Services/Document.vala 2012-08-04 08:49:40 +0000
3+++ src/Services/Document.vala 2012-09-14 19:24:31 +0000
4@@ -83,7 +83,6 @@
5 return DocumentStates.NORMAL;
6 else
7 return DocumentStates.READONLY;
8- return _state;
9 }
10 }
11
12@@ -406,8 +405,8 @@
13 modified = false;
14 opening = false;
15 tab.text_view.modified = false;
16+ timeout_saving = -1;
17 return false;
18- timeout_saving = -1;
19 });
20 }
21 else {
22@@ -718,33 +717,36 @@
23
24 public bool can_write () {
25
26- if (filename != null) {
27-
28- FileInfo info;
29- bool writable;
30-
31- try {
32-
33- info = file.query_info (FileAttribute.ACCESS_CAN_WRITE, FileQueryInfoFlags.NONE, null);
34- writable = info.get_attribute_boolean (FileAttribute.ACCESS_CAN_WRITE);
35-
36- return writable;
37-
38- } catch (Error e) {
39-
40- warning ("%s", e.message);
41- return false;
42-
43+ FileInfo info;
44+ //false by default, this way state always flow trough writable
45+ bool writable = false;
46+
47+ //this is flood logic, a null filename should be an error, but since
48+ //the rest of the program relies on this assumption, it will be allowed
49+ //for now
50+ if (filename == null) {
51+ debug ("filename is set to null, assuming it's a new file");
52+ return writable = true;
53+ }
54+
55+ try {
56+ info = file.query_info(FileAttribute.ACCESS_CAN_WRITE, FileQueryInfoFlags.NONE, null);
57+ writable = info.get_attribute_boolean(FileAttribute.ACCESS_CAN_WRITE);
58+ return writable;
59+ } catch (Error e) {
60+
61+ if (filename != null ) {
62+ warning ("query_info failed, but filename appears to be correct, allowing as new file");
63+ writable = true;
64 }
65-
66- } else {
67-
68- return true;
69-
70+
71+ return writable;
72+
73 }
74-
75 }
76
77+
78+
79 }
80
81 }

Subscribers

People subscribed via source and target branches