mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-09 10:47:57 +00:00
use FileName::isDirectory()
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21047 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
055c95ca51
commit
988f372843
@ -771,8 +771,7 @@ namespace {
|
||||
|
||||
bool insertIfExists(FileName const & absname, DepTable & head)
|
||||
{
|
||||
if (absname.exists() &&
|
||||
!fs::is_directory(absname.toFilesystemEncoding())) {
|
||||
if (absname.exists() && !absname.isDirectory()) {
|
||||
head.insert(absname, true);
|
||||
return true;
|
||||
}
|
||||
@ -851,8 +850,7 @@ bool handleFoundFile(string const & ff, DepTable & head)
|
||||
|
||||
// (2) foundfile is in the tmpdir
|
||||
// insert it into head
|
||||
if (absname.exists() &&
|
||||
!fs::is_directory(absname.toFilesystemEncoding())) {
|
||||
if (absname.exists() && !absname.isDirectory()) {
|
||||
// FIXME: This regex contained glo, but glo is used by the old
|
||||
// version of nomencl.sty. Do we need to put it back?
|
||||
static regex const unwanted("^.*\\.(aux|log|dvi|bbl|ind)$");
|
||||
|
39
src/LyX.cpp
39
src/LyX.cpp
@ -62,7 +62,6 @@
|
||||
#include "support/Systemcall.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
@ -84,8 +83,6 @@ using std::signal;
|
||||
using std::system;
|
||||
#endif
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::addName;
|
||||
@ -985,8 +982,7 @@ bool LyX::init()
|
||||
prependEnvPath("PATH", lyxrc.path_prefix);
|
||||
|
||||
FileName const document_path(lyxrc.document_path);
|
||||
if (document_path.exists() &&
|
||||
fs::is_directory(document_path.toFilesystemEncoding()))
|
||||
if (document_path.exists() && document_path.isDirectory())
|
||||
package().document_dir() = document_path;
|
||||
|
||||
package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path));
|
||||
@ -1114,38 +1110,32 @@ void LyX::deadKeyBindings(KeyMap * kbmap)
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// return true if file does not exist or is older than configure.py.
|
||||
bool needsUpdate(string const & file)
|
||||
static bool needsUpdate(string const & file)
|
||||
{
|
||||
// We cannot initialize configure_script directly because the package
|
||||
// is not initialized yet when static objects are constructed.
|
||||
static string configure_script;
|
||||
static FileName configure_script;
|
||||
static bool firstrun = true;
|
||||
if (firstrun) {
|
||||
configure_script = FileName(addName(
|
||||
package().system_support().absFilename(),
|
||||
"configure.py")).toFilesystemEncoding();
|
||||
configure_script =
|
||||
FileName(addName(package().system_support().absFilename(),
|
||||
"configure.py"));
|
||||
firstrun = false;
|
||||
}
|
||||
|
||||
string const absfile = FileName(addName(
|
||||
package().user_support().absFilename(), file)).toFilesystemEncoding();
|
||||
return (! fs::exists(absfile))
|
||||
|| (fs::last_write_time(configure_script)
|
||||
> fs::last_write_time(absfile));
|
||||
}
|
||||
|
||||
FileName absfile =
|
||||
FileName(addName(package().user_support().absFilename(), file));
|
||||
return !absfile.exists()
|
||||
|| configure_script.lastModified() > absfile.lastModified();
|
||||
}
|
||||
|
||||
|
||||
bool LyX::queryUserLyXDir(bool explicit_userdir)
|
||||
{
|
||||
// Does user directory exist?
|
||||
string const user_support =
|
||||
package().user_support().toFilesystemEncoding();
|
||||
if (fs::exists(user_support) && fs::is_directory(user_support)) {
|
||||
FileName const sup = package().user_support();
|
||||
if (sup.exists() && sup.isDirectory()) {
|
||||
first_start = false;
|
||||
|
||||
return needsUpdate("lyxrc.defaults")
|
||||
@ -1173,10 +1163,9 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
|
||||
}
|
||||
|
||||
lyxerr << to_utf8(bformat(_("LyX: Creating directory %1$s"),
|
||||
from_utf8(package().user_support().absFilename())))
|
||||
<< endl;
|
||||
from_utf8(sup.absFilename()))) << endl;
|
||||
|
||||
if (!createDirectory(package().user_support(), 0755)) {
|
||||
if (!createDirectory(sup, 0755)) {
|
||||
// Failed, so let's exit.
|
||||
lyxerr << to_utf8(_("Failed to create directory. Exiting."))
|
||||
<< endl;
|
||||
|
@ -2077,7 +2077,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
|
||||
filename = addName(lyxrc.document_path,
|
||||
"newfile" + convert<string>(++newfile_number) + ".lyx");
|
||||
while (theBufferList().exists(filename) ||
|
||||
fs::is_readable(FileName(filename).toFilesystemEncoding())) {
|
||||
FileName(filename).isReadable()) {
|
||||
++newfile_number;
|
||||
filename = addName(lyxrc.document_path,
|
||||
"newfile" + convert<string>(newfile_number) +
|
||||
@ -2403,9 +2403,8 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
|
||||
case LyXRC::RC_DISPLAY_GRAPHICS:
|
||||
case LyXRC::RC_DOCUMENTPATH:
|
||||
if (lyxrc_orig.document_path != lyxrc_new.document_path) {
|
||||
string const encoded = FileName(
|
||||
lyxrc_new.document_path).toFilesystemEncoding();
|
||||
if (fs::exists(encoded) && fs::is_directory(encoded))
|
||||
FileName path(lyxrc_new.document_path);
|
||||
if (path.exists() && path.isDirectory())
|
||||
support::package().document_dir() = FileName(lyxrc.document_path);
|
||||
}
|
||||
case LyXRC::RC_ESC_CHARS:
|
||||
|
@ -16,8 +16,6 @@
|
||||
#include "support/Package.h"
|
||||
#include "support/filetools.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
@ -28,8 +26,6 @@ using lyx::support::addName;
|
||||
using lyx::support::FileName;
|
||||
using lyx::support::package;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
using std::vector;
|
||||
using std::getline;
|
||||
using std::string;
|
||||
@ -78,9 +74,8 @@ void LastFilesSection::read(istream & is)
|
||||
|
||||
// read lastfiles
|
||||
FileName const file(tmp);
|
||||
if (file.exists() &&
|
||||
!fs::is_directory(file.toFilesystemEncoding()) &&
|
||||
lastfiles.size() < num_lastfiles)
|
||||
if (file.exists() && !file.isDirectory()
|
||||
&& lastfiles.size() < num_lastfiles)
|
||||
lastfiles.push_back(file);
|
||||
else
|
||||
LYXERR(Debug::INIT) << "LyX: Warning: Ignore last file: " << tmp << endl;
|
||||
@ -133,8 +128,7 @@ void LastOpenedSection::read(istream & is)
|
||||
continue;
|
||||
|
||||
FileName const file(tmp);
|
||||
if (file.exists() &&
|
||||
!fs::is_directory(file.toFilesystemEncoding()))
|
||||
if (file.exists() && !file.isDirectory())
|
||||
lastopened.push_back(file);
|
||||
else
|
||||
LYXERR(Debug::INIT) << "LyX: Warning: Ignore last opened file: " << tmp << endl;
|
||||
@ -188,9 +182,8 @@ void LastFilePosSection::read(istream & is)
|
||||
if (!absolutePath(fname))
|
||||
continue;
|
||||
FileName const file(fname);
|
||||
if (file.exists() &&
|
||||
!fs::is_directory(file.toFilesystemEncoding()) &&
|
||||
lastfilepos.size() < num_lastfilepos)
|
||||
if (file.exists() && !file.isDirectory()
|
||||
&& lastfilepos.size() < num_lastfilepos)
|
||||
lastfilepos[file] = boost::tie(pit, pos);
|
||||
else
|
||||
LYXERR(Debug::INIT) << "LyX: Warning: Ignore pos of last file: " << fname << endl;
|
||||
@ -269,9 +262,7 @@ void BookmarksSection::read(istream & is)
|
||||
continue;
|
||||
FileName const file(fname);
|
||||
// only load valid bookmarks
|
||||
if (file.exists() &&
|
||||
!fs::is_directory(file.toFilesystemEncoding()) &&
|
||||
idx <= max_bookmarks)
|
||||
if (file.exists() && !file.isDirectory() && idx <= max_bookmarks)
|
||||
bookmarks[idx] = Bookmark(file, pit, pos, 0, 0);
|
||||
else
|
||||
LYXERR(Debug::INIT) << "LyX: Warning: Ignore bookmark of file: " << fname << endl;
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "support/types.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QCloseEvent>
|
||||
@ -68,8 +67,6 @@ using std::make_pair;
|
||||
using std::pair;
|
||||
using std::vector;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
@ -765,8 +762,8 @@ docstring const GuiGraphics::browse(docstring const & in_name) const
|
||||
|
||||
// Does user clipart directory exist?
|
||||
string clipdir = addName(package().user_support().absFilename(), "clipart");
|
||||
string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding();
|
||||
if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir)))
|
||||
FileName clip(clipdir);
|
||||
if (!clip.exists() && clip.isDirectory())
|
||||
// No - bail out to system clipart directory
|
||||
clipdir = addName(package().system_support().absFilename(), "clipart");
|
||||
pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
|
||||
|
@ -35,16 +35,12 @@
|
||||
#include "support/os.h"
|
||||
#include "support/Package.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
using boost::filesystem::is_directory;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -260,7 +256,7 @@ void updateExternal(InsetExternalParams const & params,
|
||||
FileName const temp_file(
|
||||
support::makeAbsPath(params.filename.mangledFilename(),
|
||||
m_buffer->temppath()));
|
||||
if (!params.filename.empty() && !is_directory(params.filename.toFilesystemEncoding())) {
|
||||
if (!params.filename.empty() && !params.filename.isDirectory()) {
|
||||
unsigned long const from_checksum = support::sum(params.filename);
|
||||
unsigned long const temp_checksum = support::sum(temp_file);
|
||||
|
||||
|
@ -87,7 +87,7 @@ bool FileName::exists() const
|
||||
}
|
||||
|
||||
|
||||
bool FileName::isDir() const
|
||||
bool FileName::isDirectory() const
|
||||
{
|
||||
return QFileInfo(toqstr(name_)).isDir();
|
||||
}
|
||||
@ -100,6 +100,13 @@ bool FileName::isReadOnly() const
|
||||
}
|
||||
|
||||
|
||||
bool FileName::isReadable() const
|
||||
{
|
||||
QFileInfo const fi(toqstr(name_));
|
||||
return fi.isReadable();
|
||||
}
|
||||
|
||||
|
||||
std::time_t FileName::lastModified() const
|
||||
{
|
||||
return boost::filesystem::last_write_time(toFilesystemEncoding());
|
||||
|
@ -60,7 +60,9 @@ public:
|
||||
/// return true when file is readable but not writabel
|
||||
bool isReadOnly() const;
|
||||
/// return true when it names a directory
|
||||
bool isDir() const;
|
||||
bool isDirectory() const;
|
||||
/// return true when file is readable
|
||||
bool isReadable() const;
|
||||
|
||||
/**
|
||||
* Get a FileName from \p name in the encoding used by the file system.
|
||||
|
@ -695,8 +695,7 @@ bool check_env_var_dir(FileName const & dir,
|
||||
bool check_env_var_dir(FileName const & dir,
|
||||
string const & env_var)
|
||||
{
|
||||
string const encoded = dir.toFilesystemEncoding();
|
||||
bool const success = (dir.exists() && fs::is_directory(encoded));
|
||||
bool const success = dir.exists() && dir.isDirectory();
|
||||
|
||||
if (!success) {
|
||||
// Put this string on a single line so that the gettext
|
||||
|
@ -224,8 +224,7 @@ vector<FileName> const dirList(FileName const & dir, string const & ext)
|
||||
// EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
|
||||
vector<FileName> dirlist;
|
||||
|
||||
string const encoded_dir = dir.toFilesystemEncoding();
|
||||
if (!(fs::exists(encoded_dir) && fs::is_directory(encoded_dir))) {
|
||||
if (!(dir.exists() && dir.isDirectory())) {
|
||||
LYXERR(Debug::FILES)
|
||||
<< "Directory \"" << dir
|
||||
<< "\" does not exist to DirList." << endl;
|
||||
@ -237,6 +236,7 @@ vector<FileName> const dirList(FileName const & dir, string const & ext)
|
||||
extension += '.';
|
||||
extension += ext;
|
||||
|
||||
string const encoded_dir = dir.toFilesystemEncoding();
|
||||
fs::directory_iterator dit(encoded_dir);
|
||||
fs::directory_iterator end;
|
||||
for (; dit != end; ++dit) {
|
||||
@ -1224,23 +1224,20 @@ string const readBB_from_PSFile(FileName const & file)
|
||||
}
|
||||
|
||||
|
||||
int compare_timestamps(FileName const & filename1, FileName const & filename2)
|
||||
int compare_timestamps(FileName const & file1, FileName const & file2)
|
||||
{
|
||||
// If the original is newer than the copy, then copy the original
|
||||
// to the new directory.
|
||||
|
||||
string const file1 = filename1.toFilesystemEncoding();
|
||||
string const file2 = filename2.toFilesystemEncoding();
|
||||
int cmp = 0;
|
||||
if (fs::exists(file1) && fs::exists(file2)) {
|
||||
double const tmp = difftime(fs::last_write_time(file1),
|
||||
fs::last_write_time(file2));
|
||||
if (file1.exists() && file2.exists()) {
|
||||
double const tmp = difftime(file1.lastModified(), file2.lastModified());
|
||||
if (tmp != 0)
|
||||
cmp = tmp > 0 ? 1 : -1;
|
||||
|
||||
} else if (fs::exists(file1)) {
|
||||
} else if (file1.exists()) {
|
||||
cmp = 1;
|
||||
} else if (fs::exists(file2)) {
|
||||
} else if (file2.exists()) {
|
||||
cmp = -1;
|
||||
}
|
||||
|
||||
|
@ -11,21 +11,16 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "support/lyxlib.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
// OK, this is ugly, but it is the only workaround I found to compile
|
||||
// with gcc (any version) on a system which uses a non-GNU toolchain.
|
||||
// The problem is that gcc uses a weak symbol for a particular
|
||||
@ -124,10 +119,10 @@ unsigned long sum(FileName const & file)
|
||||
LYXERR(Debug::FILES) << "lyx::sum() using istreambuf_iterator (fast)"
|
||||
<< endl;
|
||||
|
||||
string filename = file.toFilesystemEncoding();
|
||||
// a directory may be passed here so we need to test it. (bug 3622)
|
||||
if (fs::is_directory(filename))
|
||||
if (file.isDirectory())
|
||||
return 0;
|
||||
string filename = file.toFilesystemEncoding();
|
||||
ifstream ifs(filename.c_str());
|
||||
if (!ifs)
|
||||
return 0;
|
||||
@ -148,10 +143,11 @@ unsigned long sum(FileName const & file)
|
||||
<< "lyx::sum() using istream_iterator (slow as a snail)"
|
||||
<< endl;
|
||||
|
||||
string filename = file.toFilesystemEncoding();
|
||||
// a directory may be passed here so we need to test it. (bug 3622)
|
||||
if (fs::is_directory(filename))
|
||||
if (file.isDirectory())
|
||||
return 0;
|
||||
|
||||
string filename = file.toFilesystemEncoding();
|
||||
ifstream ifs(filename.c_str());
|
||||
if (!ifs)
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user