mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
ditch FileInfo -> use boost.filesystem
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9547 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d9d7cbe23b
commit
b6e6f87f71
@ -1,7 +1,44 @@
|
||||
2005-01-31 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* vc-backend.C (find_file): rewrite to use boost.filesystem
|
||||
(scanMaster): ditto
|
||||
|
||||
* main.C (main): sett default name check for boost.filesystem to
|
||||
no check
|
||||
|
||||
* lyxfunc.C (menuNew): rewrite to use boost.filesystem
|
||||
(open): ditto
|
||||
(doImport): ditto
|
||||
(actOnUpdatedPrefs): ditto
|
||||
|
||||
* lyx_main.C (init): rewrite to use boost.filesystem
|
||||
(queryUserLyXDir): ditto
|
||||
|
||||
* lyx_cb.C (WriteAs): rewrite to use boost.filesystem
|
||||
(getContentsOfAsciiFile): ditto
|
||||
|
||||
* lastfiles.C (readFile): rewrite to use boost.filesystem
|
||||
|
||||
* exporter.C (checkOverwrite): rewrite to use boost.filesystem
|
||||
|
||||
* buffer_funcs.C (readFile): rewrite to use boost.filesystem
|
||||
(loadLyXFile): ditto
|
||||
|
||||
* buffer.C (Buffer): adjust for destroydir
|
||||
(getLogName): rewrite to use boost.filesystem
|
||||
(setFileName): ditto
|
||||
(save): use fs::copy_file (from fs_extras)
|
||||
|
||||
* Makefile.am (BOOST_LIBS): add BOOST_FILESYSTEM
|
||||
|
||||
* LaTeX.C (run): rewrite to use boost.filesystem
|
||||
(scanAuxFiles): ditto
|
||||
(handleFoundFile): ditto
|
||||
|
||||
2005-01-28 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* LaTeXFeatures.C (getAvailable): always clear packages_ list.
|
||||
|
||||
|
||||
* lyx_cb.C (Reconfigure): call LaTeXFeatures::getAvailable()
|
||||
|
||||
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
19
src/LaTeX.C
19
src/LaTeX.C
@ -21,13 +21,13 @@
|
||||
#include "debug.h"
|
||||
#include "DepTable.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/convert.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/systemcall.h"
|
||||
#include "support/os.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <fstream>
|
||||
@ -36,7 +36,6 @@ using lyx::support::AbsolutePath;
|
||||
using lyx::support::bformat;
|
||||
using lyx::support::ChangeExtension;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::findtexfile;
|
||||
using lyx::support::getcwd;
|
||||
using lyx::support::OnlyFilename;
|
||||
@ -51,6 +50,7 @@ using lyx::support::unlink;
|
||||
using lyx::support::trim;
|
||||
|
||||
namespace os = lyx::support::os;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
using boost::regex;
|
||||
using boost::smatch;
|
||||
@ -197,8 +197,7 @@ int LaTeX::run(TeXErrors & terr)
|
||||
// remake the dependency file.
|
||||
//
|
||||
|
||||
FileInfo fi(depfile);
|
||||
bool had_depfile = fi.exist();
|
||||
bool had_depfile = fs::exists(depfile);
|
||||
bool run_bibtex = false;
|
||||
string aux_file = OnlyFilename(ChangeExtension(file, "aux"));
|
||||
|
||||
@ -214,7 +213,7 @@ int LaTeX::run(TeXErrors & terr)
|
||||
// Can't just check if anything has changed because it might have aborted
|
||||
// on error last time... in which cas we need to re-run latex
|
||||
// and collect the error messages (even if they are the same).
|
||||
if (!FileInfo(output_file).exist()) {
|
||||
if (!fs::exists(output_file)) {
|
||||
lyxerr[Debug::DEPEND]
|
||||
<< "re-running LaTeX because output file doesn't exist." << endl;
|
||||
} else if (!head.sumchange()) {
|
||||
@ -412,10 +411,10 @@ LaTeX::scanAuxFiles(string const & file)
|
||||
result.push_back(scanAuxFile(file));
|
||||
|
||||
for (int i = 1; i < 1000; ++i) {
|
||||
string file2 = ChangeExtension(file, "") + '.' + convert<string>(i)
|
||||
string const file2 = ChangeExtension(file, "")
|
||||
+ '.' + convert<string>(i)
|
||||
+ ".aux";
|
||||
FileInfo fi(file2);
|
||||
if (!fi.exist())
|
||||
if (!fs::exists(file2))
|
||||
break;
|
||||
result.push_back(scanAuxFile(file2));
|
||||
}
|
||||
@ -688,7 +687,7 @@ void handleFoundFile(string const & ff, DepTable & head)
|
||||
// On initial insert we want to do the update at once
|
||||
// since this file can not be a file generated by
|
||||
// the latex run.
|
||||
if (FileInfo(foundfile).exist())
|
||||
if (fs::exists(foundfile))
|
||||
head.insert(foundfile, true);
|
||||
|
||||
return;
|
||||
@ -698,7 +697,7 @@ void handleFoundFile(string const & ff, DepTable & head)
|
||||
|
||||
// (2) foundfile is in the tmpdir
|
||||
// insert it into head
|
||||
if (FileInfo(onlyfile).exist()) {
|
||||
if (fs::exists(onlyfile)) {
|
||||
static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
|
||||
if (regex_match(onlyfile, unwanted)) {
|
||||
lyxerr[Debug::DEPEND]
|
||||
|
@ -20,7 +20,7 @@ LYX_POST_LIBS = frontends/controllers/libcontrollers.la \
|
||||
graphics/libgraphics.la \
|
||||
support/libsupport.la
|
||||
|
||||
BOOST_LIBS = $(BOOST_REGEX) $(BOOST_SIGNALS)
|
||||
BOOST_LIBS = $(BOOST_REGEX) $(BOOST_SIGNALS) $(BOOST_FILESYSTEM)
|
||||
|
||||
OTHERLIBS = $(BOOST_LIBS) $(INTLLIBS) $(AIKSAURUS_LIBS) @LIBS@
|
||||
|
||||
|
83
src/buffer.C
83
src/buffer.C
@ -63,8 +63,8 @@
|
||||
|
||||
#include "graphics/Previews.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/fs_extras.h"
|
||||
#ifdef USE_COMPRESSION
|
||||
# include "support/gzstream.h"
|
||||
#endif
|
||||
@ -75,6 +75,7 @@
|
||||
#include "support/convert.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <utime.h>
|
||||
|
||||
@ -93,11 +94,8 @@ using lyx::support::ChangeExtension;
|
||||
using lyx::support::cmd_ret;
|
||||
using lyx::support::createBufferTmpDir;
|
||||
using lyx::support::destroyDir;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::getFormatFromContents;
|
||||
using lyx::support::IsDirWriteable;
|
||||
using lyx::support::IsFileWriteable;
|
||||
using lyx::support::LibFileSearch;
|
||||
using lyx::support::ltrim;
|
||||
using lyx::support::MakeAbsPath;
|
||||
@ -116,6 +114,7 @@ using lyx::support::tempName;
|
||||
using lyx::support::trim;
|
||||
|
||||
namespace os = lyx::support::os;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
using std::endl;
|
||||
using std::for_each;
|
||||
@ -222,7 +221,7 @@ Buffer::~Buffer()
|
||||
|
||||
closing();
|
||||
|
||||
if (!temppath().empty() && destroyDir(temppath()) != 0) {
|
||||
if (!temppath().empty() && !destroyDir(temppath())) {
|
||||
Alert::warning(_("Could not remove temporary directory"),
|
||||
bformat(_("Could not remove the temporary directory %1$s"), temppath()));
|
||||
}
|
||||
@ -348,11 +347,8 @@ pair<Buffer::LogType, string> const Buffer::getLogName() const
|
||||
|
||||
// If no Latex log or Build log is newer, show Build log
|
||||
|
||||
FileInfo const f_fi(fname);
|
||||
FileInfo const b_fi(bname);
|
||||
|
||||
if (b_fi.exist() &&
|
||||
(!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
|
||||
if (fs::exists(bname) &&
|
||||
(!fs::exists(fname) || fs::last_write_time(fname) < fs::last_write_time(bname))) {
|
||||
lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
|
||||
return make_pair(Buffer::buildlog, bname);
|
||||
}
|
||||
@ -374,7 +370,7 @@ void Buffer::setFileName(string const & newfile)
|
||||
{
|
||||
pimpl_->filename = MakeAbsPath(newfile);
|
||||
pimpl_->filepath = OnlyPath(pimpl_->filename);
|
||||
setReadonly(IsFileWriteable(pimpl_->filename) == 0);
|
||||
setReadonly(fs::is_readonly(pimpl_->filename));
|
||||
updateTitles();
|
||||
}
|
||||
|
||||
@ -687,51 +683,18 @@ bool Buffer::save() const
|
||||
s = AddName(lyxrc.backupdir_path,
|
||||
subst(os::internal_path(s),'/','!'));
|
||||
|
||||
// Rename is the wrong way of making a backup,
|
||||
// this is the correct way.
|
||||
/* truss cp fil fil2:
|
||||
lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
|
||||
stat("LyXVC.lyx", 0xEFFFF688) = 0
|
||||
open("LyXVC.lyx", O_RDONLY) = 3
|
||||
open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
|
||||
fstat(4, 0xEFFFF508) = 0
|
||||
fstat(3, 0xEFFFF508) = 0
|
||||
read(3, " # T h i s f i l e w".., 8192) = 5579
|
||||
write(4, " # T h i s f i l e w".., 5579) = 5579
|
||||
read(3, 0xEFFFD4A0, 8192) = 0
|
||||
close(4) = 0
|
||||
close(3) = 0
|
||||
chmod("LyXVC3.lyx", 0100644) = 0
|
||||
lseek(0, 0, SEEK_CUR) = 46440
|
||||
_exit(0)
|
||||
*/
|
||||
|
||||
// Should probably have some more error checking here.
|
||||
// Doing it this way, also makes the inodes stay the same.
|
||||
// This is still not a very good solution, in particular we
|
||||
// might loose the owner of the backup.
|
||||
FileInfo finfo(fileName());
|
||||
if (finfo.exist()) {
|
||||
mode_t fmode = finfo.getMode();
|
||||
struct utimbuf times = {
|
||||
finfo.getAccessTime(),
|
||||
finfo.getModificationTime() };
|
||||
|
||||
ifstream ifs(fileName().c_str());
|
||||
ofstream ofs(s.c_str(), ios::out|ios::trunc);
|
||||
if (ifs && ofs) {
|
||||
ofs << ifs.rdbuf();
|
||||
ifs.close();
|
||||
ofs.close();
|
||||
::chmod(s.c_str(), fmode);
|
||||
|
||||
if (::utime(s.c_str(), ×)) {
|
||||
lyxerr << "utime error." << endl;
|
||||
}
|
||||
} else {
|
||||
lyxerr << "LyX was not able to make "
|
||||
"backup copy. Beware." << endl;
|
||||
}
|
||||
// It might very well be that this variant is just
|
||||
// good enough. (Lgb)
|
||||
// But to use this we need fs::copy_file to actually do a copy,
|
||||
// even when the target file exists. (Lgb)
|
||||
if (fs::exists(fileName())) {
|
||||
//try {
|
||||
fs::copy_file(fileName(), s, false);
|
||||
//}
|
||||
//catch (fs::filesystem_error const & fe) {
|
||||
//lyxerr << "LyX was not able to make backup copy. Beware.\n"
|
||||
// << fe.what() << endl;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@ -753,15 +716,11 @@ bool Buffer::writeFile(string const & fname) const
|
||||
if (pimpl_->read_only && fname == fileName())
|
||||
return false;
|
||||
|
||||
FileInfo finfo(fname);
|
||||
if (finfo.exist() && !finfo.writable())
|
||||
return false;
|
||||
|
||||
bool retval = false;
|
||||
|
||||
if (params().compressed) {
|
||||
#ifdef USE_COMPRESSION
|
||||
gz::ogzstream ofs(fname.c_str());
|
||||
gz::ogzstream ofs(fname.c_str(), ios::out|ios::trunc);
|
||||
if (!ofs)
|
||||
return false;
|
||||
|
||||
@ -770,7 +729,7 @@ bool Buffer::writeFile(string const & fname) const
|
||||
return false;
|
||||
#endif
|
||||
} else {
|
||||
ofstream ofs(fname.c_str());
|
||||
ofstream ofs(fname.c_str(), ios::out|ios::trunc);
|
||||
if (!ofs)
|
||||
return false;
|
||||
|
||||
|
@ -28,15 +28,14 @@
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/lyxlib.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
using lyx::support::bformat;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::IsFileWriteable;
|
||||
using lyx::support::LibFileSearch;
|
||||
using lyx::support::MakeDisplayPath;
|
||||
using lyx::support::OnlyFilename;
|
||||
@ -45,6 +44,7 @@ using lyx::support::unlink;
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
extern BufferList bufferlist;
|
||||
|
||||
@ -55,8 +55,7 @@ bool readFile(Buffer * const b, string const & s)
|
||||
BOOST_ASSERT(b);
|
||||
|
||||
// File information about normal file
|
||||
FileInfo fileN(s);
|
||||
if (!fileN.exist()) {
|
||||
if (!fs::exists(s)) {
|
||||
string const file = MakeDisplayPath(s, 50);
|
||||
string text = bformat(_("The specified document\n%1$s"
|
||||
"\ncould not be read."), file);
|
||||
@ -66,10 +65,9 @@ bool readFile(Buffer * const b, string const & s)
|
||||
|
||||
// Check if emergency save file exists and is newer.
|
||||
string const e = OnlyPath(s) + OnlyFilename(s) + ".emergency";
|
||||
FileInfo fileE(e);
|
||||
|
||||
if (fileE.exist() && fileN.exist()
|
||||
&& fileE.getModificationTime() > fileN.getModificationTime())
|
||||
if (fs::exists(e) && fs::exists(s)
|
||||
&& fs::last_write_time(e) > fs::last_write_time(s))
|
||||
{
|
||||
string const file = MakeDisplayPath(s, 20);
|
||||
string const text =
|
||||
@ -93,10 +91,9 @@ bool readFile(Buffer * const b, string const & s)
|
||||
|
||||
// Now check if autosave file is newer.
|
||||
string const a = OnlyPath(s) + '#' + OnlyFilename(s) + '#';
|
||||
FileInfo fileA(a);
|
||||
|
||||
if (fileA.exist() && fileN.exist()
|
||||
&& fileA.getModificationTime() > fileN.getModificationTime())
|
||||
if (fs::exists(a) && fs::exists(s)
|
||||
&& fs::last_write_time(a) > fs::last_write_time(s))
|
||||
{
|
||||
string const file = MakeDisplayPath(s, 20);
|
||||
string const text =
|
||||
@ -131,17 +128,14 @@ bool loadLyXFile(Buffer * b, string const & s)
|
||||
{
|
||||
BOOST_ASSERT(b);
|
||||
|
||||
switch (IsFileWriteable(s)) {
|
||||
case 0:
|
||||
b->setReadonly(true);
|
||||
// Fall through
|
||||
case 1:
|
||||
if (fs::is_readable(s)) {
|
||||
if (readFile(b, s)) {
|
||||
b->lyxvc().file_found_hook(s);
|
||||
if (!fs::is_writable(s))
|
||||
b->setReadonly(true);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
} else {
|
||||
string const file = MakeDisplayPath(s, 20);
|
||||
// Here we probably should run
|
||||
if (LyXVC::file_not_found_hook(s)) {
|
||||
@ -159,7 +153,6 @@ bool loadLyXFile(Buffer * b, string const & s)
|
||||
return loadLyXFile(b, s);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -30,11 +30,12 @@
|
||||
#include "outputparams.h"
|
||||
#include "frontends/Alert.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/package.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
using lyx::support::AddName;
|
||||
using lyx::support::bformat;
|
||||
using lyx::support::ChangeExtension;
|
||||
@ -50,6 +51,7 @@ using std::find;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
@ -66,7 +68,7 @@ vector<string> const Backends(Buffer const & buffer)
|
||||
/// ask the user what to do if a file already exists
|
||||
int checkOverwrite(string const & filename)
|
||||
{
|
||||
if (lyx::support::FileInfo(filename, true).exist()) {
|
||||
if (fs::exists(filename)) {
|
||||
string text = bformat(_("The file %1$s already exists.\n\n"
|
||||
"Do you want to over-write that file?"),
|
||||
MakeDisplayPath(filename));
|
||||
|
@ -1,3 +1,7 @@
|
||||
2005-01-31 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* ControlGraphics.C (browse): rewrite to use boost.filesystem
|
||||
|
||||
2005-01-20 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ControlSpellchecker.C (check): s/IGNORE/IGNORED_WORD/.
|
||||
|
@ -26,22 +26,24 @@
|
||||
#include "insets/insetgraphics.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filefilterlist.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/package.h"
|
||||
#include "support/types.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
using std::make_pair;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
using std::vector;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::AddName;
|
||||
using support::FileFilterList;
|
||||
using support::FileInfo;
|
||||
using support::IsFileReadable;
|
||||
using support::MakeAbsPath;
|
||||
using support::package;
|
||||
@ -85,8 +87,7 @@ string const ControlGraphics::browse(string const & in_name) const
|
||||
|
||||
// Does user clipart directory exist?
|
||||
string clipdir = AddName (package().user_support(), "clipart");
|
||||
FileInfo fileInfo(clipdir);
|
||||
if (!(fileInfo.isOK() && fileInfo.isDir()))
|
||||
if (!(fs::exists(clipdir) && fs::is_directory(clipdir)))
|
||||
// No - bail out to system clipart directory
|
||||
clipdir = AddName (package().system_support(), "clipart");
|
||||
pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
|
||||
|
@ -1,3 +1,10 @@
|
||||
2005-01-31 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* xforms_helpers.C: rewrite to use boost.filesystem
|
||||
|
||||
* FormFiledialog.[Ch]: simplify and rewrite to use boost.filesystem,
|
||||
remove lot of now unused code.
|
||||
|
||||
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* Several files: use convert<> instead of atoi,strToXXX and friends
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
#include "frontends/Dialogs.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filefilterlist.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/globbing.h"
|
||||
@ -31,47 +29,21 @@
|
||||
#include "lyx_forms.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
|
||||
//#ifdef HAVE_ERRNO_H
|
||||
//#include <cerrno>
|
||||
//#endif
|
||||
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
#else
|
||||
# define dirent direct
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
using lyx::support::AbsolutePath;
|
||||
using lyx::support::AddName;
|
||||
using lyx::support::ExpandPath;
|
||||
using lyx::support::FileFilterList;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::getcwd;
|
||||
using lyx::support::LyXReadLink;
|
||||
using lyx::support::MakeAbsPath;
|
||||
using lyx::support::OnlyFilename;
|
||||
using lyx::support::package;
|
||||
using lyx::support::split;
|
||||
using lyx::support::subst;
|
||||
using lyx::support::suffixIs;
|
||||
using lyx::support::trim;
|
||||
|
||||
@ -79,11 +51,10 @@ using std::max;
|
||||
using std::sort;
|
||||
using std::ostringstream;
|
||||
using std::string;
|
||||
using std::map;
|
||||
using std::vector;
|
||||
|
||||
using namespace lyx::frontend;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
@ -114,11 +85,6 @@ vector<string> const expand_globs(string const & mask,
|
||||
}
|
||||
|
||||
|
||||
// six months, in seconds
|
||||
long const SIX_MONTH_SEC = 6L * 30L * 24L * 60L * 60L;
|
||||
//static
|
||||
long const ONE_HOUR_SEC = 60L * 60L;
|
||||
|
||||
extern "C" {
|
||||
|
||||
static
|
||||
@ -141,72 +107,6 @@ extern "C" {
|
||||
|
||||
}
|
||||
|
||||
// *** User cache class implementation
|
||||
/// User cache class definition
|
||||
class UserCache {
|
||||
public:
|
||||
/// seeks user name from group ID
|
||||
string const & find(uid_t ID) const {
|
||||
Users::const_iterator cit = users.find(ID);
|
||||
if (cit == users.end()) {
|
||||
add(ID);
|
||||
return users[ID];
|
||||
}
|
||||
return cit->second;
|
||||
}
|
||||
private:
|
||||
///
|
||||
void add(uid_t ID) const;
|
||||
///
|
||||
typedef map<uid_t, string> Users;
|
||||
///
|
||||
mutable Users users;
|
||||
};
|
||||
|
||||
|
||||
void UserCache::add(uid_t ID) const
|
||||
{
|
||||
struct passwd const * entry = getpwuid(ID);
|
||||
users[ID] = entry ? entry->pw_name : convert<string>(int(ID));
|
||||
}
|
||||
|
||||
|
||||
/// Group cache class definition
|
||||
class GroupCache {
|
||||
public:
|
||||
/// seeks group name from group ID
|
||||
string const & find(gid_t ID) const ;
|
||||
private:
|
||||
///
|
||||
void add(gid_t ID) const;
|
||||
///
|
||||
typedef map<gid_t, string> Groups;
|
||||
///
|
||||
mutable Groups groups;
|
||||
};
|
||||
|
||||
|
||||
string const & GroupCache::find(gid_t ID) const
|
||||
{
|
||||
Groups::const_iterator cit = groups.find(ID);
|
||||
if (cit == groups.end()) {
|
||||
add(ID);
|
||||
return groups[ID];
|
||||
}
|
||||
return cit->second;
|
||||
}
|
||||
|
||||
|
||||
void GroupCache::add(gid_t ID) const
|
||||
{
|
||||
struct group const * entry = getgrgid(ID);
|
||||
groups[ID] = entry ? entry->gr_name : convert<string>(int(ID));
|
||||
}
|
||||
|
||||
|
||||
// local instances
|
||||
UserCache lyxUserCache;
|
||||
GroupCache lyxGroupCache;
|
||||
|
||||
// compares two LyXDirEntry objects content (used for sort)
|
||||
class comp_direntry : public std::binary_function<DirEntry, DirEntry, bool> {
|
||||
@ -240,15 +140,13 @@ int FileDialog::Private::minh_ = 0;
|
||||
void FileDialog::Private::Reread()
|
||||
{
|
||||
// Opens directory
|
||||
DIR * dir = ::opendir(directory_.c_str());
|
||||
if (!dir) {
|
||||
if (!fs::exists(directory_) || !fs::is_directory(directory_)) {
|
||||
// FIXME: re-add ...
|
||||
#if 0
|
||||
Alert::err_alert(_("Warning! Couldn't open directory."),
|
||||
directory_);
|
||||
#endif
|
||||
directory_ = getcwd();
|
||||
dir = ::opendir(directory_.c_str());
|
||||
}
|
||||
|
||||
// Clear the present namelist
|
||||
@ -261,14 +159,14 @@ void FileDialog::Private::Reread()
|
||||
|
||||
// Splits complete directory name into directories and compute depth
|
||||
depth_ = 0;
|
||||
string line, Temp;
|
||||
string mode;
|
||||
string line;
|
||||
string Temp;
|
||||
string File = directory_;
|
||||
if (File != "/")
|
||||
File = split(File, Temp, '/');
|
||||
|
||||
while (!File.empty() || !Temp.empty()) {
|
||||
string dline = "@b" + line + Temp + '/';
|
||||
string const dline = "@b" + line + Temp + '/';
|
||||
fl_add_browser_line(file_dlg_form_->List, dline.c_str());
|
||||
File = split(File, Temp, '/');
|
||||
line += ' ';
|
||||
@ -277,118 +175,37 @@ void FileDialog::Private::Reread()
|
||||
|
||||
vector<string> const glob_matches = expand_globs(mask_, directory_);
|
||||
|
||||
time_t curTime = time(0);
|
||||
rewinddir(dir);
|
||||
while (dirent * entry = readdir(dir)) {
|
||||
bool isLink = false, isDir = false;
|
||||
fs::directory_iterator beg(directory_);
|
||||
fs::directory_iterator end;
|
||||
for (; beg != end; ++beg) {
|
||||
string const fname = beg->leaf();
|
||||
|
||||
// If the pattern doesn't start with a dot, skip hidden files
|
||||
if (!mask_.empty() && mask_[0] != '.' &&
|
||||
entry->d_name[0] == '.')
|
||||
if (!mask_.empty() && mask_[0] != '.' && fname[0] == '.')
|
||||
continue;
|
||||
|
||||
// Gets filename
|
||||
string fname = entry->d_name;
|
||||
|
||||
// Under all circumstances, "." and ".." are not wanted
|
||||
if (fname == "." || fname == "..")
|
||||
continue;
|
||||
|
||||
// gets file status
|
||||
File = AddName(directory_, fname);
|
||||
|
||||
FileInfo fileInfo(File, true);
|
||||
|
||||
// can this really happen?
|
||||
if (!fileInfo.isOK())
|
||||
continue;
|
||||
|
||||
mode = fileInfo.modeString();
|
||||
string const user = lyxUserCache.find(fileInfo.getUid());
|
||||
string const group = lyxGroupCache.find(fileInfo.getGid());
|
||||
|
||||
time_t modtime = fileInfo.getModificationTime();
|
||||
string Time = ctime(&modtime);
|
||||
|
||||
if (curTime > modtime + SIX_MONTH_SEC
|
||||
|| curTime < modtime + ONE_HOUR_SEC) {
|
||||
// The file is fairly old or in the future. POSIX says
|
||||
// the cutoff is 6 months old. Allow a 1 hour slop
|
||||
// factor for what is considered "the future", to
|
||||
// allow for NFS server/client clock disagreement.
|
||||
// Show the year instead of the time of day.
|
||||
Time.erase(10, 9);
|
||||
Time.erase(15, string::npos);
|
||||
} else {
|
||||
Time.erase(16, string::npos);
|
||||
}
|
||||
|
||||
string buffer = mode + ' ' +
|
||||
user + ' ' +
|
||||
group + ' ' +
|
||||
Time.substr(4, string::npos) + ' ';
|
||||
|
||||
buffer += entry->d_name;
|
||||
buffer += fileInfo.typeIndicator();
|
||||
|
||||
isLink = fileInfo.isLink();
|
||||
if (isLink) {
|
||||
string Link;
|
||||
|
||||
if (LyXReadLink(File, Link)) {
|
||||
buffer += " -> ";
|
||||
buffer += Link;
|
||||
|
||||
// This gives the FileType of the file that
|
||||
// is really pointed to after resolving all
|
||||
// symlinks. This is not necessarily the same
|
||||
// as the type of Link (which could again be a
|
||||
// link). Is that intended?
|
||||
// JV 199902
|
||||
fileInfo.newFile(File);
|
||||
if (fileInfo.isOK())
|
||||
buffer += fileInfo.typeIndicator();
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
bool const isDir = fs::is_directory(*beg);
|
||||
|
||||
// filters files according to pattern and type
|
||||
if (fileInfo.isRegular()
|
||||
|| fileInfo.isChar()
|
||||
|| fileInfo.isBlock()
|
||||
|| fileInfo.isFifo()) {
|
||||
typedef vector<string>::const_iterator viterator;
|
||||
viterator gbegin = glob_matches.begin();
|
||||
viterator const gend = glob_matches.end();
|
||||
if (std::find(gbegin, gend, fname) == gend)
|
||||
continue;
|
||||
} else if (!(isDir = fileInfo.isDir()))
|
||||
|
||||
if (!isDir && std::find(gbegin, gend, fname) == gend)
|
||||
continue;
|
||||
|
||||
DirEntry tmp;
|
||||
|
||||
// Note ls_entry_ is an string!
|
||||
tmp.ls_entry_ = buffer;
|
||||
// creates used name
|
||||
string temp = fname;
|
||||
tmp.name_ = fname;
|
||||
|
||||
if (isDir)
|
||||
temp += '/';
|
||||
tmp.name_ += '/';
|
||||
|
||||
tmp.name_ = temp;
|
||||
// creates displayed name
|
||||
temp = entry->d_name;
|
||||
if (isLink)
|
||||
temp += '@';
|
||||
else
|
||||
temp += fileInfo.typeIndicator();
|
||||
tmp.displayed_ = temp;
|
||||
|
||||
tmp.displayed_ = fname;
|
||||
dir_entries_.push_back(tmp);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
// Sort the names
|
||||
sort(dir_entries_.begin(), dir_entries_.end(), comp_direntry());
|
||||
|
||||
@ -414,14 +231,12 @@ void FileDialog::Private::SetDirectory(string const & path)
|
||||
tmp = MakeAbsPath(ExpandPath(path), directory_);
|
||||
|
||||
// must check the directory exists
|
||||
DIR * dir = ::opendir(tmp.c_str());
|
||||
if (!dir) {
|
||||
if (!fs::exists(tmp) || !fs::is_directory(tmp)) {
|
||||
// FIXME: re-add ...
|
||||
#if 0
|
||||
Alert::err_alert(_("Warning! Couldn't open directory."), tmp);
|
||||
#endif
|
||||
} else {
|
||||
::closedir(dir);
|
||||
directory_ = tmp;
|
||||
}
|
||||
}
|
||||
@ -457,14 +272,6 @@ void FileDialog::Private::SetFilters(FileFilterList const & filters)
|
||||
}
|
||||
|
||||
|
||||
// SetInfoLine: sets dialog information line
|
||||
void FileDialog::Private::SetInfoLine(string const & line)
|
||||
{
|
||||
info_line_ = line;
|
||||
fl_set_object_label(file_dlg_form_->FileInfo, info_line_.c_str());
|
||||
}
|
||||
|
||||
|
||||
FileDialog::Private::Private()
|
||||
{
|
||||
directory_ = MakeAbsPath(string("."));
|
||||
@ -644,10 +451,12 @@ void FileDialog::Private::HandleListHit()
|
||||
{
|
||||
// set info line
|
||||
int const select_ = fl_get_browser(file_dlg_form_->List);
|
||||
if (select_ > depth_)
|
||||
SetInfoLine(dir_entries_[select_ - depth_ - 1].ls_entry_);
|
||||
else
|
||||
SetInfoLine(string());
|
||||
string line = (select_ > depth_ ?
|
||||
dir_entries_[select_ - depth_ - 1].name_ :
|
||||
string());
|
||||
if (suffixIs(line, '/'))
|
||||
line.clear();
|
||||
fl_set_input(file_dlg_form_->Filename, line.c_str());
|
||||
}
|
||||
|
||||
|
||||
@ -670,14 +479,11 @@ bool FileDialog::Private::HandleDoubleClick()
|
||||
int const select_ = fl_get_browser(file_dlg_form_->List);
|
||||
if (select_ > depth_) {
|
||||
tmp = dir_entries_[select_ - depth_ - 1].name_;
|
||||
SetInfoLine(dir_entries_[select_ - depth_ - 1].ls_entry_);
|
||||
if (!suffixIs(tmp, '/')) {
|
||||
isDir = false;
|
||||
fl_set_input(file_dlg_form_->Filename, tmp.c_str());
|
||||
}
|
||||
} else if (select_ != 0) {
|
||||
SetInfoLine(string());
|
||||
} else
|
||||
} else if (select_ == 0)
|
||||
return true;
|
||||
|
||||
// executes action
|
||||
@ -696,7 +502,7 @@ bool FileDialog::Private::HandleDoubleClick()
|
||||
// Directory higher up
|
||||
Temp.erase();
|
||||
for (int i = 0; i < select_; ++i) {
|
||||
string piece = fl_get_browser_line(file_dlg_form_->List, i+1);
|
||||
string const piece = fl_get_browser_line(file_dlg_form_->List, i + 1);
|
||||
// The '+2' is here to count the '@b' (JMarc)
|
||||
Temp += piece.substr(i + 2);
|
||||
}
|
||||
@ -808,7 +614,6 @@ string const FileDialog::Private::Select(string const & title,
|
||||
current_dlg_ = this;
|
||||
|
||||
// runs dialog
|
||||
SetInfoLine(string());
|
||||
setEnabled(file_dlg_form_->Filename, true);
|
||||
fl_set_input(file_dlg_form_->Filename, suggested.c_str());
|
||||
fl_set_button(file_dlg_form_->Cancel, 0);
|
||||
@ -858,11 +663,10 @@ string const FileDialog::Private::SelectDir(string const & title,
|
||||
string tmp = suggested;
|
||||
if (!suffixIs(tmp, '/'))
|
||||
tmp += '/';
|
||||
string full_path = path;
|
||||
full_path += tmp;
|
||||
string const full_path = path + tmp;
|
||||
// check if this is really a directory
|
||||
DIR * dir = ::opendir(full_path.c_str());
|
||||
if (dir)
|
||||
if (fs::exists(full_path)
|
||||
&& fs::is_directory(full_path))
|
||||
SetDirectory(full_path);
|
||||
else
|
||||
SetDirectory(path);
|
||||
@ -879,7 +683,6 @@ string const FileDialog::Private::SelectDir(string const & title,
|
||||
current_dlg_ = this;
|
||||
|
||||
// runs dialog
|
||||
SetInfoLine(string());
|
||||
fl_set_input(file_dlg_form_->Filename, "");
|
||||
setEnabled(file_dlg_form_->Filename, false);
|
||||
fl_set_button(file_dlg_form_->Cancel, 0);
|
||||
|
@ -43,8 +43,6 @@ public:
|
||||
std::string name_;
|
||||
///
|
||||
std::string displayed_;
|
||||
///
|
||||
std::string ls_entry_;
|
||||
};
|
||||
|
||||
|
||||
@ -115,8 +113,6 @@ private:
|
||||
///
|
||||
long last_time_;
|
||||
///
|
||||
std::string info_line_;
|
||||
///
|
||||
typedef std::vector<lyx::frontend::DirEntry> DirEntries;
|
||||
///
|
||||
DirEntries dir_entries_;
|
||||
@ -136,8 +132,6 @@ private:
|
||||
/// sets dialog file mask
|
||||
void SetFilters(std::string const & filters);
|
||||
void SetFilters(lyx::support::FileFilterList const & filters);
|
||||
/// sets dialog information line
|
||||
void SetInfoLine(std::string const & pszLine);
|
||||
/// handle dialog during file selection
|
||||
bool RunDialog();
|
||||
/// Handle callback from list
|
||||
|
@ -18,15 +18,16 @@
|
||||
#include "lyxgluelength.h"
|
||||
#include "lyxlex.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h" // frontStrip, strip
|
||||
#include "support/convert.h"
|
||||
#include "support/fs_extras.h"
|
||||
|
||||
#include "lyx_forms.h"
|
||||
#include "combox.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@ -36,10 +37,11 @@ using std::ofstream;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::AbsolutePath;
|
||||
using support::FileInfo;
|
||||
using support::isStrDbl;
|
||||
using support::OnlyPath;
|
||||
using support::subst;
|
||||
@ -336,9 +338,8 @@ const int xformCount = sizeof(xformTags) / sizeof(keyword_item);
|
||||
|
||||
bool XformsColor::read(string const & filename)
|
||||
{
|
||||
FileInfo const f(filename);
|
||||
LyXLex lexrc(xformTags, xformCount);
|
||||
if (f.readable() && !lexrc.setFile(filename)) {
|
||||
if (fs::is_readable(filename) && !lexrc.setFile(filename)) {
|
||||
lyxerr << "XformsColor::read(" << filename << ")\n"
|
||||
<< _("Failed to open file.") << std::endl;
|
||||
return false;
|
||||
@ -421,13 +422,12 @@ bool RWInfo::WriteableDir(string const & name)
|
||||
return false;
|
||||
}
|
||||
|
||||
FileInfo const tp(name);
|
||||
if (!tp.isOK() || !tp.isDir()) {
|
||||
if (!fs::exists(name) || !fs::is_directory(name)) {
|
||||
error_message = _("Directory does not exist.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tp.writable()) {
|
||||
if (!fs::is_writable(name)) {
|
||||
error_message = _("Cannot write to this directory.");
|
||||
return false;
|
||||
}
|
||||
@ -445,13 +445,12 @@ bool RWInfo::ReadableDir(string const & name)
|
||||
return false;
|
||||
}
|
||||
|
||||
FileInfo const tp(name);
|
||||
if (!tp.isOK() || !tp.isDir()) {
|
||||
if (!fs::exists(name) || !fs::is_directory(name)) {
|
||||
error_message = _("Directory does not exist.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tp.readable()) {
|
||||
if (!fs::is_readable(name)) {
|
||||
error_message = _("Cannot read this directory.");
|
||||
return false;
|
||||
}
|
||||
@ -480,29 +479,28 @@ bool RWInfo::WriteableFile(string const & name)
|
||||
return false;
|
||||
}
|
||||
|
||||
FileInfo d(name);
|
||||
string checkFile = name;
|
||||
|
||||
if (!d.isOK() || !d.isDir()) {
|
||||
d.newFile(dir);
|
||||
if (!fs::exists(checkFile) || !fs::is_directory(checkFile)) {
|
||||
checkFile = dir;
|
||||
}
|
||||
|
||||
if (!d.isOK() || !d.isDir()) {
|
||||
error_message = _("Directory does not exist.");
|
||||
if (!fs::exists(checkFile) || !fs::is_directory(checkFile)) {
|
||||
error_message = _("Directory does not exists.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!d.writable()) {
|
||||
if (!fs::is_writable(checkFile)) {
|
||||
error_message = _("Cannot write to this directory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
FileInfo f(name);
|
||||
if (dir == name || (f.isOK() && f.isDir())) {
|
||||
if (dir == name || (fs::exists(name) && fs::is_directory(name))) {
|
||||
error_message = _("A file is required, not a directory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (f.isOK() && f.exist() && !f.writable()) {
|
||||
if (fs::exists(name) && !fs::is_writable(name)) {
|
||||
error_message = _("Cannot write to this file.");
|
||||
return false;
|
||||
}
|
||||
@ -526,34 +524,33 @@ bool RWInfo::ReadableFile(string const & name)
|
||||
return false;
|
||||
}
|
||||
|
||||
FileInfo d(name);
|
||||
string checkFile = name;
|
||||
|
||||
if (!d.isOK() && !d.isDir()) {
|
||||
d.newFile(dir);
|
||||
if (!fs::exists(checkFile) && !fs::is_directory(checkFile)) {
|
||||
checkFile = dir;
|
||||
}
|
||||
|
||||
if (!d.isOK() || !d.isDir()) {
|
||||
if (!fs::exists(checkFile) || !fs::is_directory(checkFile)) {
|
||||
error_message = _("Directory does not exist.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!d.readable()) {
|
||||
if (!fs::is_readable(checkFile)) {
|
||||
error_message = _("Cannot read from this directory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
FileInfo f(name);
|
||||
if (dir == name || (f.isOK() && f.isDir())) {
|
||||
if (dir == name || (fs::exists(name) && fs::is_directory(name))) {
|
||||
error_message = _("A file is required, not a directory.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!f.exist()) {
|
||||
if (!fs::exists(name)) {
|
||||
error_message = _("File does not exist.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!f.readable()) {
|
||||
if (!fs::is_readable(name)) {
|
||||
error_message = _("Cannot read from this file.");
|
||||
return false;
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
2005-01-31 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* insetinclude.C (loadIfNeeded): rewrite to use boost.filesystem
|
||||
|
||||
2005-01-31 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* insetgraphicsParams.C: protect a #warning preprocessor call
|
||||
|
@ -37,7 +37,6 @@
|
||||
|
||||
#include "graphics/PreviewLoader.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
|
@ -39,7 +39,6 @@
|
||||
|
||||
#include "insets/render_preview.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filename.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h" // contains
|
||||
@ -47,6 +46,7 @@
|
||||
#include "support/convert.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
|
||||
@ -58,7 +58,6 @@ using lyx::support::bformat;
|
||||
using lyx::support::ChangeExtension;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::copy;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::FileName;
|
||||
using lyx::support::GetFileContents;
|
||||
using lyx::support::IsFileReadable;
|
||||
@ -78,6 +77,7 @@ using std::istringstream;
|
||||
using std::ostream;
|
||||
using std::ostringstream;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
extern BufferList bufferlist;
|
||||
|
||||
@ -294,8 +294,7 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
|
||||
Buffer * buf = bufferlist.getBuffer(included_file);
|
||||
if (!buf) {
|
||||
// the readonly flag can/will be wrong, not anymore I think.
|
||||
FileInfo finfo(included_file);
|
||||
if (!finfo.isOK())
|
||||
if (!fs::exists(included_file))
|
||||
return false;
|
||||
buf = bufferlist.newBuffer(included_file);
|
||||
if (!loadLyXFile(buf, included_file))
|
||||
|
@ -13,13 +13,13 @@
|
||||
#include "lastfiles.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
|
||||
using lyx::support::FileInfo;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
using std::copy;
|
||||
using std::endl;
|
||||
@ -58,14 +58,10 @@ void LastFiles::readFile(string const & filename)
|
||||
// we issue a warning. (Lgb)
|
||||
ifstream ifs(filename.c_str());
|
||||
string tmp;
|
||||
FileInfo fileInfo;
|
||||
|
||||
while (getline(ifs, tmp) && files.size() < num_files) {
|
||||
if (dostat) {
|
||||
if (!(fileInfo.newFile(tmp).exist() &&
|
||||
fileInfo.isRegular()))
|
||||
if (dostat && !fs::exists(tmp))
|
||||
continue;
|
||||
}
|
||||
files.push_back(tmp);
|
||||
}
|
||||
}
|
||||
|
20
src/lyx_cb.C
20
src/lyx_cb.C
@ -36,15 +36,16 @@
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
#include "support/filefilterlist.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/forkedcall.h"
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/package.h"
|
||||
#include "support/path.h"
|
||||
#include "support/systemcall.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <cerrno>
|
||||
#include <fstream>
|
||||
@ -53,7 +54,6 @@ using lyx::support::AddName;
|
||||
using lyx::support::bformat;
|
||||
using lyx::support::destroyDir;
|
||||
using lyx::support::FileFilterList;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::ForkedProcess;
|
||||
using lyx::support::IsLyXFilename;
|
||||
using lyx::support::LibFileSearch;
|
||||
@ -73,6 +73,8 @@ using lyx::support::unlink;
|
||||
|
||||
using boost::shared_ptr;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
using std::back_inserter;
|
||||
using std::copy;
|
||||
using std::endl;
|
||||
@ -154,8 +156,7 @@ bool WriteAs(Buffer * buffer, string const & filename)
|
||||
} else
|
||||
fname = filename;
|
||||
|
||||
FileInfo const myfile(fname);
|
||||
if (myfile.isOK()) {
|
||||
if (fs::exists(fname)) {
|
||||
string const file = MakeDisplayPath(fname, 30);
|
||||
string text = bformat(_("The document %1$s already exists.\n\n"
|
||||
"Do you want to over-write that document?"), file);
|
||||
@ -204,10 +205,11 @@ void QuitLyX()
|
||||
// do any other cleanup procedures now
|
||||
lyxerr[Debug::INFO] << "Deleting tmp dir " << package().temp_dir() << endl;
|
||||
|
||||
if (destroyDir(package().temp_dir()) != 0) {
|
||||
string msg = bformat(_("Could not remove the temporary directory %1$s"),
|
||||
if (!destroyDir(package().temp_dir())) {
|
||||
string const msg =
|
||||
bformat(_("Unable to remove the temporary directory %1$s"),
|
||||
package().temp_dir());
|
||||
Alert::warning(_("Could not remove temporary directory"), msg);
|
||||
Alert::warning(_("Unable to remove temporary directory"), msg);
|
||||
}
|
||||
|
||||
lyx_gui::exit();
|
||||
@ -392,9 +394,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
|
||||
return string();
|
||||
}
|
||||
|
||||
FileInfo fi(fname);
|
||||
|
||||
if (!fi.readable()) {
|
||||
if (!fs::is_readable(fname)) {
|
||||
string const error = strerror(errno);
|
||||
string const file = MakeDisplayPath(fname, 50);
|
||||
string const text = bformat(_("Could not read the specified document\n"
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "frontends/lyx_gui.h"
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/os.h"
|
||||
@ -53,6 +52,7 @@
|
||||
#include "support/path.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
@ -62,7 +62,6 @@ using lyx::support::AddPath;
|
||||
using lyx::support::bformat;
|
||||
using lyx::support::createDirectory;
|
||||
using lyx::support::createLyXTmpDir;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::FileSearch;
|
||||
using lyx::support::GetEnv;
|
||||
using lyx::support::i18nLibFileSearch;
|
||||
@ -74,6 +73,7 @@ using lyx::support::QuoteName;
|
||||
using lyx::support::rtrim;
|
||||
|
||||
namespace os = lyx::support::os;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
@ -483,8 +483,7 @@ void LyX::init(bool gui)
|
||||
if (reconfigure)
|
||||
reconfigureUserLyXDir();
|
||||
|
||||
FileInfo fi(lyxrc.document_path);
|
||||
if (fi.isOK() && fi.isDir())
|
||||
if (fs::is_directory(lyxrc.document_path))
|
||||
package().document_dir() = lyxrc.document_path;
|
||||
|
||||
package().temp_dir() = createLyXTmpDir(lyxrc.tempdir_path);
|
||||
@ -612,15 +611,16 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
|
||||
bool reconfigure = false;
|
||||
|
||||
// Does user directory exist?
|
||||
FileInfo fileInfo(package().user_support());
|
||||
if (fileInfo.isOK() && fileInfo.isDir()) {
|
||||
if (fs::is_directory(package().user_support())) {
|
||||
first_start = false;
|
||||
string const configure_script =
|
||||
AddName(package().system_support(), "configure");
|
||||
FileInfo script(configure_script);
|
||||
FileInfo defaults(AddName(package().user_support(), "lyxrc.defaults"));
|
||||
if (defaults.isOK() && script.isOK()
|
||||
&& defaults.getModificationTime() < script.getModificationTime()) {
|
||||
string const userDefaults =
|
||||
AddName(package().user_support(), "lyxrc.defaults");
|
||||
if (fs::exists(configure_script) &&
|
||||
fs::exists(userDefaults) &&
|
||||
fs::last_write_time(configure_script)
|
||||
< fs::last_write_time(userDefaults)) {
|
||||
reconfigure = true;
|
||||
}
|
||||
return reconfigure;
|
||||
|
@ -79,9 +79,9 @@
|
||||
#include "frontends/Toolbars.h"
|
||||
|
||||
#include "support/filefilterlist.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/forkedcontr.h"
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/path.h"
|
||||
#include "support/package.h"
|
||||
@ -89,6 +89,8 @@
|
||||
#include "support/convert.h"
|
||||
#include "support/os.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using bv_funcs::freefont2string;
|
||||
@ -99,7 +101,6 @@ using lyx::support::bformat;
|
||||
using lyx::support::ChangeExtension;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::FileFilterList;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::FileSearch;
|
||||
using lyx::support::ForkedcallsController;
|
||||
using lyx::support::i18nLibFileSearch;
|
||||
@ -126,6 +127,7 @@ using std::string;
|
||||
using std::istringstream;
|
||||
|
||||
namespace biblio = lyx::biblio;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
|
||||
extern BufferList bufferlist;
|
||||
@ -1610,13 +1612,11 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
|
||||
if (filename.empty()) {
|
||||
filename = AddName(lyxrc.document_path,
|
||||
"newfile" + convert<string>(++newfile_number) + ".lyx");
|
||||
FileInfo fi(filename);
|
||||
while (bufferlist.exists(filename) || fi.readable()) {
|
||||
while (bufferlist.exists(filename) || fs::is_readable(filename)) {
|
||||
++newfile_number;
|
||||
filename = AddName(lyxrc.document_path,
|
||||
"newfile" + convert<string>(newfile_number) +
|
||||
".lyx");
|
||||
fi.newFile(filename);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1695,8 +1695,7 @@ void LyXFunc::open(string const & fname)
|
||||
string const disp_fn(MakeDisplayPath(filename));
|
||||
|
||||
// if the file doesn't exist, let the user create one
|
||||
FileInfo const f(filename, true);
|
||||
if (!f.exist()) {
|
||||
if (!fs::exists(filename)) {
|
||||
// the user specifically chose this name. Believe them.
|
||||
view()->newFile(filename, "", true);
|
||||
return;
|
||||
@ -1779,7 +1778,7 @@ void LyXFunc::doImport(string const & argument)
|
||||
|
||||
// if the file exists already, and we didn't do
|
||||
// -i lyx thefile.lyx, warn
|
||||
if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
|
||||
if (fs::exists(lyxfile) && filename != lyxfile) {
|
||||
string const file = MakeDisplayPath(lyxfile, 30);
|
||||
|
||||
string text = bformat(_("The document %1$s already exists.\n\n"
|
||||
@ -1903,8 +1902,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) {
|
||||
FileInfo fi(lyxrc_new.document_path);
|
||||
if (fi.isOK() && fi.isDir()) {
|
||||
if (fs::exists(lyxrc_new.document_path) &&
|
||||
fs::is_directory(lyxrc_new.document_path)) {
|
||||
using lyx::support::package;
|
||||
package().document_dir() = lyxrc.document_path;
|
||||
}
|
||||
|
@ -17,18 +17,23 @@
|
||||
|
||||
#include "support/os.h"
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#ifdef HAVE_IOS
|
||||
#include <ios>
|
||||
#endif
|
||||
|
||||
|
||||
namespace os = lyx::support::os;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
#ifdef HAVE_IOS
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
#endif
|
||||
fs::path::default_name_check(fs::no_check);
|
||||
|
||||
// To avoid ordering of global object problems with some
|
||||
// stdlibs we do the initialization here, but still as
|
||||
// early as possible.
|
||||
|
@ -7,3 +7,4 @@ libsupport.la
|
||||
path_defines.C
|
||||
pch.h.gch
|
||||
pch.h.gch.dep
|
||||
package.C
|
||||
|
@ -1,10 +1,30 @@
|
||||
2005-01-31 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* .cvsignore: add package.C
|
||||
|
||||
* FileInfo.C, FileInfo.h: delete files
|
||||
|
||||
* fs_extras.C, fs_extras.h: new files
|
||||
|
||||
* FileMonitor.C, filetools.C: rewrite to use boost.filesystem
|
||||
|
||||
* Makefile.am (libsupport_la_SOURCES: delete FileInfo.[Ch], add
|
||||
fs_extras.[Ch]
|
||||
|
||||
* filetools.C: make destroydir return true if something was
|
||||
deleted. adjust callers.
|
||||
(IsFileWritable): replace with is_readonly in fs_extras, adjust
|
||||
callers
|
||||
|
||||
* package.C.in: rewrite to use boost.filesystem
|
||||
|
||||
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* tests: add some code for automatic regression testing, can be
|
||||
improved or removed as we see fit
|
||||
|
||||
|
||||
* lyxlib.h (atoi): delete func
|
||||
|
||||
|
||||
* lstrings.[Ch] (strToInt): delete func
|
||||
(strToUnsignedInt): delete func
|
||||
(strToDbl): delete func
|
||||
|
@ -1,393 +0,0 @@
|
||||
/**
|
||||
* \file FileInfo.C
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Lars Gullik Bjønnes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cerrno>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
#if !S_IRUSR
|
||||
# if S_IREAD
|
||||
# define S_IRUSR S_IREAD
|
||||
# else
|
||||
# define S_IRUSR 00400
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !S_IWUSR
|
||||
# if S_IWRITE
|
||||
# define S_IWUSR S_IWRITE
|
||||
# else
|
||||
# define S_IWUSR 00200
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !S_IXUSR
|
||||
# if S_IEXEC
|
||||
# define S_IXUSR S_IEXEC
|
||||
# else
|
||||
# define S_IXUSR 00100
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef STAT_MACROS_BROKEN
|
||||
#undef S_ISBLK
|
||||
#undef S_ISCHR
|
||||
#undef S_ISDIR
|
||||
#undef S_ISFIFO
|
||||
#undef S_ISLNK
|
||||
#undef S_ISMPB
|
||||
#undef S_ISMPC
|
||||
#undef S_ISNWK
|
||||
#undef S_ISREG
|
||||
#undef S_ISSOCK
|
||||
#endif
|
||||
|
||||
#if !defined(S_ISBLK) && defined(S_IFBLK)
|
||||
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
||||
#endif
|
||||
#if !defined(S_ISCHR) && defined(S_IFCHR)
|
||||
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
#endif
|
||||
#if !defined(S_ISDIR) && defined(S_IFDIR)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
#if !defined(S_ISREG) && defined(S_IFREG)
|
||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
#if !defined(S_ISFIFO) && defined(S_IFIFO)
|
||||
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
#endif
|
||||
#if !defined(S_ISLNK) && defined(S_IFLNK)
|
||||
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
||||
#endif
|
||||
#if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
||||
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
#endif
|
||||
#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
||||
#define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
||||
#define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
||||
#endif
|
||||
#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
||||
#define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
||||
#endif
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// builds 'rwx' string describing file access rights
|
||||
void flagRWX(mode_t i, char * str)
|
||||
{
|
||||
str[0] = (i & S_IRUSR) ? 'r' : '-';
|
||||
str[1] = (i & S_IWUSR) ? 'w' : '-';
|
||||
str[2] = (i & S_IXUSR) ? 'x' : '-';
|
||||
}
|
||||
|
||||
// updates mode string to match suid/sgid/sticky bits
|
||||
void setSticky(mode_t i, char * str)
|
||||
{
|
||||
#ifdef S_ISUID
|
||||
if (i & S_ISUID)
|
||||
str[3] = (str[3] == 'x') ? 's' : 'S';
|
||||
#endif
|
||||
#ifdef S_ISGID
|
||||
if (i & S_ISGID)
|
||||
str[6] = (str[6] == 'x') ? 's' : 'S';
|
||||
#endif
|
||||
#ifdef S_ISVTX
|
||||
if (i & S_ISVTX)
|
||||
str[9] = (str[9] == 'x') ? 's' : 'S';
|
||||
#endif
|
||||
}
|
||||
|
||||
// returns a letter describing a file type (ls style)
|
||||
char typeLetter(mode_t i)
|
||||
{
|
||||
#ifdef S_ISBLK
|
||||
if (S_ISBLK(i)) return 'b';
|
||||
#endif
|
||||
if (S_ISCHR(i)) return 'c';
|
||||
if (S_ISDIR(i)) return 'd';
|
||||
if (S_ISREG(i)) return '-';
|
||||
#ifdef S_ISFIFO
|
||||
if (S_ISFIFO(i)) return 'p';
|
||||
#endif
|
||||
#ifdef S_ISLNK
|
||||
if (S_ISLNK(i)) return 'l';
|
||||
#endif
|
||||
#ifdef S_ISSOCK
|
||||
if (S_ISSOCK(i)) return 's';
|
||||
#endif
|
||||
#ifdef S_ISMPC
|
||||
if (S_ISMPC(i)) return 'm';
|
||||
#endif
|
||||
#ifdef S_ISNWK
|
||||
if (S_ISNWK(i)) return 'n';
|
||||
#endif
|
||||
return '?';
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
FileInfo::FileInfo()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
FileInfo::FileInfo(string const & path, bool link)
|
||||
// Win32 stat() doesn't dig trailing slashes.
|
||||
// Posix stat() doesn't care, but we'll remove it anyway.
|
||||
: fname_(rtrim(path, "/"))
|
||||
{
|
||||
init();
|
||||
dostat(link);
|
||||
}
|
||||
|
||||
|
||||
FileInfo::FileInfo(int fildes)
|
||||
{
|
||||
init();
|
||||
status_ = fstat(fildes, &buf_);
|
||||
if (status_)
|
||||
err_ = errno;
|
||||
}
|
||||
|
||||
|
||||
void FileInfo::init()
|
||||
{
|
||||
status_ = 0;
|
||||
err_ = NoErr;
|
||||
}
|
||||
|
||||
|
||||
void FileInfo::dostat(bool link)
|
||||
{
|
||||
#ifdef HAVE_LSTAT
|
||||
if (link)
|
||||
status_ = ::lstat(fname_.c_str(), &buf_);
|
||||
else
|
||||
status_ = ::stat(fname_.c_str(), &buf_);
|
||||
#else
|
||||
status_ = ::stat(fname_.c_str(), &buf_);
|
||||
#endif
|
||||
|
||||
if (status_)
|
||||
err_ = errno;
|
||||
}
|
||||
|
||||
|
||||
FileInfo & FileInfo::newFile(string const & path, bool link)
|
||||
{
|
||||
// Win32 stat() doesn't dig trailing slashes.
|
||||
// Posix stat() doesn't care, but we'll remove it anyway.
|
||||
fname_ = rtrim(path, "/");
|
||||
status_ = 0;
|
||||
err_ = NoErr;
|
||||
dostat(link);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
FileInfo & FileInfo::newFile(int fildes)
|
||||
{
|
||||
status_ = 0;
|
||||
err_ = NoErr;
|
||||
status_ = fstat(fildes, &buf_);
|
||||
if (status_)
|
||||
err_ = errno;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// should not be in FileInfo
|
||||
char FileInfo::typeIndicator() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
if (S_ISDIR(buf_.st_mode))
|
||||
return '/';
|
||||
#ifdef S_ISLNK
|
||||
if (S_ISLNK(buf_.st_mode))
|
||||
return '@';
|
||||
#endif
|
||||
#ifdef S_ISFIFO
|
||||
if (S_ISFIFO(buf_.st_mode))
|
||||
return '|';
|
||||
#endif
|
||||
#ifdef S_ISSOCK
|
||||
if (S_ISSOCK(buf_.st_mode))
|
||||
return '=';
|
||||
#endif
|
||||
return ' ';
|
||||
}
|
||||
|
||||
|
||||
mode_t FileInfo::getMode() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return buf_.st_mode;
|
||||
}
|
||||
|
||||
|
||||
// should not be in FileInfo
|
||||
string FileInfo::modeString() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
char str[11];
|
||||
str[0] = typeLetter(buf_.st_mode);
|
||||
flagRWX((buf_.st_mode & 0700) << 0, &str[1]);
|
||||
flagRWX((buf_.st_mode & 0070) << 3, &str[4]);
|
||||
flagRWX((buf_.st_mode & 0007) << 6, &str[7]);
|
||||
setSticky(buf_.st_mode, str);
|
||||
str[10] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
time_t FileInfo::getModificationTime() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return buf_.st_mtime;
|
||||
}
|
||||
|
||||
|
||||
time_t FileInfo::getAccessTime() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return buf_.st_atime;
|
||||
}
|
||||
|
||||
|
||||
time_t FileInfo::getStatusChangeTime() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return buf_.st_ctime;
|
||||
}
|
||||
|
||||
|
||||
uid_t FileInfo::getUid() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return buf_.st_uid;
|
||||
}
|
||||
|
||||
|
||||
gid_t FileInfo::getGid() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return buf_.st_gid;
|
||||
}
|
||||
|
||||
|
||||
off_t FileInfo::getSize() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return buf_.st_size;
|
||||
}
|
||||
|
||||
|
||||
int FileInfo::getError() const
|
||||
{
|
||||
return err_;
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isOK() const
|
||||
{
|
||||
return status_ == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isLink() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
#ifdef S_ISLNK
|
||||
return S_ISLNK(buf_.st_mode);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isRegular() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return S_ISREG(buf_.st_mode);
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isDir() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return S_ISDIR(buf_.st_mode);
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isChar() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return S_ISCHR(buf_.st_mode);
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isBlock() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return S_ISBLK(buf_.st_mode);
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isFifo() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
return S_ISFIFO(buf_.st_mode);
|
||||
}
|
||||
|
||||
|
||||
bool FileInfo::isSocket() const
|
||||
{
|
||||
BOOST_ASSERT(isOK());
|
||||
#ifdef S_ISSOCK
|
||||
return S_ISSOCK(buf_.st_mode);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// should not be in FileInfo
|
||||
bool FileInfo::access(int p) const
|
||||
{
|
||||
// if we don't have a filename we fail
|
||||
if (fname_.empty())
|
||||
return false;
|
||||
|
||||
// If we were really kind, we would also tell why
|
||||
// the file access failed.
|
||||
return ::access(fname_.c_str(), p) == 0;
|
||||
}
|
||||
|
||||
} // namespace support
|
||||
} // namespace lyx
|
@ -1,145 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file FileInfo.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Lars Gullik Bjønnes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef FILE_INFO_H
|
||||
#define FILE_INFO_H
|
||||
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
/** Use objects of this class to get information about files.
|
||||
*
|
||||
* Users must make sure to check fi.isOK() before any operations
|
||||
* requiring the file to exist such as fi.isDir()
|
||||
*/
|
||||
class FileInfo : boost::noncopyable {
|
||||
public:
|
||||
///
|
||||
FileInfo();
|
||||
|
||||
/** Get information about file.
|
||||
If link is true, the information is about the link itself, not
|
||||
the file that is obtained by tracing the links. */
|
||||
explicit FileInfo(std::string const & path, bool link = false);
|
||||
|
||||
/// File descriptor
|
||||
explicit FileInfo(int fildes);
|
||||
|
||||
/// Query a new file
|
||||
FileInfo & newFile(std::string const & path, bool link = false);
|
||||
|
||||
/// Query a new file descriptor
|
||||
FileInfo & newFile(int fildes);
|
||||
|
||||
/// Returns a character describing file type (ls -F)
|
||||
char typeIndicator() const;
|
||||
|
||||
/// File protection mode
|
||||
mode_t getMode() const;
|
||||
|
||||
/// Constructs standard mode string (ls style)
|
||||
std::string modeString() const;
|
||||
|
||||
///
|
||||
time_t getModificationTime() const;
|
||||
|
||||
///
|
||||
time_t getAccessTime() const;
|
||||
|
||||
///
|
||||
time_t getStatusChangeTime() const;
|
||||
|
||||
/// Total file size in bytes
|
||||
off_t getSize() const;
|
||||
|
||||
/// User ID of owner
|
||||
uid_t getUid() const;
|
||||
|
||||
/// Group ID of owner
|
||||
gid_t getGid() const;
|
||||
|
||||
/// Is the file information correct? Did the query succeed?
|
||||
bool isOK() const;
|
||||
|
||||
/// Permission flags
|
||||
enum perm_test {
|
||||
/// test for read permission
|
||||
rperm = R_OK,
|
||||
/// test for write permission
|
||||
wperm = W_OK,
|
||||
/// test for execute (search) permission
|
||||
xperm = X_OK,
|
||||
/// test for existence of file
|
||||
eperm = F_OK
|
||||
};
|
||||
/// Test whether the current user has a given set of permissions
|
||||
bool access(int p) const;
|
||||
/// Is the file writable for the current user?
|
||||
bool writable() const { return access(FileInfo::wperm); }
|
||||
/// Is the file readable for the current user?
|
||||
bool readable() const { return access(FileInfo::rperm); }
|
||||
/// Is the file executable for the current user?
|
||||
bool executable() const { return access(FileInfo::xperm); }
|
||||
/// Does the file exist?
|
||||
bool exist() const { return access(FileInfo::eperm); }
|
||||
///
|
||||
bool isLink() const;
|
||||
///
|
||||
bool isRegular() const;
|
||||
///
|
||||
bool isDir() const;
|
||||
///
|
||||
bool isChar() const;
|
||||
///
|
||||
bool isBlock() const;
|
||||
///
|
||||
bool isFifo() const;
|
||||
///
|
||||
bool isSocket() const;
|
||||
///
|
||||
int getError() const;
|
||||
///
|
||||
enum Err {
|
||||
///
|
||||
NoErr = -1
|
||||
};
|
||||
private:
|
||||
///
|
||||
void init();
|
||||
///
|
||||
void dostat(bool);
|
||||
|
||||
///
|
||||
struct stat buf_;
|
||||
///
|
||||
int status_;
|
||||
///
|
||||
int err_;
|
||||
///
|
||||
std::string fname_;
|
||||
};
|
||||
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
@ -11,18 +11,19 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "support/FileMonitor.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/lyxlib.h"
|
||||
|
||||
// FIXME Interface violation
|
||||
#include "frontends/Timeout.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/signals/trackable.hpp>
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
@ -90,11 +91,10 @@ void FileMonitor::start() const
|
||||
if (monitoring())
|
||||
return;
|
||||
|
||||
FileInfo finfo(pimpl_->filename_);
|
||||
if (!finfo.isOK())
|
||||
if (!fs::exists(pimpl_->filename_))
|
||||
return;
|
||||
|
||||
pimpl_->timestamp_ = finfo.getModificationTime();
|
||||
pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename_);
|
||||
pimpl_->checksum_ = sum(pimpl_->filename_);
|
||||
|
||||
if (pimpl_->timestamp_ && pimpl_->checksum_) {
|
||||
@ -156,14 +156,13 @@ void FileMonitor::Impl::monitorFile()
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
FileInfo finfo(filename_);
|
||||
if (!finfo.isOK()) {
|
||||
if (!fs::exists(filename_)) {
|
||||
changed = timestamp_ || checksum_;
|
||||
timestamp_ = 0;
|
||||
checksum_ = 0;
|
||||
|
||||
} else {
|
||||
time_t const new_timestamp = finfo.getModificationTime();
|
||||
time_t const new_timestamp = fs::last_write_time(filename_);
|
||||
|
||||
if (new_timestamp != timestamp_) {
|
||||
timestamp_ = new_timestamp;
|
||||
|
@ -17,8 +17,6 @@ BUILT_SOURCES = package.C
|
||||
AM_CPPFLAGS = $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
|
||||
|
||||
libsupport_la_SOURCES = \
|
||||
FileInfo.C \
|
||||
FileInfo.h \
|
||||
FileMonitor.h \
|
||||
FileMonitor.C \
|
||||
abort.C \
|
||||
@ -41,6 +39,8 @@ libsupport_la_SOURCES = \
|
||||
forkedcallqueue.h \
|
||||
forkedcontr.C \
|
||||
forkedcontr.h \
|
||||
fs_extras.C \
|
||||
fs_extras.h \
|
||||
getcwd.C \
|
||||
globbing.C \
|
||||
globbing.h \
|
||||
|
@ -25,8 +25,8 @@
|
||||
#include "support/systemcall.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/forkedcontr.h"
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/package.h"
|
||||
#include "support/path.h"
|
||||
#include "support/lyxlib.h"
|
||||
@ -37,6 +37,7 @@
|
||||
#include "debug.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
@ -51,25 +52,6 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
// Which part of this is still necessary? (JMarc).
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||
#else
|
||||
# define dirent direct
|
||||
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CXX_GLOBAL_CSTD
|
||||
using std::fgetc;
|
||||
using std::isalnum;
|
||||
@ -84,6 +66,7 @@ using std::ifstream;
|
||||
using std::ostringstream;
|
||||
using std::vector;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
@ -135,24 +118,7 @@ string const QuoteName(string const & name)
|
||||
// Is a file readable ?
|
||||
bool IsFileReadable(string const & path)
|
||||
{
|
||||
FileInfo file(path);
|
||||
return file.isOK() && file.isRegular() && file.readable();
|
||||
}
|
||||
|
||||
|
||||
// Is a file read_only?
|
||||
// return 1 read-write
|
||||
// 0 read_only
|
||||
// -1 error (doesn't exist, no access, anything else)
|
||||
int IsFileWriteable(string const & path)
|
||||
{
|
||||
FileInfo fi(path);
|
||||
|
||||
if (fi.access(FileInfo::wperm|FileInfo::rperm)) // read-write
|
||||
return 1;
|
||||
if (fi.readable()) // read-only
|
||||
return 0;
|
||||
return -1; // everything else.
|
||||
return fs::exists(path) && !fs::is_directory(path) && fs::is_readable(path);
|
||||
}
|
||||
|
||||
|
||||
@ -217,51 +183,30 @@ string const FileOpenSearch(string const & path, string const & name,
|
||||
/// Returns a vector of all files in directory dir having extension ext.
|
||||
vector<string> const DirList(string const & dir, string const & ext)
|
||||
{
|
||||
// This is a non-error checking C/system implementation
|
||||
string extension;
|
||||
if (!ext.empty() && ext[0] != '.')
|
||||
extension += '.';
|
||||
extension += ext;
|
||||
|
||||
// EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
|
||||
vector<string> dirlist;
|
||||
DIR * dirp = ::opendir(dir.c_str());
|
||||
if (!dirp) {
|
||||
|
||||
if (!(fs::exists(dir) && fs::is_directory(dir))) {
|
||||
lyxerr[Debug::FILES]
|
||||
<< "Directory \"" << dir
|
||||
<< "\" does not exist to DirList." << endl;
|
||||
return dirlist;
|
||||
}
|
||||
|
||||
dirent * dire;
|
||||
while ((dire = ::readdir(dirp))) {
|
||||
string const fil = dire->d_name;
|
||||
string extension;
|
||||
if (!ext.empty() && ext[0] != '.')
|
||||
extension += '.';
|
||||
extension += ext;
|
||||
|
||||
fs::directory_iterator dit(dir);
|
||||
fs::directory_iterator end;
|
||||
for (; dit != end; ++dit) {
|
||||
string const & fil = dit->leaf();
|
||||
if (suffixIs(fil, extension)) {
|
||||
dirlist.push_back(fil);
|
||||
}
|
||||
}
|
||||
::closedir(dirp);
|
||||
return dirlist;
|
||||
/* I would have prefered to take a vector<string>& as parameter so
|
||||
that we could avoid the copy of the vector when returning.
|
||||
Then we would use:
|
||||
dirlist.swap(argvec);
|
||||
to avoid the copy. (Lgb)
|
||||
*/
|
||||
/* A C++ implementaion will look like this:
|
||||
string extension(ext);
|
||||
if (extension[0] != '.') extension.insert(0, 1, '.');
|
||||
vector<string> dirlist;
|
||||
directory_iterator dit("dir");
|
||||
while (dit != directory_iterator()) {
|
||||
string fil = dit->filename;
|
||||
if (prefixIs(fil, extension)) {
|
||||
dirlist.push_back(fil);
|
||||
}
|
||||
++dit;
|
||||
}
|
||||
dirlist.swap(argvec);
|
||||
return;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@ -498,55 +443,6 @@ bool putEnv(string const & envstr)
|
||||
|
||||
namespace {
|
||||
|
||||
int DeleteAllFilesInDir(string const & path)
|
||||
{
|
||||
// I have decided that we will be using parts from the boost
|
||||
// library. Check out http://www.boost.org/
|
||||
// For directory access we will then use the directory_iterator.
|
||||
// Then the code will be something like:
|
||||
// directory_iterator dit(path);
|
||||
// directory_iterator dend;
|
||||
// if (dit == dend) {
|
||||
// return -1;
|
||||
// }
|
||||
// for (; dit != dend; ++dit) {
|
||||
// string filename(*dit);
|
||||
// if (filename == "." || filename == "..")
|
||||
// continue;
|
||||
// string unlinkpath(AddName(path, filename));
|
||||
// lyx::unlink(unlinkpath);
|
||||
// }
|
||||
// return 0;
|
||||
DIR * dir = ::opendir(path.c_str());
|
||||
if (!dir)
|
||||
return -1;
|
||||
|
||||
struct dirent * de;
|
||||
int return_value = 0;
|
||||
while ((de = readdir(dir))) {
|
||||
string const temp = de->d_name;
|
||||
if (temp == "." || temp == "..")
|
||||
continue;
|
||||
string const unlinkpath = AddName (path, temp);
|
||||
|
||||
lyxerr[Debug::FILES] << "Deleting file: " << unlinkpath
|
||||
<< endl;
|
||||
|
||||
bool deleted = true;
|
||||
FileInfo fi(unlinkpath);
|
||||
if (fi.isOK() && fi.isDir()) {
|
||||
deleted = (DeleteAllFilesInDir(unlinkpath) == 0);
|
||||
deleted &= (rmdir(unlinkpath) == 0);
|
||||
} else
|
||||
deleted &= (unlink(unlinkpath) == 0);
|
||||
if (!deleted)
|
||||
return_value = -1;
|
||||
}
|
||||
closedir(dir);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
string const createTmpDir(string const & tempdir, string const & mask)
|
||||
{
|
||||
lyxerr[Debug::FILES]
|
||||
@ -572,18 +468,13 @@ string const createTmpDir(string const & tempdir, string const & mask)
|
||||
} // namespace anon
|
||||
|
||||
|
||||
int destroyDir(string const & tmpdir)
|
||||
bool destroyDir(string const & tmpdir)
|
||||
{
|
||||
|
||||
#ifdef __EMX__
|
||||
Path p(user_lyxdir());
|
||||
#endif
|
||||
if (DeleteAllFilesInDir(tmpdir))
|
||||
return -1;
|
||||
|
||||
if (rmdir(tmpdir))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return fs::remove_all(tmpdir) > 0;
|
||||
}
|
||||
|
||||
|
||||
@ -844,8 +735,7 @@ string const NormalizePath(string const & path)
|
||||
|
||||
string const GetFileContents(string const & fname)
|
||||
{
|
||||
FileInfo finfo(fname);
|
||||
if (finfo.exist()) {
|
||||
if (fs::exists(fname)) {
|
||||
ifstream ifs(fname.c_str());
|
||||
ostringstream ofs;
|
||||
if (ifs && ofs) {
|
||||
@ -1319,7 +1209,7 @@ string const findtexfile(string const & fil, string const & /*format*/)
|
||||
|
||||
// If the file can be found directly, we just return a
|
||||
// absolute path version of it.
|
||||
if (FileInfo(fil).exist())
|
||||
if (fs::exists(fil))
|
||||
return MakeAbsPath(fil);
|
||||
|
||||
// No we try to find it using kpsewhich.
|
||||
@ -1362,8 +1252,7 @@ void removeAutosaveFile(string const & filename)
|
||||
a += '#';
|
||||
a += OnlyFilename(filename);
|
||||
a += '#';
|
||||
FileInfo const fileinfo(a);
|
||||
if (fileinfo.exist())
|
||||
if (fs::exists(a))
|
||||
unlink(a);
|
||||
}
|
||||
|
||||
@ -1421,19 +1310,17 @@ int compare_timestamps(string const & file1, string const & file2)
|
||||
|
||||
// If the original is newer than the copy, then copy the original
|
||||
// to the new directory.
|
||||
FileInfo f1(file1);
|
||||
FileInfo f2(file2);
|
||||
|
||||
int cmp = 0;
|
||||
if (f1.exist() && f2.exist()) {
|
||||
double const tmp = difftime(f1.getModificationTime(),
|
||||
f2.getModificationTime());
|
||||
if (fs::exists(file1) && fs::exists(file2)) {
|
||||
double const tmp = difftime(fs::last_write_time(file1),
|
||||
fs::last_write_time(file2));
|
||||
if (tmp != 0)
|
||||
cmp = tmp > 0 ? 1 : -1;
|
||||
|
||||
} else if (f1.exist()) {
|
||||
} else if (fs::exists(file1)) {
|
||||
cmp = 1;
|
||||
} else if (f2.exist()) {
|
||||
} else if (fs::exists(file2)) {
|
||||
cmp = -1;
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
/// remove directory and all contents, returns 0 on success
|
||||
int destroyDir(std::string const & tmpdir);
|
||||
/// remove directory and all contents, returns true on success
|
||||
bool destroyDir(std::string const & tmpdir);
|
||||
|
||||
/// Creates the per buffer temporary directory
|
||||
std::string const createBufferTmpDir();
|
||||
@ -70,14 +70,6 @@ bool IsDirWriteable (std::string const & path);
|
||||
*/
|
||||
bool IsFileReadable (std::string const & path);
|
||||
|
||||
/** Is file read only?
|
||||
returns
|
||||
1: read-write
|
||||
0: read_only
|
||||
-1: error (doesn't exist, no access, anything else)
|
||||
*/
|
||||
int IsFileWriteable (std::string const & path);
|
||||
|
||||
///
|
||||
bool IsLyXFilename(std::string const & filename);
|
||||
|
||||
|
123
src/support/fs_extras.C
Normal file
123
src/support/fs_extras.C
Normal file
@ -0,0 +1,123 @@
|
||||
// -*- C++ -*-
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "fs_extras.h"
|
||||
|
||||
#include <boost/filesystem/config.hpp>
|
||||
#include <boost/filesystem/exception.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
// BOOST_POSIX or BOOST_WINDOWS specify which API to use.
|
||||
# if !defined( BOOST_WINDOWS ) && !defined( BOOST_POSIX )
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
|
||||
# define BOOST_WINDOWS
|
||||
# else
|
||||
# define BOOST_POSIX
|
||||
# endif
|
||||
# endif
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
|
||||
bool is_readable(path const & ph)
|
||||
{
|
||||
#ifdef BOOST_POSIX
|
||||
return ::access(ph.string().c_str(), R_OK) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool is_writable(path const & ph)
|
||||
{
|
||||
#ifdef BOOST_POSIX
|
||||
return ::access(ph.string().c_str(), W_OK) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool is_readonly(path const & ph)
|
||||
{
|
||||
#ifdef BOOST_POSIX
|
||||
return is_readable(ph) && !is_writable(ph);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void copy_file(path const & source, path const & target, bool noclobber)
|
||||
{
|
||||
|
||||
#ifdef BOOST_POSIX
|
||||
int const infile = ::open(source.string().c_str(), O_RDONLY);
|
||||
if (infile == -1) {
|
||||
boost::throw_exception(
|
||||
filesystem_error(
|
||||
"boost::filesystem::copy_file",
|
||||
source, target,
|
||||
fs::detail::system_error_code()));
|
||||
}
|
||||
|
||||
struct stat source_stat;
|
||||
int const ret = ::fstat(infile, &source_stat);
|
||||
if (ret == -1) {
|
||||
::close(infile);
|
||||
boost::throw_exception(
|
||||
filesystem_error(
|
||||
"boost::filesystem::copy_file",
|
||||
source, target,
|
||||
fs::detail::system_error_code()));
|
||||
}
|
||||
|
||||
int const flags = O_WRONLY | O_CREAT | (noclobber ? O_EXCL : O_TRUNC);
|
||||
|
||||
int const outfile = ::open(target.string().c_str(), flags, source_stat.st_mode);
|
||||
if (outfile == -1) {
|
||||
::close(infile);
|
||||
boost::throw_exception(
|
||||
filesystem_error(
|
||||
"boost::filesystem::copy_file",
|
||||
source, target,
|
||||
fs::detail::system_error_code()));
|
||||
}
|
||||
|
||||
std::size_t const buf_sz = 32768;
|
||||
char buf[buf_sz];
|
||||
ssize_t in = -1;
|
||||
ssize_t out = -1;
|
||||
|
||||
while (true) {
|
||||
in = ::read(infile, buf, buf_sz);
|
||||
if (in == -1) {
|
||||
break;
|
||||
} else if (in == 0) {
|
||||
break;
|
||||
} else {
|
||||
out = ::write(outfile, buf, in);
|
||||
if (out == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::close(infile);
|
||||
::close(outfile);
|
||||
|
||||
if (in == -1 || out == -1)
|
||||
boost::throw_exception(
|
||||
filesystem_error(
|
||||
"boost::filesystem::copy_file",
|
||||
source, target,
|
||||
fs::detail::system_error_code()));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
17
src/support/fs_extras.h
Normal file
17
src/support/fs_extras.h
Normal file
@ -0,0 +1,17 @@
|
||||
// -*- C++ -*-
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
|
||||
bool is_readable(path const & ph);
|
||||
|
||||
bool is_writable(path const & ph);
|
||||
|
||||
bool is_readonly(path const & ph);
|
||||
|
||||
void copy_file(path const & source, path const & target, bool noclobber);
|
||||
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@
|
||||
#include "debug.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/os.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include <list>
|
||||
@ -51,6 +51,7 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
@ -257,8 +258,7 @@ std::pair<string, string> const get_build_dirs(string const & abs_binary)
|
||||
|
||||
// Check whether binary is a symbolic link.
|
||||
// If so, resolve it and repeat the exercise.
|
||||
FileInfo const file(binary, true);
|
||||
if (!file.isOK() || !file.isLink())
|
||||
if (!fs::symbolic_link_exists(binary))
|
||||
break;
|
||||
|
||||
string link;
|
||||
@ -317,14 +317,12 @@ string const get_locale_dir(string const & system_support_dir)
|
||||
// be "../locale/".)
|
||||
path = NormalizePath(AddPath(system_support_dir, relative_locale_dir()));
|
||||
|
||||
FileInfo fi(path);
|
||||
if (fi.isOK() && fi.isDir())
|
||||
if (fs::exists(path) && fs::is_directory(path))
|
||||
return path;
|
||||
|
||||
// 3. Fall back to the hard-coded LOCALEDIR.
|
||||
path = hardcoded_localedir();
|
||||
FileInfo fi2(path);
|
||||
if (fi2.isOK() && fi2.isDir())
|
||||
if (fs::exists(path) && fs::is_directory(path))
|
||||
return path;
|
||||
|
||||
return string();
|
||||
@ -378,7 +376,7 @@ string const get_binary_path(string const & exe)
|
||||
// Two possibilities present themselves.
|
||||
// 1. The binary is relative to the CWD.
|
||||
string const abs_exe_path = MakeAbsPath(exe_path);
|
||||
if (FileInfo(abs_exe_path, true).isOK())
|
||||
if (fs::exists(abs_exe_path))
|
||||
return abs_exe_path;
|
||||
|
||||
// 2. exe must be the name of the binary only and it
|
||||
@ -395,7 +393,7 @@ string const get_binary_path(string const & exe)
|
||||
string const exe_dir = MakeAbsPath(*it);
|
||||
|
||||
string const exe_path = AddName(exe_dir, exe_name);
|
||||
if (FileInfo(exe_path, true).isOK())
|
||||
if (fs::exists(exe_path))
|
||||
return exe_path;
|
||||
}
|
||||
|
||||
@ -473,8 +471,7 @@ get_system_support_dir(string const & abs_binary,
|
||||
|
||||
// Check whether binary is a symbolic link.
|
||||
// If so, resolve it and repeat the exercise.
|
||||
FileInfo const file(binary, true);
|
||||
if (!file.isOK() || !file.isLink())
|
||||
if (!fs::symbolic_link_exists(binary))
|
||||
break;
|
||||
|
||||
string link;
|
||||
@ -492,8 +489,7 @@ get_system_support_dir(string const & abs_binary,
|
||||
// This time test whether the directory is a symbolic link
|
||||
// *before* looking for "chkconfig.ltx".
|
||||
// (We've looked relative to the original already.)
|
||||
FileInfo const file(binary_dir, true);
|
||||
if (!file.isOK() || !file.isLink())
|
||||
if (!fs::symbolic_link_exists(binary))
|
||||
break;
|
||||
|
||||
string link;
|
||||
@ -657,8 +653,7 @@ bool check_env_var_dir(string const & dir,
|
||||
bool check_env_var_dir(string const & dir,
|
||||
string const & env_var)
|
||||
{
|
||||
FileInfo fi(dir);
|
||||
bool const success = (fi.isOK() && fi.isDir());
|
||||
bool const success = (fs::exists(dir) && fs::is_directory(dir));
|
||||
|
||||
if (!success) {
|
||||
// Put this string on a single line so that the gettext
|
||||
|
@ -4,3 +4,5 @@ Makefile.in
|
||||
.libs
|
||||
convert
|
||||
lstrings
|
||||
pch.h.gch
|
||||
pch.h.gch.dep
|
||||
|
@ -1,3 +1,10 @@
|
||||
2005-01-31 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* tex2lyx.C: rewrite to use boost.filesystem
|
||||
* text.C: ditto
|
||||
|
||||
* Makefile.am (BOOST_LIBS): add BOOST_FILESYSTEM
|
||||
|
||||
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* Spacing (set): take double instead of float
|
||||
|
@ -15,6 +15,8 @@ bin_PROGRAMS = tex2lyx
|
||||
|
||||
AM_CPPFLAGS = $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
|
||||
|
||||
BOOST_LIBS = $(BOOST_REGEX) $(BOOST_FILESYSTEM)
|
||||
|
||||
BUILT_SOURCES = \
|
||||
FloatList.C \
|
||||
Floating.C \
|
||||
@ -48,7 +50,7 @@ tex2lyx_SOURCES = \
|
||||
|
||||
tex2lyx_LDADD = \
|
||||
$(top_builddir)/src/support/libsupport.la \
|
||||
$(BOOST_REGEX) -lz
|
||||
$(BOOST_LIBS) -lz
|
||||
|
||||
$(BUILT_SOURCES) :
|
||||
@rm -f $@ ; \
|
||||
|
@ -20,12 +20,14 @@
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/os.h"
|
||||
#include "support/package.h"
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <fstream>
|
||||
@ -53,7 +55,9 @@ using lyx::support::isStrUnsignedInt;
|
||||
using lyx::support::ltrim;
|
||||
using lyx::support::rtrim;
|
||||
using lyx::support::IsFileReadable;
|
||||
using lyx::support::IsFileWriteable;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
|
||||
// Hacks to allow the thing to link in the lyxlayout stuff
|
||||
LyXErr lyxerr(std::cerr.rdbuf());
|
||||
@ -358,7 +362,7 @@ void tex2lyx(std::istream &is, std::ostream &os)
|
||||
|
||||
bool tex2lyx(string const &infilename, string const &outfilename)
|
||||
{
|
||||
if (!(IsFileReadable(infilename) && IsFileWriteable(outfilename))) {
|
||||
if (!(IsFileReadable(infilename) && fs::is_writable(outfilename))) {
|
||||
return false;
|
||||
}
|
||||
if (!overwrite_files && IsFileReadable(outfilename)) {
|
||||
|
@ -17,11 +17,11 @@
|
||||
#include "context.h"
|
||||
#include "FloatList.h"
|
||||
#include "lengthcommon.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/convert.h"
|
||||
#include "support/filetools.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include <iostream>
|
||||
@ -29,7 +29,6 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::MakeAbsPath;
|
||||
using lyx::support::rtrim;
|
||||
using lyx::support::suffixIs;
|
||||
@ -46,6 +45,8 @@ using std::istringstream;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
|
||||
/// thin wrapper around parse_text using a string
|
||||
string parse_text(Parser & p, unsigned flags, const bool outer,
|
||||
@ -316,7 +317,7 @@ string find_file(string const & name, string const & path,
|
||||
// We don't use ChangeExtension() because it does the wrong
|
||||
// thing if name contains a dot.
|
||||
string const trial = name + '.' + (*what);
|
||||
if (FileInfo(MakeAbsPath(trial, path)).exist())
|
||||
if (fs::exists(MakeAbsPath(trial, path)))
|
||||
return trial;
|
||||
}
|
||||
return string();
|
||||
@ -1162,7 +1163,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
string const path = getMasterFilePath();
|
||||
// We want to preserve relative / absolute filenames,
|
||||
// therefore path is only used for testing
|
||||
if (!FileInfo(MakeAbsPath(name, path)).exist()) {
|
||||
if (!fs::exists(MakeAbsPath(name, path))) {
|
||||
// The file extension is probably missing.
|
||||
// Now try to find it out.
|
||||
string const dvips_name =
|
||||
@ -1191,7 +1192,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
} else if (!pdftex_name.empty())
|
||||
name = pdftex_name;
|
||||
|
||||
if (!FileInfo(MakeAbsPath(name, path)).exist())
|
||||
if (!fs::exists(MakeAbsPath(name, path)))
|
||||
cerr << "Warning: Could not find graphics file '"
|
||||
<< name << "'." << endl;
|
||||
}
|
||||
|
@ -14,12 +14,13 @@
|
||||
#include "debug.h"
|
||||
#include "buffer.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/path.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/systemcall.h"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <fstream>
|
||||
@ -27,7 +28,6 @@
|
||||
using lyx::support::AddName;
|
||||
using lyx::support::AddPath;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::OnlyFilename;
|
||||
using lyx::support::OnlyPath;
|
||||
using lyx::support::Path;
|
||||
@ -49,6 +49,8 @@ using std::getline;
|
||||
using std::string;
|
||||
using std::ifstream;
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
|
||||
int VCS::doVCCommand(string const & cmd, string const & path)
|
||||
{
|
||||
@ -72,10 +74,9 @@ string const RCS::find_file(string const & file)
|
||||
string tmp(file);
|
||||
// Check if *,v exists.
|
||||
tmp += ",v";
|
||||
FileInfo f;
|
||||
lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
|
||||
<< tmp << endl;
|
||||
if (f.newFile(tmp).readable()) {
|
||||
if (fs::is_readable(tmp)) {
|
||||
lyxerr[Debug::LYXVC] << "Yes " << file
|
||||
<< " is under rcs." << endl;
|
||||
return tmp;
|
||||
@ -85,7 +86,7 @@ string const RCS::find_file(string const & file)
|
||||
tmp += ",v";
|
||||
lyxerr[Debug::LYXVC] << "Checking if file is under rcs: "
|
||||
<< tmp << endl;
|
||||
if (f.newFile(tmp).readable()) {
|
||||
if (fs::is_readable(tmp)) {
|
||||
lyxerr[Debug::LYXVC] << "Yes " << file
|
||||
<< " it is under rcs."<< endl;
|
||||
return tmp;
|
||||
@ -239,8 +240,7 @@ string const CVS::find_file(string const & file)
|
||||
string const tmpf = "/" + OnlyFilename(file) + "/";
|
||||
lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
|
||||
<< "' for `" << tmpf << '\'' << endl;
|
||||
FileInfo const f(dir);
|
||||
if (f.readable()) {
|
||||
if (fs::is_readable(dir)) {
|
||||
// Ok we are at least in a CVS dir. Parse the CVS/Entries
|
||||
// and see if we can find this file. We do a fast and
|
||||
// dirty parse here.
|
||||
@ -280,9 +280,8 @@ void CVS::scanMaster()
|
||||
|
||||
//sm[4]; // options
|
||||
//sm[5]; // tag or tagdate
|
||||
FileInfo fi(file_);
|
||||
// FIXME: must double check file is stattable/existing
|
||||
time_t mod = fi.getModificationTime();
|
||||
time_t mod = fs::last_write_time(file_);
|
||||
string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
|
||||
lyxerr[Debug::LYXVC]
|
||||
<< "Date in Entries: `" << file_date
|
||||
|
Loading…
Reference in New Issue
Block a user