Browse Source

Added filesystem::get_canonical_path instead of using boost::filesystem::canonical_path that always throws if boost::filesystem::current_path fails

pipelines/143601543
eidheim 6 years ago
parent
commit
d5ac358ca5
  1. 4
      src/directories.cc
  2. 9
      src/filesystem.cc
  3. 3
      src/filesystem.h
  4. 5
      src/notebook.cc
  5. 10
      src/source_diff.cc

4
src/directories.cc

@ -823,9 +823,7 @@ void Directories::colorize_path(boost::filesystem::path dir_path_, bool include_
auto name = Glib::Markup::escape_text(child.get_value(column_record.name));
auto path = child.get_value(column_record.path);
// Use canonical path to follow symbolic links
auto canonical_path = boost::filesystem::canonical(path, ec);
if(ec)
canonical_path = path;
auto canonical_path = filesystem::get_canonical_path(path);
Gdk::RGBA *color;
if(status.modified.find(canonical_path.generic_string()) != status.modified.end())

9
src/filesystem.cc

@ -312,3 +312,12 @@ boost::filesystem::path filesystem::get_path_from_uri(const std::string &uri) {
return unencoded;
}
boost::filesystem::path filesystem::get_canonical_path(const boost::filesystem::path &path) {
try {
return boost::filesystem::canonical(path);
}
catch(...) {
return path;
}
}

3
src/filesystem.h

@ -44,4 +44,7 @@ public:
static std::string get_uri_from_path(const boost::filesystem::path &path);
/// Get path from file uri
static boost::filesystem::path get_path_from_uri(const std::string &uri);
/// Returns path on error. Do not use boost::filesystem::canonical_path since it is bugged when current_folder() fails.
static boost::filesystem::path get_canonical_path(const boost::filesystem::path &path);
};

5
src/notebook.cc

@ -116,10 +116,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, Position position
// Use canonical path to follow symbolic links
if(position == Position::infer) {
boost::system::error_code ec;
auto canonical_file_path = boost::filesystem::canonical(file_path, ec);
if(ec)
canonical_file_path = file_path;
auto canonical_file_path = filesystem::get_canonical_path(file_path);
for(size_t c = 0; c < size(); c++) {
bool equal;
{

10
src/source_diff.cc

@ -35,10 +35,7 @@ void Source::DiffView::Renderer::draw_vfunc(const Cairo::RefPtr<Cairo::Context>
}
Source::DiffView::DiffView(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language) : BaseView(file_path, language), renderer(new Renderer()) {
boost::system::error_code ec;
canonical_file_path = boost::filesystem::canonical(file_path, ec);
if(ec)
canonical_file_path = file_path;
canonical_file_path = filesystem::get_canonical_path(file_path);
renderer->tag_added = get_buffer()->create_tag("git_added");
renderer->tag_modified = get_buffer()->create_tag("git_modified");
@ -254,10 +251,7 @@ void Source::DiffView::rename(const boost::filesystem::path &path) {
Source::BaseView::rename(path);
LockGuard lock(canonical_file_path_mutex);
boost::system::error_code ec;
canonical_file_path = boost::filesystem::canonical(path, ec);
if(ec)
canonical_file_path = path;
canonical_file_path = filesystem::get_canonical_path(path);
}
void Source::DiffView::goto_next_diff() {

Loading…
Cancel
Save