Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
UffeJakobsen committed Jul 19, 2024
1 parent d1ff88d commit 7678c01
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CodeLite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ include_directories(
"${CL_SRC_ROOT}/CodeLite/ssh"
"${CL_SRC_ROOT}/PCH"
"${CL_SRC_ROOT}/Interfaces"
"${CL_SRC_ROOT}/CodeLite/ssh")
"${CL_SRC_ROOT}/Plugin"
)

set(ADDITIONAL_LIBRARIES "")

Expand Down
25 changes: 14 additions & 11 deletions CodeLite/clFilesCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "file_logger.h"
#include "fileutils.h"
#include "globals.h"

#include <queue>
#include <unordered_set>
Expand All @@ -10,6 +11,8 @@
#include <wx/filename.h>
#include <wx/tokenzr.h>

static wxString my_CLRealPath(const wxString& filepath) { return filepath; }

clFilesScanner::clFilesScanner() {}

clFilesScanner::~clFilesScanner() {}
Expand Down Expand Up @@ -110,19 +113,19 @@ size_t clFilesScanner::Scan(const wxString& rootFolder, std::vector<wxString>& f
filename.MakeLower();
#endif
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(my_CLRealPath(fullpath)))
#else
(excludeFolders.count(FileUtils::RealPath(fullpath))
(excludeFolders.count(my_CLRealPath(fullpath))
#endif
|| IsRelPathContainedInSpec(rootFolder, fullpath, excludeFolders)));
if (isDirectory && !isExcludeDir) {
// Traverse into this folder
wxString realPath = FileUtils::RealPath(fullpath);
wxString realPath = my_CLRealPath(fullpath);
if (Visited.insert(realPath).second) {
Q.push(fullpath);
}
Expand Down Expand Up @@ -153,8 +156,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(my_CLRealPath(rootFolder));
Visited.insert(my_CLRealPath(rootFolder));

size_t nCount = 0;
while (!Q.empty()) {
Expand All @@ -174,11 +177,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 = my_CLRealPath(fullpath);
if (Visited.count(real_path) == 0) {
Visited.insert(real_path);
Q.push(fullpath);
Expand Down Expand Up @@ -259,8 +262,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(my_CLRealPath(rootFolder));
Visited.insert(my_CLRealPath(rootFolder));

while (!Q.empty()) {
wxString dirpath = Q.front();
Expand Down Expand Up @@ -299,7 +302,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 = my_CLRealPath(fullpath);
if (Visited.insert(real_path).second) {
Q.push_back(fullpath);
}
Expand Down
20 changes: 14 additions & 6 deletions LiteEditor/mainbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,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(fullpath, true);
#endif

for (size_t i = 0; i < m_book->GetPageCount(); ++i) {
Expand Down Expand Up @@ -466,7 +466,7 @@ int MainBook::FindEditorIndexByFullPath(const wxString& fullpath)

#if defined(__WXGTK__)
// Try again, dereferencing the editor fpath
wxString editorDest = CLRealPath(unixStyleFile);
wxString editorDest = CLRealPath(unixStyleFile, true);
if (editorDest.Cmp(fullpath) == 0 || editorDest.Cmp(fileNameDest) == 0) {
return i;
}
Expand Down Expand Up @@ -595,6 +595,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__
Expand Down Expand Up @@ -1746,7 +1753,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(file_name, true);
auto editor = FindEditor(real_path);
if (editor) {
push_callback(std::move(callback), real_path);
Expand All @@ -1757,7 +1764,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);
}
Expand Down Expand Up @@ -1822,11 +1829,12 @@ void MainBook::OnIdle(wxIdleEvent& event)
auto editor = GetActiveEditor();
CHECK_PTR_RET(editor);

execute_callbacks_for_file(CLRealPath(editor->GetFileName().GetFullPath()));
execute_callbacks_for_file(CLRealPath(editor->GetFileName().GetFullPath(), true));
}

void MainBook::OnEditorModified(clCommandEvent& event) { event.Skip(); }

void MainBook::OnEditorSaved(clCommandEvent& event) { event.Skip(); }

void MainBook::OnSessionLoaded(clCommandEvent& event) { event.Skip(); }
void MainBook::OnSessionLoaded(clCommandEvent& event) { event.Skip(); }

10 changes: 7 additions & 3 deletions Plugin/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,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;
Expand All @@ -936,10 +936,14 @@ wxFileName wxReadLink(const wxFileName& filename)
#endif
}

wxString CLRealPath(const wxString& filepath) // This is readlink on steroids: it also makes-absolute, and dereferences
wxString CLRealPath(const wxString& filepath, bool force) // This is readlink on steroids: it also makes-absolute, and dereferences
// any symlinked dirs in the path
{
return FileUtils::RealPath(filepath);
if (force) {
return FileUtils::RealPath(filepath);
} else {
return filepath;
}
}

int wxStringToInt(const wxString& str, int defval, int minval, int maxval)
Expand Down
2 changes: 1 addition & 1 deletion Plugin/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,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(const wxString& filepath, bool force=false);

/**
* @brief convert string to integer using range validation and default value
Expand Down

0 comments on commit 7678c01

Please sign in to comment.