Jean-Marc,
we decided recently that if LyX failed to create a temp directory then it
should inform the user and exit. Looking at the code, I see that's exactly
what the 1.4.x code base does. The 1.3.x code, however, is a little
different because of the existence of the LyXRC::use_temp_dir boolean.
Nonetheless, the current 1.3.x code tries unconditionally to create a
'lyx-level' temp directory /tmp/lyx_tmpdirXXX/ in lyx_main.C's init
function. Whether this directory is used or not then depends on
LyXRC::use_temp_dir which is checked in the Buffer constructor before any
attempt is made to create a lyx_tmpbuf subdirectory.
Having looked at all this code, I've come to the conclusion that we should
do exactly what LyX 1.4.x does. That is, exit LyX if we fail to create
the /tmp/lyx_tmpdirXXX/ directory. We need this thing for the weird case
when a user starts off with LyXRC::use_temp_dir = false but then changes
it to true and then opens a new buffer.
One final point. The 1.3.x and 1.4.x implementations of CreateLyXTmpDir
differ in that the 1.4.x version has an extra
if (IsDirWriteable(deflt))
check. Actually, I fail to see the reason for this extra check. Shouldn't
mkdir fail if it's unable to set the permissions correctly? Nonetheless,
should I backport this change to the 1.3.x tree?
Summary: I'm proposing the attached patch for inclusion in the 1.3.x. tree.
--
Angus
Index: src/lyx_main.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_main.C,v
retrieving revision 1.134.2.10
diff -u -p -r1.134.2.10 lyx_main.C
--- src/lyx_main.C 13 Jan 2005 10:09:46 -0000 1.134.2.10
+++ src/lyx_main.C 16 Jan 2005 17:08:58 -0000
@@ -321,6 +321,31 @@ void LyX::init(bool gui)
package.document_dir() = lyxrc.document_path;
package.temp_dir() = CreateLyXTmpDir(lyxrc.tempdir_path);
+ if (package.temp_dir().empty()) {
+#if USE_BOOST_FORMAT
+ using boost::format;
+ string const message =
+ format(_("Could not create a temporary directory in\n"
+ "%1$s. Make sure that this\n"
+ "path exists and is writable and try again."))
+ % lyxrc.tempdir_path;
+#else
+ string const message =
+ _("Could not create a temporary directory in\n") +
+ lyxrc.tempdir_path +
+ _(". Make sure that this\n"
+ "path exists and is writable and try again.");
+#endif
+
+ Alert::alert(_("Could not create temporary directory"), message);
+ // createLyXTmpDir() tries sufficiently hard to create a
+ // usable temp dir, so the probability to come here is
+ // close to zero. We therefore don't try to overcome this
+ // problem with e.g. asking the user for a new path and
+ // trying again but simply exit.
+ exit(EXIT_FAILURE);
+ }
+
if (lyxerr.debugging(Debug::INIT)) {
lyxerr << "LyX tmp dir: `" << package.temp_dir() << '\''
<< endl;
Index: src/support/filetools.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v
retrieving revision 1.146.2.12
diff -u -p -r1.146.2.12 filetools.C
--- src/support/filetools.C 13 Jan 2005 10:09:46 -0000 1.146.2.12
+++ src/support/filetools.C 16 Jan 2005 17:08:59 -0000
@@ -576,14 +576,22 @@ int DestroyBufferTmpDir(string const & t
}
-string const CreateLyXTmpDir(string const & deflt)
+string const createLyXTmpDir(string const & deflt)
{
- if ((!deflt.empty()) && (deflt != "/tmp")) {
+ if (!deflt.empty() && deflt != "/tmp") {
if (lyx::mkdir(deflt, 0777)) {
#ifdef __EMX__
- Path p(lyx::package().user_support());
+ Path p(lyx::package().user_support());
#endif
- return CreateTmpDir(deflt, "lyx_tmpdir");
+ if (IsDirWriteable(deflt)) {
+ // 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("/tmp", "lyx_tmpdir");
+ }
} else
return deflt;
} else {