Skip to content

Commit

Permalink
Use realpath on Linux when saving in an editor. This makes the save w…
Browse files Browse the repository at this point in the history
…ork for relative symlinks and symlinks-to-symlinks too.

This should fully fix #1576.

Also, move a comment line back to the code it refers to.
  • Loading branch information
dghart committed Dec 14, 2017
1 parent 733c5ae commit 766d8c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LiteEditor/cl_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,10 +1487,10 @@ bool LEditor::SaveToFile(const wxFileName& fileName)
file.Write(buf.data(), strlen(buf.data()));
file.Close();

// keep the original file permissions
wxFileName symlinkedFile = fileName;
if(wxIsFileSymlink(fileName)) { symlinkedFile = wxReadLink(fileName); }

// keep the original file permissions
mode_t origPermissions = 0;
if(!FileUtils::GetFilePermissions(symlinkedFile, origPermissions)) {
clWARNING() << "Failed to read file permissions." << fileName << clEndl;
Expand Down
6 changes: 6 additions & 0 deletions Plugin/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,11 @@ wxFileName wxReadLink(const wxFileName& filename)
{
#ifndef __WXMSW__
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()));

#else // OSX
wxFileName realFileName;
char _tmp[512];
memset(_tmp, 0, sizeof(_tmp));
Expand All @@ -1146,6 +1151,7 @@ wxFileName wxReadLink(const wxFileName& filename)
realFileName = wxFileName(wxString(_tmp, wxConvUTF8, len));
return realFileName;
}
#endif // !OSX
}
return filename;

Expand Down

0 comments on commit 766d8c7

Please sign in to comment.