From 28fd15307bba85f08bb5dee6a7c2b33b124e78c7 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Sat, 15 Apr 2017 13:30:27 +0200 Subject: [PATCH] Care for a tilde in front of a path name. A path name with tilde sign at start is interpreted as relative to the current users home directory. --- src/support/FileName.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 929c4165be..e70279ccbd 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -89,7 +89,7 @@ struct FileName::Private { Private() {} - Private(string const & abs_filename) : fi(toqstr(abs_filename)) + Private(string const & abs_filename) : fi(toqstr(handleTildeName(abs_filename))) { name = fromqstr(fi.absoluteFilePath()); fi.setCaching(fi.exists() ? true : false); @@ -100,7 +100,6 @@ struct FileName::Private fi.refresh(); } - static bool isFilesystemEqual(QString const & lhs, QString const & rhs) { @@ -108,6 +107,14 @@ struct FileName::Private Qt::CaseSensitive : Qt::CaseInsensitive) == 0; } + static + string const handleTildeName(string const & name) + { + return name == "~" ? Package::get_home_dir().absFileName() : + prefixIs(name, "~/") ? Package::get_home_dir().absFileName() + name.substr(1) : + name; + } + /// The absolute file name in UTF-8 encoding. std::string name; /// @@ -171,7 +178,7 @@ bool FileName::empty() const bool FileName::isAbsolute(string const & name) { - QFileInfo fi(toqstr(name)); + QFileInfo fi(toqstr(Private::handleTildeName(name))); return fi.isAbsolute(); } @@ -190,7 +197,7 @@ string FileName::realPath() const void FileName::set(string const & name) { - d->fi.setFile(toqstr(name)); + d->fi.setFile(toqstr(Private::handleTildeName(name))); d->name = fromqstr(d->fi.absoluteFilePath()); //LYXERR(Debug::FILES, "FileName::set(" << name << ')'); LATTEST(empty() || isAbsolute(d->name)); -- 2.39.5