#include <QDir>
-#include <boost/assert.hpp>
+#include "support/lassert.h"
#include <boost/regex.hpp>
#include <fcntl.h>
LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
<< "createTmpDir: mask=`" << mask << '\'');
- FileName const tmpfl = FileName::tempName(tempdir.absFilename()
- + "/" + mask);
- // FileName::tempName actually creates a file to make sure that it
- // stays unique. So we have to delete it before we can create
- // a dir with the same name. Note also that we are not thread
- // safe because of the gap between unlink and mkdir. (Lgb)
- tmpfl.removeFile();
+ FileName const tmpfl = FileName::tempName(tempdir, mask);
if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
- lyxerr << "LyX could not create the temporary directory '"
- << tmpfl << "'" << endl;
+ LYXERR0("LyX could not create temporary directory in " << tempdir
+ << "'");
return FileName();
}
FileName const createLyXTmpDir(FileName const & deflt)
{
- if (deflt.empty() || deflt.absFilename() == "/tmp")
- return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
+ if (deflt.empty() || deflt == package().system_temp_dir())
+ return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
if (deflt.createDirectory(0777))
return deflt;
return createTmpDir(deflt, "lyx_tmpdir");
} else {
// some other error occured.
- return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
+ return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
}
}
string rTemp = tempRel;
string temp;
+ // Check for a leading "~"
+ // Split by first /
+ rTemp = split(rTemp, temp, '/');
+ if (temp == "~") {
+ tempBase = package().home_dir().absFilename();
+ tempRel = rTemp;
+ }
+
+ rTemp = tempRel;
while (!rTemp.empty()) {
// Split by next /
rTemp = split(rTemp, temp, '/');
if (temp == ".") continue;
if (temp == "..") {
// Remove one level of TempBase
- string::difference_type i = tempBase.length() - 2;
- if (i < 0)
- i = 0;
+ if (tempBase.length() <= 1) {
+ //this is supposed to be an absolute path, so...
+ tempBase = "/";
+ continue;
+ }
+ //erase a trailing slash if there is one
+ if (suffixIs(tempBase, "/"))
+ tempBase.erase(tempBase.length() - 1, string::npos);
+
+ string::size_type i = tempBase.length() - 1;
while (i > 0 && tempBase[i] != '/')
--i;
if (i > 0)
tempBase.erase(i, string::npos);
else
- tempBase += '/';
+ tempBase = '/';
} else if (temp.empty() && !rTemp.empty()) {
tempBase = os::current_root() + rTemp;
rTemp.erase();
string const ext = getExtension(zipped_file);
if (ext == "gz" || ext == "z" || ext == "Z")
return changeExtension(zipped_file, string());
- return "unzipped_" + zipped_file;
+ return onlyPath(zipped_file) + "unzipped_" + onlyFilename(zipped_file);
}
if (absfile.exists())
return absfile;
- // No we try to find it using kpsewhich.
+ // Now we try to find it using kpsewhich.
// It seems from the kpsewhich manual page that it is safe to use
// kpsewhich without --format: "When the --format option is not
// given, the search path used when looking for a file is inferred