#include "support/FileFilterList.h"
#include "support/filetools.h"
#include "support/Forkedcall.h"
-#include "support/fs_extras.h"
#include "support/gzstream.h"
#include "support/lyxlib.h"
#include "support/os.h"
#endif
#include <boost/bind.hpp>
-#include <boost/filesystem/exception.hpp>
-#include <boost/filesystem/operations.hpp>
#include <boost/shared_ptr.hpp>
#include <algorithm>
namespace Alert = frontend::Alert;
namespace os = support::os;
-namespace fs = boost::filesystem;
namespace {
backupName = FileName(addName(lyxrc.backupdir_path,
mangledName));
}
- try {
- fs::copy_file(encodedFilename, backupName.toFilesystemEncoding(), false);
+ if (fileName().copyTo(backupName, false)) {
madeBackup = true;
- } catch (fs::filesystem_error const & fe) {
+ } else {
Alert::error(_("Backup failure"),
bformat(_("Cannot create backup file %1$s.\n"
"Please check whether the directory exists and is writeable."),
from_utf8(backupName.absFilename())));
- LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
+ //LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
}
}
#include <boost/filesystem/operations.hpp>
#include "support/filetools.h"
-#include "support/fs_extras.h"
#include "support/convert.h"
#include "support/lyxlib.h"
#include "support/lstrings.h"
return true;
}
// copy file
- try {
- // need to make directory?
- string path = support::onlyPath(ext_file);
- if (!fs::is_directory(path))
- makedir(const_cast<char*>(path.c_str()), 0755);
- fs::copy_file(emb_file, ext_file, false);
+
+ // need to make directory?
+ string path = support::onlyPath(ext_file);
+ if (!fs::is_directory(path))
+ makedir(const_cast<char*>(path.c_str()), 0755);
+ FileName emb(emb_file);
+ FileName ext(ext_file);
+ if (emb.copyTo(ext, false))
return true;
- } catch (fs::filesystem_error const & fe) {
- Alert::error(_("Copy file failure"),
- bformat(_("Cannot copy file %1$s to %2$s.\n"
- "Please check whether the directory exists and is writeable."),
- from_utf8(emb_file), from_utf8(ext_file)));
- LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
- }
+ Alert::error(_("Copy file failure"),
+ bformat(_("Cannot copy file %1$s to %2$s.\n"
+ "Please check whether the directory exists and is writeable."),
+ from_utf8(emb_file), from_utf8(ext_file)));
+ //LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
return false;
}
return true;
}
// copy file
- try {
- // need to make directory?
- string path = support::onlyPath(emb_file);
- if (!fs::is_directory(path))
- makedir(const_cast<char*>(path.c_str()), 0755);
- fs::copy_file(ext_file, emb_file, false);
+ FileName emb(emb_file);
+ FileName ext(ext_file);
+ // need to make directory?
+ string path = support::onlyPath(emb_file);
+ if (!fs::is_directory(path))
+ makedir(const_cast<char*>(path.c_str()), 0755);
+ if (ext.copyTo(emb, false))
return true;
- } catch (fs::filesystem_error const & fe) {
- Alert::error(_("Copy file failure"),
- bformat(_("Cannot copy file %1$s to %2$s.\n"
- "Please check whether the directory exists and is writeable."),
- from_utf8(ext_file), from_utf8(emb_file)));
- LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
- }
+ Alert::error(_("Copy file failure"),
+ bformat(_("Cannot copy file %1$s to %2$s.\n"
+ "Please check whether the directory exists and is writeable."),
+ from_utf8(ext_file), from_utf8(emb_file)));
+ //LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
return false;
}
::zipFiles(zipfile.toFilesystemEncoding(), filenames);
// copy file back
- try {
- fs::copy_file(zipfile.toFilesystemEncoding(), filename.toFilesystemEncoding(), false);
- } catch (fs::filesystem_error const & fe) {
+ if (!zipfile.copyTo(filename, false)) {
Alert::error(_("Save failure"),
bformat(_("Cannot create file %1$s.\n"
"Please check whether the directory exists and is writeable."),
from_utf8(filename.absFilename())));
- LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
+ //LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
}
return true;
}
-EmbeddedFiles::EmbeddedFileList::const_iterator EmbeddedFiles::find(std::string filename) const
+EmbeddedFiles::EmbeddedFileList::const_iterator
+EmbeddedFiles::find(std::string filename) const
{
EmbeddedFileList::const_iterator it = file_list_.begin();
EmbeddedFileList::const_iterator it_end = file_list_.end();
#include "support/environment.h"
#include "support/FileFilterList.h"
#include "support/filetools.h"
-#include "support/fs_extras.h"
#include "support/lstrings.h"
#include "support/Path.h"
#include "support/Package.h"
#include "support/Path.h"
#include "support/filetools.h"
-#include "support/fs_extras.h"
#include "support/lstrings.h"
#include "support/Systemcall.h"
#include "insets/InsetInclude.h"
#include "support/filetools.h"
-#include "support/fs_extras.h"
#include "support/lyxlib.h"
-#include <boost/bind.hpp>
-
using std::min;
using std::string;
Paragraph & prev_par = *prev_it;
depth_type const prev_depth = getDepth(prev_it);
if (labeltype == prev_par.layout()->labeltype) {
- if (prev_depth < min_depth) {
+ if (prev_depth < min_depth)
return prev_par.itemdepth + 1;
- }
- else if (prev_depth == min_depth) {
+ if (prev_depth == min_depth)
return prev_par.itemdepth;
- }
}
min_depth = std::min(min_depth, prev_depth);
// small optimization: if we are at depth 0, we won't
// find anything else
- if (prev_depth == 0) {
+ if (prev_depth == 0)
return 0;
- }
}
}
#include "FuncRequest.h"
#include "LaTeXFeatures.h"
-#include "support/fs_extras.h"
#include "support/lstrings.h"
#include <algorithm>
namespace fs = boost::filesystem;
+// FIXME: merge this
+//
+#include <boost/filesystem/config.hpp>
+#include <boost/detail/workaround.hpp>
+#include <boost/throw_exception.hpp>
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#include <cerrno>
+#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
+
+#if defined (BOOST_WINDOWS)
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
+
+static bool copy_file(std::string const & source, std::string const & target, bool noclobber)
+{
+
+#ifdef BOOST_POSIX
+ int const infile = ::open(source.c_str(), O_RDONLY);
+ if (infile == -1)
+ return false;
+
+ struct stat source_stat;
+ int const ret = ::fstat(infile, &source_stat);
+ if (ret == -1) {
+ //int err = errno;
+ ::close(infile);
+ }
+
+ int const flags = O_WRONLY | O_CREAT | (noclobber ? O_EXCL : O_TRUNC);
+
+ int const outfile = ::open(target.c_str(), flags, source_stat.st_mode);
+ if (outfile == -1) {
+ int err = errno;
+ ::close(infile);
+ return false;
+ }
+
+ 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;
+ }
+ }
+ }
+
+ int err = errno;
+
+ ::close(infile);
+ ::close(outfile);
+
+ if (in == -1 || out == -1)
+ return false;
+#endif
+
+#ifdef BOOST_WINDOWS
+ if (::CopyFile(source.c_str(), target.c_str(), noclobber) == 0) {
+ // CopyFile is probably not setting errno so this is most
+ // likely wrong.
+ return false;
+ }
+#endif
+}
+
namespace lyx {
namespace support {
}
+bool FileName::copyTo(FileName const & name, bool noclobber) const
+{
+ try {
+ copy_file(toFilesystemEncoding(), name.toFilesystemEncoding(), noclobber);
+ return true;
+ }
+ catch (...) {
+ }
+ return false;
+}
+
+
string FileName::toFilesystemEncoding() const
{
QByteArray const encoded = QFile::encodeName(toqstr(name_));
} // namespace support
} // namespace lyx
+
+
+
/// return true when file/directory is writable (write test file)
bool isDirWritable() const;
+ /// return true when file/directory is writable (write test file)
+ bool copyTo(FileName const & target, bool noclobber) const;
+
/// remove directory and all contents, returns true on success
bool destroyDirectory() const;
/// Creates directory. Returns true on success
ForkedCallQueue.h \
ForkedcallsController.cpp \
ForkedcallsController.h \
- fs_extras.cpp \
- fs_extras.h \
getcwd.cpp \
gzstream.cpp \
gzstream.h \
#include "support/convert.h"
#include "support/environment.h"
#include "support/filetools.h"
-#include "support/fs_extras.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/os.h"
FileName const createLyXTmpDir(FileName const & deflt)
{
- if (!deflt.empty() && deflt.absFilename() != "/tmp") {
- if (mkdir(deflt, 0777)) {
- if (deflt.isDirWritable()) {
- // deflt could not be created because it
- // did exist already, so let's create our own
- // dir inside deflt.
- return createTmpDir(deflt, "lyx_tmpdir");
- } else {
- // some other error occured.
- return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
- }
- } else
- return deflt;
+ if (deflt.empty() || deflt.absFilename() == "/tmp")
+ return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
+
+ if (!mkdir(deflt, 0777))
+ return deflt;
+
+ if (deflt.isDirWritable()) {
+ // deflt could not be created because it
+ // did exist already, so let's create our own
+ // dir inside deflt.
+ return createTmpDir(deflt, "lyx_tmpdir");
} else {
+ // some other error occured.
return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
}
}
return filename;
// Find last / or start of filename
- string::size_type j = filename.rfind('/');
+ size_t j = filename.rfind('/');
return j == string::npos ? "./" : filename.substr(0, j + 1);
}
+++ /dev/null
-// -*- C++ -*-
-/* \file fs_extras.cpp
- * 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 "fs_extras.h"
-
-#include <boost/filesystem/config.hpp>
-#include <boost/detail/workaround.hpp>
-#include <boost/throw_exception.hpp>
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#include <cerrno>
-#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
-
-#if defined (BOOST_WINDOWS)
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-#endif
-
-namespace fs = boost::filesystem;
-
-namespace boost {
-namespace filesystem {
-
-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_path_error(
- "boost::filesystem::copy_file",
- source, target,
- fs::lookup_errno(errno)));
- }
-
- struct stat source_stat;
- int const ret = ::fstat(infile, &source_stat);
- if (ret == -1) {
- int err = errno;
- ::close(infile);
- boost::throw_exception(filesystem_path_error(
- "boost::filesystem::copy_file",
- source, target,
- fs::lookup_errno(err)));
- }
-
- 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) {
- int err = errno;
- ::close(infile);
- boost::throw_exception(
- filesystem_path_error(
- "boost::filesystem::copy_file",
- source, target,
- fs::lookup_errno(err)));
- }
-
- 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;
- }
- }
- }
-
- int err = errno;
-
- ::close(infile);
- ::close(outfile);
-
- if (in == -1 || out == -1)
- boost::throw_exception(
- filesystem_path_error(
- "boost::filesystem::copy_file",
- source, target,
- fs::lookup_errno(err)));
-#endif
-#ifdef BOOST_WINDOWS
- if (::CopyFile(source.string().c_str(), target.string().c_str(), noclobber) == 0) {
- // CopyFile is probably not setting errno so this is most
- // likely wrong.
- boost::throw_exception(
- filesystem_path_error(
- "boost::filesystem::copy_file",
- source, target,
- fs::lookup_error_code(errno)));
- }
-#endif
-}
-
-}
-}
+++ /dev/null
-// -*- C++ -*-
-/* \file fs_extras.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.
- */
-
-#include <boost/filesystem/path.hpp>
-
-
-namespace boost {
-namespace filesystem {
-
-void copy_file(path const & source, path const & target, bool noclobber);
-
-}
-}
#include "support/convert.h"
#include "support/filetools.h"
-#include "support/fs_extras.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/ExceptionMessage.h"