FileName const to_file_base = FileName::tempName("CacheItem");
remove_loaded_file_ = true;
- // Remove the temp file, we only want the name...
- // FIXME: This is unsafe!
- to_file_base.removeFile();
-
// Connect a signal to this->imageConverted and pass this signal to
// the graphics converter so that we can load the modified file
// on completion of the conversion process.
#include <QFile>
#include <QFileInfo>
#include <QList>
+#include <QTemporaryFile>
#include <QTime>
#include "support/lassert.h"
bool FileName::isDirWritable() const
{
LYXERR(Debug::FILES, "isDirWriteable: " << *this);
-
FileName const tmpfl = FileName::tempName(absFilename() + "/lyxwritetest");
-
- if (tmpfl.empty())
- return false;
-
- tmpfl.removeFile();
- return true;
+ return !tmpfl.empty();
}
}
-static int make_tempfile(char * templ)
-{
-#if defined(HAVE_MKSTEMP)
- return ::mkstemp(templ);
-#elif defined(HAVE_MKTEMP)
- // This probably just barely works...
- ::mktemp(templ);
-# if defined (HAVE_OPEN)
-# if (!defined S_IRUSR)
-# define S_IRUSR S_IREAD
-# define S_IWUSR S_IWRITE
-# endif
- return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
-# elif defined (HAVE__OPEN)
- return ::_open(templ,
- _O_RDWR | _O_CREAT | _O_EXCL,
- _S_IREAD | _S_IWRITE);
-# else
-# error No open() function.
-# endif
-#else
-#error FIX FIX FIX
-#endif
-}
-
-
FileName FileName::tempName(string const & mask)
{
FileName tmp_name(mask);
else
tmpfl = package().temp_dir().absFilename() + "/" + mask;
-#if defined (HAVE_GETPID)
- tmpfl += convert<string>(getpid());
-#elif defined (HAVE__GETPID)
- tmpfl += convert<string>(_getpid());
-#else
-# error No getpid() function
-#endif
- tmpfl += "XXXXXX";
-
- // The supposedly safe mkstemp version
- // FIXME: why not using std::string directly?
- boost::scoped_array<char> tmpl(new char[tmpfl.length() + 1]); // + 1 for '\0'
- tmpfl.copy(tmpl.get(), string::npos);
- tmpl[tmpfl.length()] = '\0'; // terminator
-
- int const tmpf = make_tempfile(tmpl.get());
- if (tmpf != -1) {
- string const t(to_utf8(from_filesystem8bit(tmpl.get())));
-#if defined (HAVE_CLOSE)
- ::close(tmpf);
-#elif defined (HAVE__CLOSE)
- ::_close(tmpf);
-#else
-# error No x() function.
-#endif
- LYXERR(Debug::FILES, "Temporary file `" << t << "' created.");
- return FileName(t);
+ QTemporaryFile qt_tmp(toqstr(tmpfl));
+ if (qt_tmp.open()) {
+ tmp_name.d->fi.setFile(qt_tmp.fileName());
+ LYXERR(Debug::FILES, "Temporary file `" << tmp_name << "' created.");
+ return tmp_name;
}
LYXERR(Debug::FILES, "LyX Error: Unable to create temporary file.");
return FileName();
string const tmp_dir = tempdir.absFilename() + "/" + mask;
FileName const tmpfl = FileName::tempName(tmp_dir);
- // 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();
if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
LYXERR0("LyX could not create the temporary directory '" << tmp_dir