mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 03:11:59 +00:00
start using FileName::exists()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21044 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a5031475be
commit
0e08bc5e16
@ -416,9 +416,8 @@ pair<Buffer::LogType, string> const Buffer::getLogName() const
|
|||||||
|
|
||||||
// If no Latex log or Build log is newer, show Build log
|
// If no Latex log or Build log is newer, show Build log
|
||||||
|
|
||||||
if (fs::exists(bname.toFilesystemEncoding()) &&
|
if (bname.exists() &&
|
||||||
(!fs::exists(fname.toFilesystemEncoding()) ||
|
(!fname.exists() || fname.lastModified() < bname.lastModified())) {
|
||||||
fs::last_write_time(fname.toFilesystemEncoding()) < fs::last_write_time(bname.toFilesystemEncoding()))) {
|
|
||||||
LYXERR(Debug::FILES) << "Log name calculated as: " << bname << endl;
|
LYXERR(Debug::FILES) << "Log name calculated as: " << bname << endl;
|
||||||
return make_pair(Buffer::buildlog, bname.absFilename());
|
return make_pair(Buffer::buildlog, bname.absFilename());
|
||||||
}
|
}
|
||||||
@ -688,7 +687,7 @@ bool Buffer::readFile(FileName const & filename)
|
|||||||
//
|
//
|
||||||
FileName lyxfile(addName(temppath(), "content.lyx"));
|
FileName lyxfile(addName(temppath(), "content.lyx"));
|
||||||
// if both manifest.txt and file.lyx exist, this is am embedded file
|
// if both manifest.txt and file.lyx exist, this is am embedded file
|
||||||
if (fs::exists(lyxfile.toFilesystemEncoding())) {
|
if (lyxfile.exists()) {
|
||||||
params().embedded = true;
|
params().embedded = true;
|
||||||
fname = lyxfile;
|
fname = lyxfile;
|
||||||
}
|
}
|
||||||
@ -1645,10 +1644,10 @@ bool Buffer::isBakClean() const
|
|||||||
|
|
||||||
bool Buffer::isExternallyModified(CheckMethod method) const
|
bool Buffer::isExternallyModified(CheckMethod method) const
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(fs::exists(pimpl_->filename.toFilesystemEncoding()));
|
BOOST_ASSERT(pimpl_->filename.exists());
|
||||||
// if method == timestamp, check timestamp before checksum
|
// if method == timestamp, check timestamp before checksum
|
||||||
return (method == checksum_method
|
return (method == checksum_method
|
||||||
|| pimpl_->timestamp_ != fs::last_write_time(pimpl_->filename.toFilesystemEncoding()))
|
|| pimpl_->timestamp_ != pimpl_->filename.lastModified())
|
||||||
&& pimpl_->checksum_ != sum(pimpl_->filename);
|
&& pimpl_->checksum_ != sum(pimpl_->filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2136,7 +2135,7 @@ bool Buffer::writeAs(string const & newname)
|
|||||||
} else
|
} else
|
||||||
fname = makeAbsPath(newname, onlyPath(oldname)).absFilename();
|
fname = makeAbsPath(newname, onlyPath(oldname)).absFilename();
|
||||||
|
|
||||||
if (fs::exists(FileName(fname).toFilesystemEncoding())) {
|
if (FileName(fname).exists()) {
|
||||||
docstring const file = makeDisplayPath(fname, 30);
|
docstring const file = makeDisplayPath(fname, 30);
|
||||||
docstring text = bformat(_("The document %1$s already "
|
docstring text = bformat(_("The document %1$s already "
|
||||||
"exists.\n\nDo you want to "
|
"exists.\n\nDo you want to "
|
||||||
|
@ -135,7 +135,7 @@ void ConverterCache::Impl::readIndex()
|
|||||||
CacheItem item(orig_from_name, to_format, timestamp, checksum);
|
CacheItem item(orig_from_name, to_format, timestamp, checksum);
|
||||||
|
|
||||||
// Don't cache files that do not exist anymore
|
// Don't cache files that do not exist anymore
|
||||||
if (!fs::exists(orig_from_name.toFilesystemEncoding())) {
|
if (!orig_from_name.exists()) {
|
||||||
LYXERR(Debug::FILES) << "Not caching file `"
|
LYXERR(Debug::FILES) << "Not caching file `"
|
||||||
<< orig_from << "' (does not exist anymore)."
|
<< orig_from << "' (does not exist anymore)."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@ -146,7 +146,7 @@ void ConverterCache::Impl::readIndex()
|
|||||||
// Don't add items that are not in the cache anymore
|
// Don't add items that are not in the cache anymore
|
||||||
// This can happen if two instances of LyX are running
|
// This can happen if two instances of LyX are running
|
||||||
// at the same time and update the index file independantly.
|
// at the same time and update the index file independantly.
|
||||||
if (!fs::exists(item.cache_name.toFilesystemEncoding())) {
|
if (!item.cache_name.exists()) {
|
||||||
LYXERR(Debug::FILES) << "Not caching file `"
|
LYXERR(Debug::FILES) << "Not caching file `"
|
||||||
<< orig_from
|
<< orig_from
|
||||||
<< "' (cached copy does not exist anymore)."
|
<< "' (cached copy does not exist anymore)."
|
||||||
@ -155,8 +155,8 @@ void ConverterCache::Impl::readIndex()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete the cached file if it is too old
|
// Delete the cached file if it is too old
|
||||||
if (difftime(now, fs::last_write_time(item.cache_name.toFilesystemEncoding())) >
|
if (difftime(now, item.cache_name.lastModified())
|
||||||
lyxrc.converter_cache_maxage) {
|
> lyxrc.converter_cache_maxage) {
|
||||||
LYXERR(Debug::FILES) << "Not caching file `"
|
LYXERR(Debug::FILES) << "Not caching file `"
|
||||||
<< orig_from << "' (too old)." << std::endl;
|
<< orig_from << "' (too old)." << std::endl;
|
||||||
support::unlink(item.cache_name);
|
support::unlink(item.cache_name);
|
||||||
@ -228,7 +228,7 @@ void ConverterCache::init()
|
|||||||
// We do this here and not in the constructor because package() gets
|
// We do this here and not in the constructor because package() gets
|
||||||
// initialized after all static variables.
|
// initialized after all static variables.
|
||||||
cache_dir = FileName(addName(support::package().user_support().absFilename(), "cache"));
|
cache_dir = FileName(addName(support::package().user_support().absFilename(), "cache"));
|
||||||
if (!fs::exists(cache_dir.toFilesystemEncoding()))
|
if (!cache_dir.exists())
|
||||||
if (support::mkdir(cache_dir, 0700) != 0) {
|
if (support::mkdir(cache_dir, 0700) != 0) {
|
||||||
lyxerr << "Could not create cache directory `"
|
lyxerr << "Could not create cache directory `"
|
||||||
<< cache_dir << "'." << std::endl;
|
<< cache_dir << "'." << std::endl;
|
||||||
@ -273,7 +273,7 @@ void ConverterCache::add(FileName const & orig_from, string const & to_format,
|
|||||||
// Is the file in the cache already?
|
// Is the file in the cache already?
|
||||||
CacheItem * item = pimpl_->find(orig_from, to_format);
|
CacheItem * item = pimpl_->find(orig_from, to_format);
|
||||||
|
|
||||||
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
|
time_t const timestamp = orig_from.lastModified();
|
||||||
Mover const & mover = getMover(to_format);
|
Mover const & mover = getMover(to_format);
|
||||||
if (item) {
|
if (item) {
|
||||||
LYXERR(Debug::FILES) << "ConverterCache::add(" << orig_from << "):\n"
|
LYXERR(Debug::FILES) << "ConverterCache::add(" << orig_from << "):\n"
|
||||||
|
@ -78,7 +78,7 @@ vector<string> const Backends(Buffer const & buffer)
|
|||||||
/// ask the user what to do if a file already exists
|
/// ask the user what to do if a file already exists
|
||||||
int checkOverwrite(FileName const & filename)
|
int checkOverwrite(FileName const & filename)
|
||||||
{
|
{
|
||||||
if (fs::exists(filename.toFilesystemEncoding())) {
|
if (filename.exists()) {
|
||||||
docstring text = bformat(_("The file %1$s already exists.\n\n"
|
docstring text = bformat(_("The file %1$s already exists.\n\n"
|
||||||
"Do you want to overwrite that file?"),
|
"Do you want to overwrite that file?"),
|
||||||
makeDisplayPath(filename.absFilename()));
|
makeDisplayPath(filename.absFilename()));
|
||||||
@ -243,7 +243,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
|
|||||||
}
|
}
|
||||||
if (status == CANCEL) {
|
if (status == CANCEL) {
|
||||||
buffer->message(_("Document export cancelled."));
|
buffer->message(_("Document export cancelled."));
|
||||||
} else if (fs::exists(tmp_result_file.toFilesystemEncoding())) {
|
} else if (tmp_result_file.exists()) {
|
||||||
// Finally copy the main file
|
// Finally copy the main file
|
||||||
status = copyFile(format, tmp_result_file,
|
status = copyFile(format, tmp_result_file,
|
||||||
FileName(result_file), result_file,
|
FileName(result_file), result_file,
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
#include "support/os.h"
|
#include "support/os.h"
|
||||||
#include "support/Systemcall.h"
|
#include "support/Systemcall.h"
|
||||||
|
|
||||||
#include <boost/filesystem/operations.hpp>
|
|
||||||
|
|
||||||
using std::find_if;
|
using std::find_if;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::distance;
|
using std::distance;
|
||||||
@ -49,7 +47,6 @@ using support::Systemcall;
|
|||||||
using support::token;
|
using support::token;
|
||||||
|
|
||||||
namespace Alert = frontend::Alert;
|
namespace Alert = frontend::Alert;
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
namespace os = support::os;
|
namespace os = support::os;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -266,7 +263,7 @@ void Formats::setViewer(string const & name, string const & command)
|
|||||||
bool Formats::view(Buffer const & buffer, FileName const & filename,
|
bool Formats::view(Buffer const & buffer, FileName const & filename,
|
||||||
string const & format_name) const
|
string const & format_name) const
|
||||||
{
|
{
|
||||||
if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
|
if (filename.empty() || !filename.exists()) {
|
||||||
Alert::error(_("Cannot view file"),
|
Alert::error(_("Cannot view file"),
|
||||||
bformat(_("File does not exist: %1$s"),
|
bformat(_("File does not exist: %1$s"),
|
||||||
from_utf8(filename.absFilename())));
|
from_utf8(filename.absFilename())));
|
||||||
@ -336,7 +333,7 @@ bool Formats::view(Buffer const & buffer, FileName const & filename,
|
|||||||
bool Formats::edit(Buffer const & buffer, FileName const & filename,
|
bool Formats::edit(Buffer const & buffer, FileName const & filename,
|
||||||
string const & format_name) const
|
string const & format_name) const
|
||||||
{
|
{
|
||||||
if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
|
if (filename.empty() || !filename.exists()) {
|
||||||
Alert::error(_("Cannot edit file"),
|
Alert::error(_("Cannot edit file"),
|
||||||
bformat(_("File does not exist: %1$s"),
|
bformat(_("File does not exist: %1$s"),
|
||||||
from_utf8(filename.absFilename())));
|
from_utf8(filename.absFilename())));
|
||||||
|
@ -213,7 +213,7 @@ int LaTeX::run(TeXErrors & terr)
|
|||||||
// remake the dependency file.
|
// remake the dependency file.
|
||||||
//
|
//
|
||||||
|
|
||||||
bool had_depfile = fs::exists(depfile.toFilesystemEncoding());
|
bool had_depfile = depfile.exists();
|
||||||
bool run_bibtex = false;
|
bool run_bibtex = false;
|
||||||
FileName const aux_file(changeExtension(file.absFilename(), "aux"));
|
FileName const aux_file(changeExtension(file.absFilename(), "aux"));
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ int LaTeX::run(TeXErrors & terr)
|
|||||||
// have aborted on error last time... in which cas we need
|
// have aborted on error last time... in which cas we need
|
||||||
// to re-run latex and collect the error messages
|
// to re-run latex and collect the error messages
|
||||||
// (even if they are the same).
|
// (even if they are the same).
|
||||||
if (!fs::exists(output_file.toFilesystemEncoding())) {
|
if (!output_file.exists()) {
|
||||||
LYXERR(Debug::DEPEND)
|
LYXERR(Debug::DEPEND)
|
||||||
<< "re-running LaTeX because output file doesn't exist."
|
<< "re-running LaTeX because output file doesn't exist."
|
||||||
<< endl;
|
<< endl;
|
||||||
@ -291,8 +291,7 @@ int LaTeX::run(TeXErrors & terr)
|
|||||||
// memoir (at least) writes an empty *idx file in the first place.
|
// memoir (at least) writes an empty *idx file in the first place.
|
||||||
// A second latex run is needed.
|
// A second latex run is needed.
|
||||||
FileName const idxfile(changeExtension(file.absFilename(), ".idx"));
|
FileName const idxfile(changeExtension(file.absFilename(), ".idx"));
|
||||||
rerun = fs::exists(idxfile.toFilesystemEncoding()) &&
|
rerun = idxfile.exists() && fs::is_empty(idxfile.toFilesystemEncoding());
|
||||||
fs::is_empty(idxfile.toFilesystemEncoding());
|
|
||||||
|
|
||||||
// run makeindex
|
// run makeindex
|
||||||
if (head.haschanged(idxfile)) {
|
if (head.haschanged(idxfile)) {
|
||||||
@ -480,7 +479,7 @@ LaTeX::scanAuxFiles(FileName const & file)
|
|||||||
FileName const file2(basename
|
FileName const file2(basename
|
||||||
+ '.' + convert<string>(i)
|
+ '.' + convert<string>(i)
|
||||||
+ ".aux");
|
+ ".aux");
|
||||||
if (!fs::exists(file2.toFilesystemEncoding()))
|
if (!file2.exists())
|
||||||
break;
|
break;
|
||||||
result.push_back(scanAuxFile(file2));
|
result.push_back(scanAuxFile(file2));
|
||||||
}
|
}
|
||||||
@ -770,30 +769,9 @@ int LaTeX::scanLogFile(TeXErrors & terr)
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper around fs::exists that can handle invalid file names.
|
|
||||||
* In theory we could test with fs::native whether a filename is valid
|
|
||||||
* before calling fs::exists, but in practice it is unusable: On windows it
|
|
||||||
* does not allow spaces, and on unix it does not allow absolute file names.
|
|
||||||
* This function has the disadvantage that it catches also other errors than
|
|
||||||
* invalid names, but for dependency checking we can live with that.
|
|
||||||
*/
|
|
||||||
bool exists(FileName const & possible_name) {
|
|
||||||
try {
|
|
||||||
return fs::exists(possible_name.toFilesystemEncoding());
|
|
||||||
}
|
|
||||||
catch (fs::filesystem_error const & fe) {
|
|
||||||
LYXERR(Debug::DEPEND) << "Got error `" << fe.what()
|
|
||||||
<< "' while checking whether file `" << possible_name
|
|
||||||
<< "' exists." << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool insertIfExists(FileName const & absname, DepTable & head)
|
bool insertIfExists(FileName const & absname, DepTable & head)
|
||||||
{
|
{
|
||||||
if (exists(absname) &&
|
if (absname.exists() &&
|
||||||
!fs::is_directory(absname.toFilesystemEncoding())) {
|
!fs::is_directory(absname.toFilesystemEncoding())) {
|
||||||
head.insert(absname, true);
|
head.insert(absname, true);
|
||||||
return true;
|
return true;
|
||||||
@ -851,7 +829,7 @@ bool handleFoundFile(string const & ff, DepTable & head)
|
|||||||
|
|
||||||
// check for spaces
|
// check for spaces
|
||||||
while (contains(foundfile, ' ')) {
|
while (contains(foundfile, ' ')) {
|
||||||
if (exists(absname))
|
if (absname.exists())
|
||||||
// everything o.k.
|
// everything o.k.
|
||||||
break;
|
break;
|
||||||
else {
|
else {
|
||||||
@ -859,7 +837,7 @@ bool handleFoundFile(string const & ff, DepTable & head)
|
|||||||
// marks; those have to be removed
|
// marks; those have to be removed
|
||||||
string unquoted = subst(foundfile, "\"", "");
|
string unquoted = subst(foundfile, "\"", "");
|
||||||
absname = makeAbsPath(unquoted);
|
absname = makeAbsPath(unquoted);
|
||||||
if (exists(absname))
|
if (absname.exists())
|
||||||
break;
|
break;
|
||||||
// strip off part after last space and try again
|
// strip off part after last space and try again
|
||||||
string strippedfile;
|
string strippedfile;
|
||||||
@ -873,38 +851,28 @@ bool handleFoundFile(string const & ff, DepTable & head)
|
|||||||
|
|
||||||
// (2) foundfile is in the tmpdir
|
// (2) foundfile is in the tmpdir
|
||||||
// insert it into head
|
// insert it into head
|
||||||
if (exists(absname) &&
|
if (absname.exists() &&
|
||||||
!fs::is_directory(absname.toFilesystemEncoding())) {
|
!fs::is_directory(absname.toFilesystemEncoding())) {
|
||||||
// FIXME: This regex contained glo, but glo is used by the old
|
// FIXME: This regex contained glo, but glo is used by the old
|
||||||
// version of nomencl.sty. Do we need to put it back?
|
// version of nomencl.sty. Do we need to put it back?
|
||||||
static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
|
static regex const unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
|
||||||
if (regex_match(onlyfile, unwanted)) {
|
if (regex_match(onlyfile, unwanted)) {
|
||||||
LYXERR(Debug::DEPEND)
|
LYXERR(Debug::DEPEND) << "We don't want " << onlyfile
|
||||||
<< "We don't want "
|
<< " in the dep file" << endl;
|
||||||
<< onlyfile
|
|
||||||
<< " in the dep file"
|
|
||||||
<< endl;
|
|
||||||
} else if (suffixIs(onlyfile, ".tex")) {
|
} else if (suffixIs(onlyfile, ".tex")) {
|
||||||
// This is a tex file generated by LyX
|
// This is a tex file generated by LyX
|
||||||
// and latex is not likely to change this
|
// and latex is not likely to change this
|
||||||
// during its runs.
|
// during its runs.
|
||||||
LYXERR(Debug::DEPEND)
|
LYXERR(Debug::DEPEND) << "Tmpdir TeX file: " << onlyfile << endl;
|
||||||
<< "Tmpdir TeX file: "
|
|
||||||
<< onlyfile
|
|
||||||
<< endl;
|
|
||||||
head.insert(absname, true);
|
head.insert(absname, true);
|
||||||
} else {
|
} else {
|
||||||
LYXERR(Debug::DEPEND)
|
LYXERR(Debug::DEPEND) << "In tmpdir file:" << onlyfile << endl;
|
||||||
<< "In tmpdir file:"
|
|
||||||
<< onlyfile
|
|
||||||
<< endl;
|
|
||||||
head.insert(absname);
|
head.insert(absname);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LYXERR(Debug::DEPEND)
|
LYXERR(Debug::DEPEND)
|
||||||
<< "Not a file or we are unable to find it."
|
<< "Not a file or we are unable to find it." << endl;
|
||||||
<< endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -932,28 +900,28 @@ void LaTeX::deplog(DepTable & head)
|
|||||||
string const logfile =
|
string const logfile =
|
||||||
onlyFilename(changeExtension(file.absFilename(), ".log"));
|
onlyFilename(changeExtension(file.absFilename(), ".log"));
|
||||||
|
|
||||||
static regex reg1("File: (.+).*");
|
static regex const reg1("File: (.+).*");
|
||||||
static regex reg2("No file (.+)(.).*");
|
static regex const reg2("No file (.+)(.).*");
|
||||||
static regex reg3("\\\\openout[0-9]+.*=.*`(.+)(..).*");
|
static regex const reg3("\\\\openout[0-9]+.*=.*`(.+)(..).*");
|
||||||
// If an index should be created, MikTex does not write a line like
|
// If an index should be created, MikTex does not write a line like
|
||||||
// \openout# = 'sample.idx'.
|
// \openout# = 'sample.idx'.
|
||||||
// but instead only a line like this into the log:
|
// but instead only a line like this into the log:
|
||||||
// Writing index file sample.idx
|
// Writing index file sample.idx
|
||||||
static regex reg4("Writing index file (.+).*");
|
static regex const reg4("Writing index file (.+).*");
|
||||||
// files also can be enclosed in <...>
|
// files also can be enclosed in <...>
|
||||||
static regex reg5("<([^>]+)(.).*");
|
static regex const reg5("<([^>]+)(.).*");
|
||||||
static regex regoldnomencl("Writing glossary file (.+).*");
|
static regex const regoldnomencl("Writing glossary file (.+).*");
|
||||||
static regex regnomencl("Writing nomenclature file (.+).*");
|
static regex const regnomencl("Writing nomenclature file (.+).*");
|
||||||
// If a toc should be created, MikTex does not write a line like
|
// If a toc should be created, MikTex does not write a line like
|
||||||
// \openout# = `sample.toc'.
|
// \openout# = `sample.toc'.
|
||||||
// but only a line like this into the log:
|
// but only a line like this into the log:
|
||||||
// \tf@toc=\write#
|
// \tf@toc=\write#
|
||||||
// This line is also written by tetex.
|
// This line is also written by tetex.
|
||||||
// This line is not present if no toc should be created.
|
// This line is not present if no toc should be created.
|
||||||
static regex miktexTocReg("\\\\tf@toc=\\\\write.*");
|
static regex const miktexTocReg("\\\\tf@toc=\\\\write.*");
|
||||||
static regex reg6(".*\\([^)]+.*");
|
static regex const reg6(".*\\([^)]+.*");
|
||||||
|
|
||||||
FileName const fn(makeAbsPath(logfile));
|
FileName const fn = makeAbsPath(logfile);
|
||||||
ifstream ifs(fn.toFilesystemEncoding().c_str());
|
ifstream ifs(fn.toFilesystemEncoding().c_str());
|
||||||
string lastline;
|
string lastline;
|
||||||
while (ifs) {
|
while (ifs) {
|
||||||
@ -980,8 +948,8 @@ void LaTeX::deplog(DepTable & head)
|
|||||||
// Here we exclude some cases where we are sure
|
// Here we exclude some cases where we are sure
|
||||||
// that there is no continued filename
|
// that there is no continued filename
|
||||||
if (!lastline.empty()) {
|
if (!lastline.empty()) {
|
||||||
static regex package_info("Package \\w+ Info: .*");
|
static regex const package_info("Package \\w+ Info: .*");
|
||||||
static regex package_warning("Package \\w+ Warning: .*");
|
static regex const package_warning("Package \\w+ Warning: .*");
|
||||||
if (prefixIs(token, "File:") || prefixIs(token, "(Font)")
|
if (prefixIs(token, "File:") || prefixIs(token, "(Font)")
|
||||||
|| prefixIs(token, "Package:")
|
|| prefixIs(token, "Package:")
|
||||||
|| prefixIs(token, "Language:")
|
|| prefixIs(token, "Language:")
|
||||||
|
@ -985,7 +985,7 @@ bool LyX::init()
|
|||||||
prependEnvPath("PATH", lyxrc.path_prefix);
|
prependEnvPath("PATH", lyxrc.path_prefix);
|
||||||
|
|
||||||
FileName const document_path(lyxrc.document_path);
|
FileName const document_path(lyxrc.document_path);
|
||||||
if (fs::exists(document_path.toFilesystemEncoding()) &&
|
if (document_path.exists() &&
|
||||||
fs::is_directory(document_path.toFilesystemEncoding()))
|
fs::is_directory(document_path.toFilesystemEncoding()))
|
||||||
package().document_dir() = document_path;
|
package().document_dir() = document_path;
|
||||||
|
|
||||||
|
@ -1152,7 +1152,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
FileName const filename(makeAbsPath(target_name,
|
FileName const filename(makeAbsPath(target_name,
|
||||||
lyx_view_->buffer()->filePath()));
|
lyx_view_->buffer()->filePath()));
|
||||||
FileName const dvifile(makeAbsPath(dviname, path));
|
FileName const dvifile(makeAbsPath(dviname, path));
|
||||||
if (fs::exists(filename.toFilesystemEncoding())) {
|
if (filename.exists()) {
|
||||||
docstring text = bformat(
|
docstring text = bformat(
|
||||||
_("The file %1$s already exists.\n\n"
|
_("The file %1$s already exists.\n\n"
|
||||||
"Do you want to overwrite that file?"),
|
"Do you want to overwrite that file?"),
|
||||||
@ -2155,7 +2155,7 @@ void LyXFunc::open(string const & fname)
|
|||||||
filename = fullname.absFilename();
|
filename = fullname.absFilename();
|
||||||
|
|
||||||
// if the file doesn't exist, let the user create one
|
// if the file doesn't exist, let the user create one
|
||||||
if (!fs::exists(fullname.toFilesystemEncoding())) {
|
if (!fullname.exists()) {
|
||||||
// the user specifically chose this name. Believe him.
|
// the user specifically chose this name. Believe him.
|
||||||
Buffer * const b = newFile(filename, string(), true);
|
Buffer * const b = newFile(filename, string(), true);
|
||||||
if (b)
|
if (b)
|
||||||
@ -2247,7 +2247,7 @@ void LyXFunc::doImport(string const & argument)
|
|||||||
|
|
||||||
// if the file exists already, and we didn't do
|
// if the file exists already, and we didn't do
|
||||||
// -i lyx thefile.lyx, warn
|
// -i lyx thefile.lyx, warn
|
||||||
if (fs::exists(lyxfile.toFilesystemEncoding()) && fullname != lyxfile) {
|
if (lyxfile.exists() && fullname != lyxfile) {
|
||||||
docstring const file = makeDisplayPath(lyxfile.absFilename(), 30);
|
docstring const file = makeDisplayPath(lyxfile.absFilename(), 30);
|
||||||
|
|
||||||
docstring text = bformat(_("The document %1$s already exists.\n\n"
|
docstring text = bformat(_("The document %1$s already exists.\n\n"
|
||||||
|
@ -78,7 +78,7 @@ void LastFilesSection::read(istream & is)
|
|||||||
|
|
||||||
// read lastfiles
|
// read lastfiles
|
||||||
FileName const file(tmp);
|
FileName const file(tmp);
|
||||||
if (fs::exists(file.toFilesystemEncoding()) &&
|
if (file.exists() &&
|
||||||
!fs::is_directory(file.toFilesystemEncoding()) &&
|
!fs::is_directory(file.toFilesystemEncoding()) &&
|
||||||
lastfiles.size() < num_lastfiles)
|
lastfiles.size() < num_lastfiles)
|
||||||
lastfiles.push_back(file);
|
lastfiles.push_back(file);
|
||||||
@ -133,7 +133,7 @@ void LastOpenedSection::read(istream & is)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
FileName const file(tmp);
|
FileName const file(tmp);
|
||||||
if (fs::exists(file.toFilesystemEncoding()) &&
|
if (file.exists() &&
|
||||||
!fs::is_directory(file.toFilesystemEncoding()))
|
!fs::is_directory(file.toFilesystemEncoding()))
|
||||||
lastopened.push_back(file);
|
lastopened.push_back(file);
|
||||||
else
|
else
|
||||||
@ -188,7 +188,7 @@ void LastFilePosSection::read(istream & is)
|
|||||||
if (!absolutePath(fname))
|
if (!absolutePath(fname))
|
||||||
continue;
|
continue;
|
||||||
FileName const file(fname);
|
FileName const file(fname);
|
||||||
if (fs::exists(file.toFilesystemEncoding()) &&
|
if (file.exists() &&
|
||||||
!fs::is_directory(file.toFilesystemEncoding()) &&
|
!fs::is_directory(file.toFilesystemEncoding()) &&
|
||||||
lastfilepos.size() < num_lastfilepos)
|
lastfilepos.size() < num_lastfilepos)
|
||||||
lastfilepos[file] = boost::tie(pit, pos);
|
lastfilepos[file] = boost::tie(pit, pos);
|
||||||
@ -269,7 +269,7 @@ void BookmarksSection::read(istream & is)
|
|||||||
continue;
|
continue;
|
||||||
FileName const file(fname);
|
FileName const file(fname);
|
||||||
// only load valid bookmarks
|
// only load valid bookmarks
|
||||||
if (fs::exists(file.toFilesystemEncoding()) &&
|
if (file.exists() &&
|
||||||
!fs::is_directory(file.toFilesystemEncoding()) &&
|
!fs::is_directory(file.toFilesystemEncoding()) &&
|
||||||
idx <= max_bookmarks)
|
idx <= max_bookmarks)
|
||||||
bookmarks[idx] = Bookmark(file, pit, pos, 0, 0);
|
bookmarks[idx] = Bookmark(file, pit, pos, 0, 0);
|
||||||
|
@ -30,12 +30,8 @@
|
|||||||
#include "support/filetools.h"
|
#include "support/filetools.h"
|
||||||
#include "support/os.h"
|
#include "support/os.h"
|
||||||
|
|
||||||
#include <boost/filesystem/operations.hpp>
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
using support::FileName;
|
using support::FileName;
|
||||||
@ -1014,7 +1010,7 @@ bool TextClass::load(string const & path) const
|
|||||||
FileName layout_file;
|
FileName layout_file;
|
||||||
if (!path.empty())
|
if (!path.empty())
|
||||||
layout_file = FileName(addName(path, name_ + ".layout"));
|
layout_file = FileName(addName(path, name_ + ".layout"));
|
||||||
if (layout_file.empty() || !fs::exists(layout_file.toFilesystemEncoding()))
|
if (layout_file.empty() || !layout_file.exists())
|
||||||
layout_file = libFileSearch("layouts", name_, "layout");
|
layout_file = libFileSearch("layouts", name_, "layout");
|
||||||
loaded_ = const_cast<TextClass*>(this)->read(layout_file) == 0;
|
loaded_ = const_cast<TextClass*>(this)->read(layout_file) == 0;
|
||||||
|
|
||||||
|
@ -20,12 +20,11 @@
|
|||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
|
|
||||||
using support::FileName;
|
using support::FileName;
|
||||||
using support::addName;
|
using support::addName;
|
||||||
@ -194,7 +193,7 @@ TextClassList::addTextClass(std::string const & textclass, std::string const & p
|
|||||||
// only check for textclass.layout file, .cls can be anywhere in $TEXINPUTS
|
// only check for textclass.layout file, .cls can be anywhere in $TEXINPUTS
|
||||||
// NOTE: latex class name is defined in textclass.layout, which can be different from textclass
|
// NOTE: latex class name is defined in textclass.layout, which can be different from textclass
|
||||||
FileName const layout_file(addName(path, textclass + ".layout"));
|
FileName const layout_file(addName(path, textclass + ".layout"));
|
||||||
if (fs::exists(layout_file.toFilesystemEncoding())) {
|
if (layout_file.exists()) {
|
||||||
LYXERR(Debug::TCLASS) << "Adding class " << textclass << " from directory " << path << endl;
|
LYXERR(Debug::TCLASS) << "Adding class " << textclass << " from directory " << path << endl;
|
||||||
// Read .layout file and get description, real latex classname etc
|
// Read .layout file and get description, real latex classname etc
|
||||||
//
|
//
|
||||||
|
@ -82,7 +82,7 @@ bool readFile(Buffer * const b, FileName const & s)
|
|||||||
BOOST_ASSERT(b);
|
BOOST_ASSERT(b);
|
||||||
|
|
||||||
// File information about normal file
|
// File information about normal file
|
||||||
if (!fs::exists(s.toFilesystemEncoding())) {
|
if (!s.exists()) {
|
||||||
docstring const file = makeDisplayPath(s.absFilename(), 50);
|
docstring const file = makeDisplayPath(s.absFilename(), 50);
|
||||||
docstring text = bformat(_("The specified document\n%1$s"
|
docstring text = bformat(_("The specified document\n%1$s"
|
||||||
"\ncould not be read."), file);
|
"\ncould not be read."), file);
|
||||||
@ -93,10 +93,7 @@ bool readFile(Buffer * const b, FileName const & s)
|
|||||||
// Check if emergency save file exists and is newer.
|
// Check if emergency save file exists and is newer.
|
||||||
FileName const e(s.absFilename() + ".emergency");
|
FileName const e(s.absFilename() + ".emergency");
|
||||||
|
|
||||||
if (fs::exists(e.toFilesystemEncoding()) &&
|
if (e.exists() && s.exists() && e.lastModified() > s.lastModified()) {
|
||||||
fs::exists(s.toFilesystemEncoding()) &&
|
|
||||||
fs::last_write_time(e.toFilesystemEncoding()) > fs::last_write_time(s.toFilesystemEncoding()))
|
|
||||||
{
|
|
||||||
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
||||||
docstring const text =
|
docstring const text =
|
||||||
bformat(_("An emergency save of the document "
|
bformat(_("An emergency save of the document "
|
||||||
@ -120,10 +117,7 @@ bool readFile(Buffer * const b, FileName const & s)
|
|||||||
// Now check if autosave file is newer.
|
// Now check if autosave file is newer.
|
||||||
FileName const a(onlyPath(s.absFilename()) + '#' + onlyFilename(s.absFilename()) + '#');
|
FileName const a(onlyPath(s.absFilename()) + '#' + onlyFilename(s.absFilename()) + '#');
|
||||||
|
|
||||||
if (fs::exists(a.toFilesystemEncoding()) &&
|
if (a.exists() && s.exists() && a.lastModified() > s.lastModified()) {
|
||||||
fs::exists(s.toFilesystemEncoding()) &&
|
|
||||||
fs::last_write_time(a.toFilesystemEncoding()) > fs::last_write_time(s.toFilesystemEncoding()))
|
|
||||||
{
|
|
||||||
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
docstring const file = makeDisplayPath(s.absFilename(), 20);
|
||||||
docstring const text =
|
docstring const text =
|
||||||
bformat(_("The backup of the document "
|
bformat(_("The backup of the document "
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
#include "support/convert.h"
|
#include "support/convert.h"
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
@ -88,7 +87,6 @@ using std::ostringstream;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
namespace Alert = frontend::Alert;
|
namespace Alert = frontend::Alert;
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -386,6 +384,7 @@ Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params
|
|||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
/// return true if the file is or got loaded.
|
/// return true if the file is or got loaded.
|
||||||
Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
|
Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
|
||||||
{
|
{
|
||||||
@ -402,7 +401,7 @@ Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
|
|||||||
Buffer * child = theBufferList().getBuffer(included_file.absFilename());
|
Buffer * child = theBufferList().getBuffer(included_file.absFilename());
|
||||||
if (!child) {
|
if (!child) {
|
||||||
// the readonly flag can/will be wrong, not anymore I think.
|
// the readonly flag can/will be wrong, not anymore I think.
|
||||||
if (!fs::exists(included_file.toFilesystemEncoding()))
|
if (!included_file.exists())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
child = theBufferList().newBuffer(included_file.absFilename());
|
child = theBufferList().newBuffer(included_file.absFilename());
|
||||||
|
@ -16,14 +16,11 @@
|
|||||||
#include "support/Timeout.h"
|
#include "support/Timeout.h"
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/filesystem/operations.hpp>
|
|
||||||
#include <boost/signals/trackable.hpp>
|
#include <boost/signals/trackable.hpp>
|
||||||
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace support {
|
namespace support {
|
||||||
|
|
||||||
@ -90,10 +87,10 @@ void FileMonitor::start() const
|
|||||||
if (monitoring())
|
if (monitoring())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!fs::exists(pimpl_->filename_.toFilesystemEncoding()))
|
if (!pimpl_->filename_.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename_.toFilesystemEncoding());
|
pimpl_->timestamp_ = pimpl_->filename_.lastModified();
|
||||||
pimpl_->checksum_ = sum(pimpl_->filename_);
|
pimpl_->checksum_ = sum(pimpl_->filename_);
|
||||||
|
|
||||||
if (pimpl_->timestamp_ && pimpl_->checksum_) {
|
if (pimpl_->timestamp_ && pimpl_->checksum_) {
|
||||||
@ -155,13 +152,13 @@ void FileMonitor::Impl::monitorFile()
|
|||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
if (!fs::exists(filename_.toFilesystemEncoding())) {
|
if (!filename_.exists()) {
|
||||||
changed = timestamp_ || checksum_;
|
changed = timestamp_ || checksum_;
|
||||||
timestamp_ = 0;
|
timestamp_ = 0;
|
||||||
checksum_ = 0;
|
checksum_ = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
time_t const new_timestamp = fs::last_write_time(filename_.toFilesystemEncoding());
|
time_t const new_timestamp = filename_.lastModified();
|
||||||
|
|
||||||
if (new_timestamp != timestamp_) {
|
if (new_timestamp != timestamp_) {
|
||||||
timestamp_ = new_timestamp;
|
timestamp_ = new_timestamp;
|
||||||
|
@ -356,14 +356,12 @@ FileName const get_locale_dir(FileName const & system_support_dir)
|
|||||||
FileName path(normalizePath(addPath(system_support_dir.absFilename(),
|
FileName path(normalizePath(addPath(system_support_dir.absFilename(),
|
||||||
relative_locale_dir())));
|
relative_locale_dir())));
|
||||||
|
|
||||||
if (fs::exists(path.toFilesystemEncoding()) &&
|
if (path.exists() && fs::is_directory(path.toFilesystemEncoding()))
|
||||||
fs::is_directory(path.toFilesystemEncoding()))
|
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
// 3. Fall back to the hard-coded LOCALEDIR.
|
// 3. Fall back to the hard-coded LOCALEDIR.
|
||||||
path = hardcoded_localedir();
|
path = hardcoded_localedir();
|
||||||
if (fs::exists(path.toFilesystemEncoding()) &&
|
if (path.exists() && fs::is_directory(path.toFilesystemEncoding()))
|
||||||
fs::is_directory(path.toFilesystemEncoding()))
|
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
return FileName();
|
return FileName();
|
||||||
@ -415,7 +413,7 @@ FileName const get_binary_path(string const & exe)
|
|||||||
// Two possibilities present themselves.
|
// Two possibilities present themselves.
|
||||||
// 1. The binary is relative to the CWD.
|
// 1. The binary is relative to the CWD.
|
||||||
FileName const abs_exe_path = makeAbsPath(exe_path);
|
FileName const abs_exe_path = makeAbsPath(exe_path);
|
||||||
if (fs::exists(abs_exe_path.toFilesystemEncoding()))
|
if (abs_exe_path.exists())
|
||||||
return abs_exe_path;
|
return abs_exe_path;
|
||||||
|
|
||||||
// 2. exe must be the name of the binary only and it
|
// 2. exe must be the name of the binary only and it
|
||||||
@ -432,7 +430,7 @@ FileName const get_binary_path(string const & exe)
|
|||||||
string const exe_dir = makeAbsPath(*it).absFilename();
|
string const exe_dir = makeAbsPath(*it).absFilename();
|
||||||
|
|
||||||
FileName const exe_path(addName(exe_dir, exe_name));
|
FileName const exe_path(addName(exe_dir, exe_name));
|
||||||
if (fs::exists(exe_path.toFilesystemEncoding()))
|
if (exe_path.exists())
|
||||||
return exe_path;
|
return exe_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -697,8 +695,8 @@ bool check_env_var_dir(FileName const & dir,
|
|||||||
bool check_env_var_dir(FileName const & dir,
|
bool check_env_var_dir(FileName const & dir,
|
||||||
string const & env_var)
|
string const & env_var)
|
||||||
{
|
{
|
||||||
string const encoded(dir.toFilesystemEncoding());
|
string const encoded = dir.toFilesystemEncoding();
|
||||||
bool const success = (fs::exists(encoded) && fs::is_directory(encoded));
|
bool const success = (dir.exists() && fs::is_directory(encoded));
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// Put this string on a single line so that the gettext
|
// Put this string on a single line so that the gettext
|
||||||
|
@ -360,7 +360,7 @@ string find_file(string const & name, string const & path,
|
|||||||
// expects utf8)
|
// expects utf8)
|
||||||
for (char const * const * what = extensions; *what; ++what) {
|
for (char const * const * what = extensions; *what; ++what) {
|
||||||
string const trial = addExtension(name, *what);
|
string const trial = addExtension(name, *what);
|
||||||
if (fs::exists(makeAbsPath(trial, path).toFilesystemEncoding()))
|
if (makeAbsPath(trial, path).exists())
|
||||||
return trial;
|
return trial;
|
||||||
}
|
}
|
||||||
return string();
|
return string();
|
||||||
@ -1539,7 +1539,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
// therefore path is only used for testing
|
// therefore path is only used for testing
|
||||||
// FIXME UNICODE encoding of name and path may be
|
// FIXME UNICODE encoding of name and path may be
|
||||||
// wrong (makeAbsPath expects utf8)
|
// wrong (makeAbsPath expects utf8)
|
||||||
if (!fs::exists(makeAbsPath(name, path).toFilesystemEncoding())) {
|
if (!makeAbsPath(name, path).exists()) {
|
||||||
// The file extension is probably missing.
|
// The file extension is probably missing.
|
||||||
// Now try to find it out.
|
// Now try to find it out.
|
||||||
string const dvips_name =
|
string const dvips_name =
|
||||||
@ -1571,7 +1571,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
|
|
||||||
// FIXME UNICODE encoding of name and path may be
|
// FIXME UNICODE encoding of name and path may be
|
||||||
// wrong (makeAbsPath expects utf8)
|
// wrong (makeAbsPath expects utf8)
|
||||||
if (fs::exists(makeAbsPath(name, path).toFilesystemEncoding()))
|
if (makeAbsPath(name, path).exists())
|
||||||
fix_relative_filename(name);
|
fix_relative_filename(name);
|
||||||
else
|
else
|
||||||
cerr << "Warning: Could not find graphics file '"
|
cerr << "Warning: Could not find graphics file '"
|
||||||
@ -2203,7 +2203,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
// FIXME UNICODE encoding of filename and path may be
|
// FIXME UNICODE encoding of filename and path may be
|
||||||
// wrong (makeAbsPath expects utf8)
|
// wrong (makeAbsPath expects utf8)
|
||||||
if ((t.cs() == "include" || t.cs() == "input") &&
|
if ((t.cs() == "include" || t.cs() == "input") &&
|
||||||
!fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) {
|
!makeAbsPath(filename, path).exists()) {
|
||||||
// The file extension is probably missing.
|
// The file extension is probably missing.
|
||||||
// Now try to find it out.
|
// Now try to find it out.
|
||||||
string const tex_name =
|
string const tex_name =
|
||||||
@ -2214,7 +2214,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
}
|
}
|
||||||
// FIXME UNICODE encoding of filename and path may be
|
// FIXME UNICODE encoding of filename and path may be
|
||||||
// wrong (makeAbsPath expects utf8)
|
// wrong (makeAbsPath expects utf8)
|
||||||
if (fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) {
|
if (makeAbsPath(filename, path).exists()) {
|
||||||
string const abstexname =
|
string const abstexname =
|
||||||
makeAbsPath(filename, path).absFilename();
|
makeAbsPath(filename, path).absFilename();
|
||||||
string const abslyxname =
|
string const abslyxname =
|
||||||
|
Loading…
Reference in New Issue
Block a user