summarylogtreecommitdiffstats
path: root/codelite-fsw-symlink.patch
blob: 1a6440edc28d50f0e1881734d9b07266d0a0fce3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
diff --git CodeLite/clFilesCollector.cpp CodeLite/clFilesCollector.cpp
index a57949053..d6b785f48 100644
--- CodeLite/clFilesCollector.cpp
+++ CodeLite/clFilesCollector.cpp
@@ -2,6 +2,7 @@
 
 #include "file_logger.h"
 #include "fileutils.h"
+//#include "globals.h"
 
 #include <queue>
 #include <vector>
@@ -9,6 +10,11 @@
 #include <wx/filename.h>
 #include <wx/tokenzr.h>
 
+static wxString CLRealPath(const wxString& str)
+{
+    return str;
+}
+
 clFilesScanner::clFilesScanner() {}
 
 clFilesScanner::~clFilesScanner() {}
@@ -95,19 +101,19 @@ size_t clFilesScanner::Scan(const wxString& rootFolder, std::vector<wxString>& f
             wxString fullpath;
             fullpath << dir.GetNameWithSep() << filename;
             bool isDirectory = wxFileName::DirExists(fullpath);
-            // Use FileUtils::RealPath() here to cope with symlinks on Linux
+            // Use CLRealPath() here to cope with symlinks on Linux
             bool isExcludeDir =
                 isDirectory &&
                 (
 #if defined(__FreeBSD__)
-                    ((FileUtils::IsSymlink(fullpath) && excludeFolders.count(FileUtils::RealPath(fullpath)))
+                    ((FileUtils::IsSymlink(fullpath) && excludeFolders.count(CLRealPath(fullpath)))
 #else
-                    (excludeFolders.count(FileUtils::RealPath(fullpath))
+                    (excludeFolders.count(CLRealPath(fullpath))
 #endif
                      || IsRelPathContainedInSpec(rootFolder, fullpath, excludeFolders)));
             if(isDirectory && !isExcludeDir) {
                 // Traverse into this folder
-                wxString realPath = FileUtils::RealPath(fullpath);
+                wxString realPath = CLRealPath(fullpath);
                 if(Visited.insert(realPath).second) {
                     Q.push(fullpath);
                 }
@@ -138,8 +144,8 @@ size_t clFilesScanner::Scan(const wxString& rootFolder, const wxString& filespec
     std::queue<wxString> Q;
     std::unordered_set<wxString> Visited;
 
-    Q.push(FileUtils::RealPath(rootFolder));
-    Visited.insert(FileUtils::RealPath(rootFolder));
+    Q.push(CLRealPath(rootFolder));
+    Visited.insert(CLRealPath(rootFolder));
 
     size_t nCount = 0;
     while(!Q.empty()) {
@@ -159,11 +165,11 @@ size_t clFilesScanner::Scan(const wxString& rootFolder, const wxString& filespec
             fullpath << dir.GetNameWithSep() << filename;
             bool isDirectory = wxFileName::DirExists(fullpath);
             bool isFile = !isDirectory;
-            // Use FileUtils::RealPath() here to cope with symlinks on Linux
+            // Use CLRealPath() here to cope with symlinks on Linux
             if(isDirectory /* a folder */ &&
                !FileUtils::WildMatch(excludeFoldersSpecArr, filename) /* does not match the exclude folder spec */) {
                 // Traverse into this folder
-                wxString real_path = FileUtils::RealPath(fullpath);
+                wxString real_path = CLRealPath(fullpath);
                 if(Visited.count(real_path) == 0) {
                     Visited.insert(real_path);
                     Q.push(fullpath);
@@ -244,8 +250,8 @@ void clFilesScanner::ScanWithCallbacks(const wxString& rootFolder, std::function
     std::vector<wxString> Q;
     std::unordered_set<wxString> Visited;
 
-    Q.push_back(FileUtils::RealPath(rootFolder));
-    Visited.insert(FileUtils::RealPath(rootFolder));
+    Q.push_back(CLRealPath(rootFolder));
+    Visited.insert(CLRealPath(rootFolder));
 
     while(!Q.empty()) {
         wxString dirpath = Q.front();
@@ -284,7 +290,7 @@ void clFilesScanner::ScanWithCallbacks(const wxString& rootFolder, std::function
 
                 if(on_folder_cb && on_folder_cb(fullpath)) {
                     // Traverse into this folder
-                    wxString real_path = FileUtils::RealPath(fullpath);
+                    wxString real_path = CLRealPath(fullpath);
                     if(Visited.insert(real_path).second) {
                         Q.push_back(fullpath);
                     }
diff --git LiteEditor/mainbook.cpp LiteEditor/mainbook.cpp
index b54732a3b..2e47533d8 100644
--- LiteEditor/mainbook.cpp
+++ LiteEditor/mainbook.cpp
@@ -469,7 +469,7 @@ int MainBook::FindEditorIndexByFullPath(const wxString& fullpath)
 {
 #ifdef __WXGTK__
     // On gtk either fileName or the editor filepath (or both) may be (or their paths contain) symlinks
-    wxString fileNameDest = CLRealPath(fullpath);
+    wxString fileNameDest = CLRealPath_forced(fullpath);
 #endif
 
     for(size_t i = 0; i < m_book->GetPageCount(); i++) {
@@ -503,7 +503,7 @@ int MainBook::FindEditorIndexByFullPath(const wxString& fullpath)
 
 #if defined(__WXGTK__)
                 // Try again, dereferencing the editor fpath
-                wxString editorDest = CLRealPath(unixStyleFile);
+                wxString editorDest = CLRealPath_forced(unixStyleFile);
                 if(editorDest.Cmp(fullpath) == 0 || editorDest.Cmp(fileNameDest) == 0) {
                     return i;
                 }
@@ -640,6 +640,13 @@ clEditor* MainBook::OpenFile(const wxString& file_name, const wxString& projectN
                              int bmp /*= wxNullBitmap*/, const wxString& tooltip /* wxEmptyString */)
 {
     wxFileName fileName(CLRealPath(file_name));
+
+    if (fileName.IsRelative()) {
+        if (clWorkspaceManager::Get().IsWorkspaceOpened()) {
+            wxFileName wsPath = clWorkspaceManager::Get().GetWorkspace()->GetDir();
+            fileName.MakeAbsolute(wsPath.GetFullPath());
+        }
+    }
     fileName.MakeAbsolute();
 
 #ifdef __WXMSW__
@@ -1831,7 +1838,7 @@ WelcomePage* MainBook::GetWelcomePage(bool createIfMissing)
 
 clEditor* MainBook::OpenFileAsync(const wxString& file_name, std::function<void(IEditor*)>&& callback)
 {
-    wxString real_path = CLRealPath(file_name);
+    wxString real_path = CLRealPath_forced(file_name);
     auto editor = FindEditor(real_path);
     if(editor) {
         push_callback(std::move(callback), real_path);
@@ -1842,7 +1849,7 @@ clEditor* MainBook::OpenFileAsync(const wxString& file_name, std::function<void(
             m_book->SetSelection(index);
         }
     } else {
-        editor = OpenFile(real_path);
+        editor = OpenFile(file_name);
         if(editor) {
             push_callback(std::move(callback), real_path);
         }
@@ -1901,7 +1908,7 @@ void MainBook::OnIdle(wxIdleEvent& event)
     auto editor = GetActiveEditor(false);
     CHECK_PTR_RET(editor);
 
-    execute_callbacks_for_file(CLRealPath(editor->GetFileName().GetFullPath()));
+    execute_callbacks_for_file(CLRealPath_forced(editor->GetFileName().GetFullPath()));
 }
 
 void MainBook::OnEditorModified(clCommandEvent& event)
diff --git Plugin/globals.cpp Plugin/globals.cpp
index 7b24e91d5..ce1ca78ab 100644
--- Plugin/globals.cpp
+++ Plugin/globals.cpp
@@ -1095,7 +1095,7 @@ wxFileName wxReadLink(const wxFileName& filename)
     if(wxIsFileSymlink(filename)) {
 #if defined(__WXGTK__)
         // Use 'realpath' on Linux, otherwise this breaks on relative symlinks, and (untested) on symlinks-to-symlinks
-        return wxFileName(CLRealPath(filename.GetFullPath()));
+        return wxFileName(FileUtils::RealPath(filename.GetFullPath()));
 
 #else  // OSX
         wxFileName realFileName;
@@ -1115,12 +1115,19 @@ wxFileName wxReadLink(const wxFileName& filename)
 #endif
 }
 
-wxString CLRealPath(const wxString& filepath) // This is readlink on steroids: it also makes-absolute, and dereferences
+wxString CLRealPath_forced(const wxString& filepath) // This is readlink on steroids: it also makes-absolute, and dereferences
                                               // any symlinked dirs in the path
 {
     return FileUtils::RealPath(filepath);
 }
 
+wxString CLRealPath(const wxString& filepath) // This is readlink on steroids: it also makes-absolute, and dereferences
+                                              // any symlinked dirs in the path
+{
+    //return CLRealPath_forced(filepath);
+    return filepath;
+}
+
 int wxStringToInt(const wxString& str, int defval, int minval, int maxval)
 {
     long v;
diff --git Plugin/globals.h Plugin/globals.h
index 0ae8d1fd5..1e21da4b1 100644
--- Plugin/globals.h
+++ Plugin/globals.h
@@ -379,6 +379,7 @@ WXDLLIMPEXP_SDK wxFileName wxReadLink(const wxFileName& filename);
  * @brief makes-absolute filepath, and dereferences it and any symlinked dirs in the path
  */
 WXDLLIMPEXP_SDK wxString CLRealPath(const wxString& filepath);
+WXDLLIMPEXP_SDK wxString CLRealPath_forced(const wxString& filepath);
 
 /**
  * @brief convert string to integer using range validation and default value