mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-21 17:51:03 +00:00
Replace home made temp file creation with safer (and cleaner) Qt' solution. Should fix http://bugzilla.lyx.org/show_bug.cgi?id=4693
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25822 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b9dd28b101
commit
8195925175
@ -422,10 +422,6 @@ void CacheItem::Impl::convertToDisplayFormat()
|
||||
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.
|
||||
|
@ -295,7 +295,6 @@ static void build_script(FileName const & from_file,
|
||||
static int counter = 0;
|
||||
string const tmp = "gconvert" + convert<string>(counter++);
|
||||
FileName const to_base = FileName::tempName(tmp);
|
||||
to_base.removeFile();
|
||||
|
||||
// Create a copy of the file in case the original name contains
|
||||
// problematic characters like ' or ". We can work around that problem
|
||||
|
@ -69,8 +69,6 @@ namespace external {
|
||||
TempName::TempName()
|
||||
{
|
||||
FileName const tempname = FileName::tempName("lyxext");
|
||||
// FIXME: This is unsafe
|
||||
tempname.removeFile();
|
||||
// must have an extension for the converter code to work correctly.
|
||||
tempname_ = FileName(tempname.absFilename() + ".tmp");
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QList>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTime>
|
||||
|
||||
#include "support/lassert.h"
|
||||
@ -308,14 +309,8 @@ bool FileName::isWritable() const
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@ -352,32 +347,6 @@ FileNameList FileName::dirList(string const & ext) const
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -387,33 +356,11 @@ FileName FileName::tempName(string const & 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();
|
||||
|
@ -323,11 +323,6 @@ static FileName createTmpDir(FileName const & tempdir, string const & mask)
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user