mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Now that exceptions are allowed, handle gracefully the case where a Buffer temp directory could not be created. As a bonus, the user will get an informative message.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22196 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
8672364e1e
commit
1447a7bf98
@ -78,7 +78,9 @@
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/ExceptionMessage.h"
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/FileNameList.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/ForkedCalls.h"
|
||||
@ -87,6 +89,7 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/os.h"
|
||||
#include "support/Package.h"
|
||||
#include "support/Path.h"
|
||||
#include "support/textutils.h"
|
||||
#include "support/types.h"
|
||||
@ -137,7 +140,7 @@ public:
|
||||
|
||||
BufferParams params;
|
||||
LyXVC lyxvc;
|
||||
string temppath;
|
||||
FileName temppath;
|
||||
mutable TexRow texrow;
|
||||
Buffer const * parent_buffer;
|
||||
|
||||
@ -198,6 +201,24 @@ public:
|
||||
mutable FileNameList bibfilesCache_;
|
||||
};
|
||||
|
||||
/// Creates the per buffer temporary directory
|
||||
static FileName createBufferTmpDir()
|
||||
{
|
||||
static int count;
|
||||
// We are in our own directory. Why bother to mangle name?
|
||||
// In fact I wrote this code to circumvent a problematic behaviour
|
||||
// (bug?) of EMX mkstemp().
|
||||
FileName tmpfl(package().temp_dir().absFilename() + "/lyx_tmpbuf" +
|
||||
convert<string>(count++));
|
||||
|
||||
if (!tmpfl.createDirectory(0777)) {
|
||||
throw ExceptionMessage(WarningException, _("Disk Error: "), bformat(
|
||||
_("LyX could not create the temporary directory '%1$s' (Disk is full maybe?)"),
|
||||
from_utf8(tmpfl.absFilename())));
|
||||
}
|
||||
return tmpfl;
|
||||
}
|
||||
|
||||
|
||||
Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
|
||||
: parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false),
|
||||
@ -205,14 +226,9 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
|
||||
inset(params), toc_backend(&parent), embedded_files(&parent),
|
||||
timestamp_(0), checksum_(0), wa_(0), undo_(parent)
|
||||
{
|
||||
temppath = createBufferTmpDir();
|
||||
inset.setAutoBreakRows(true);
|
||||
lyxvc.setBuffer(&parent);
|
||||
temppath = createBufferTmpDir();
|
||||
|
||||
// FIXME: And now do something if temppath == string(), because we
|
||||
// assume from now on that temppath points to a valid temp dir.
|
||||
// See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
|
||||
|
||||
if (use_gui)
|
||||
wa_ = new frontend::WorkAreaManager;
|
||||
}
|
||||
@ -243,10 +259,10 @@ Buffer::~Buffer()
|
||||
|
||||
resetChildDocuments(false);
|
||||
|
||||
if (!temppath().empty() && !FileName(temppath()).destroyDirectory()) {
|
||||
if (!d->temppath.destroyDirectory()) {
|
||||
Alert::warning(_("Could not remove temporary directory"),
|
||||
bformat(_("Could not remove the temporary directory %1$s"),
|
||||
from_utf8(temppath())));
|
||||
from_utf8(d->temppath.absFilename())));
|
||||
}
|
||||
|
||||
// Remove any previewed LaTeX snippets associated with this buffer.
|
||||
@ -318,9 +334,9 @@ LyXVC const & Buffer::lyxvc() const
|
||||
}
|
||||
|
||||
|
||||
string const & Buffer::temppath() const
|
||||
string const Buffer::temppath() const
|
||||
{
|
||||
return d->temppath;
|
||||
return d->temppath.absFilename();
|
||||
}
|
||||
|
||||
|
||||
|
@ -328,7 +328,7 @@ public:
|
||||
LyXVC const & lyxvc() const;
|
||||
|
||||
/// Where to put temporary files.
|
||||
std::string const & temppath() const;
|
||||
std::string const temppath() const;
|
||||
|
||||
/// Used when typesetting to place errorboxes.
|
||||
TexRow const & texrow() const;
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "support/ExceptionMessage.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/gettext.h"
|
||||
@ -93,7 +94,17 @@ void BufferList::release(Buffer * buf)
|
||||
|
||||
Buffer * BufferList::newBuffer(string const & s, bool const ronly)
|
||||
{
|
||||
auto_ptr<Buffer> tmpbuf(new Buffer(s, ronly));
|
||||
auto_ptr<Buffer> tmpbuf;
|
||||
try { tmpbuf.reset(new Buffer(s, ronly));
|
||||
} catch (ExceptionMessage const & message) {
|
||||
if (message.type_ == ErrorException) {
|
||||
Alert::error(message.title_, message.details_);
|
||||
exit(1);
|
||||
} else if (message.type_ == WarningException) {
|
||||
Alert::warning(message.title_, message.details_);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
tmpbuf->params().useClassDefaults();
|
||||
LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size());
|
||||
bstore.push_back(tmpbuf.get());
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
const_iterator end() const;
|
||||
|
||||
/// create a new buffer
|
||||
/// \return 0 if the Buffer creation is not possible for whatever reason.
|
||||
Buffer * newBuffer(std::string const & s, bool ronly = false);
|
||||
|
||||
/// delete a buffer
|
||||
|
@ -81,6 +81,9 @@ Buffer * checkAndLoadLyXFile(FileName const & filename)
|
||||
|
||||
if (filename.isReadableFile()) {
|
||||
Buffer * b = theBufferList().newBuffer(filename.absFilename());
|
||||
if (!b)
|
||||
// Buffer creation is not possible.
|
||||
return 0;
|
||||
if (!b->loadLyXFile(filename)) {
|
||||
theBufferList().release(b);
|
||||
return 0;
|
||||
@ -105,7 +108,9 @@ Buffer * newFile(string const & filename, string const & templatename,
|
||||
{
|
||||
// get a free buffer
|
||||
Buffer * b = theBufferList().newBuffer(filename);
|
||||
BOOST_ASSERT(b);
|
||||
if (!b)
|
||||
// Buffer creation is not possible.
|
||||
return 0;
|
||||
|
||||
FileName tname;
|
||||
// use defaults.lyx as a default template if it exists.
|
||||
|
@ -312,6 +312,10 @@ Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
|
||||
return 0;
|
||||
|
||||
child = theBufferList().newBuffer(included_file.absFilename());
|
||||
if (!child)
|
||||
// Buffer creation is not possible.
|
||||
return 0;
|
||||
|
||||
if (!child->loadLyXFile(included_file)) {
|
||||
//close the buffer we just opened
|
||||
theBufferList().release(child);
|
||||
|
@ -338,24 +338,6 @@ static FileName createTmpDir(FileName const & tempdir, string const & mask)
|
||||
return tmpfl;
|
||||
}
|
||||
|
||||
string const createBufferTmpDir()
|
||||
{
|
||||
static int count;
|
||||
// We are in our own directory. Why bother to mangle name?
|
||||
// In fact I wrote this code to circumvent a problematic behaviour
|
||||
// (bug?) of EMX mkstemp().
|
||||
string const tmpfl =
|
||||
package().temp_dir().absFilename() + "/lyx_tmpbuf" +
|
||||
convert<string>(count++);
|
||||
|
||||
if (!FileName(tmpfl).createDirectory(0777)) {
|
||||
lyxerr << "LyX could not create the temporary directory '"
|
||||
<< tmpfl << "'" << endl;
|
||||
return string();
|
||||
}
|
||||
return tmpfl;
|
||||
}
|
||||
|
||||
|
||||
FileName const createLyXTmpDir(FileName const & deflt)
|
||||
{
|
||||
|
@ -22,9 +22,6 @@ namespace support {
|
||||
|
||||
class FileName;
|
||||
|
||||
/// Creates the per buffer temporary directory
|
||||
std::string const createBufferTmpDir();
|
||||
|
||||
/** Creates the global LyX temp dir.
|
||||
\p deflt can be an existing directory name. In this case a new directory
|
||||
inside \p deflt is created. If \p deflt does not exist yet, \p deflt is
|
||||
|
Loading…
Reference in New Issue
Block a user