Lexer lex;
istringstream is(s);
lex.setStream(is);
- FileName const fn = FileName::tempName("Buffer_readString");
+ TempFile tempfile("Buffer_readStringXXXXXX.lyx");
+ FileName const fn = tempfile.name();
int file_format;
bool success = parseLyXFormat(lex, fn, file_format) == ReadSuccess;
else if (success)
if (readDocument(lex))
success = false;
- if (fn.exists())
- fn.removeFile();
return success;
}
Buffer::ReadStatus Buffer::convertLyXFormat(FileName const & fn,
FileName & tmpfile, int from_format)
{
- tmpfile = FileName::tempName("Buffer_convertLyXFormatXXXXXX.lyx");
+ TempFile tempfile("Buffer_convertLyXFormatXXXXXX.lyx");
+ tempfile.setAutoRemove(false);
+ tmpfile = tempfile.name();
if(tmpfile.empty()) {
Alert::error(_("Conversion failed"),
bformat(_("%1$s is from a different"
// to fork. But we will do the save
// anyway.
bool failed = false;
- FileName const tmp_ret = FileName::tempName("lyxauto");
+ TempFile tempfile("lyxautoXXXXXX.lyx");
+ tempfile.setAutoRemove(false);
+ FileName const tmp_ret = tempfile.name();
if (!tmp_ret.empty()) {
buffer_.writeFile(tmp_ret);
// assume successful write of tmp_ret
// If this buffer is cloned, we assume that
// we are running in a separate thread already.
- FileName const tmp_ret = FileName::tempName("lyxauto");
+ TempFile tempfile("lyxautoXXXXXX.lyx");
+ tempfile.setAutoRemove(false);
+ FileName const tmp_ret = tempfile.name();
if (!tmp_ret.empty()) {
writeFile(tmp_ret);
// assume successful write of tmp_ret
#include "support/lassert.h"
#include "support/limited_stack.h"
#include "support/lstrings.h"
+#include "support/TempFile.h"
#include "frontends/alert.h"
#include "frontends/Clipboard.h"
// new temporary directory, etc) every time, and then to destroy it. So maybe
// it's worth just keeping this one around.
// FIXME THREAD
+ static TempFile tempfile("clipboard.internal");
+ tempfile.setAutoRemove(false);
static Buffer * staticbuffer = theBufferList().newInternalBuffer(
- FileName::tempName("clipboard.internal").absFileName());
+ tempfile.name().absFileName());
// These two things only really need doing the first time.
staticbuffer->setUnnamed(true);
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
+#include "support/TempFile.h"
#include "frontends/alert.h"
return retval == ReadOK;
LYXERR(Debug::FILES, "Converting bind file to " << LFUN_FORMAT);
- FileName const tempfile = FileName::tempName("convert_bind");
+ TempFile tmp("convert_bind");
+ FileName const tempfile = tmp.name();
bool const success = prefs2prefs(bind_file, tempfile, true);
if (!success) {
LYXERR0 ("Unable to convert " << bind_file <<
return false;
}
retval = readWithoutConv(tempfile, unbind_map);
- tempfile.removeFile();
return retval == ReadOK;
}
#include "support/bind.h"
#include "support/regex.h"
+#include "support/TempFile.h"
#include <fstream>
LayoutFileIndex LayoutFileList::addEmptyClass(string const & textclass)
{
// FIXME This could be simplified a bit to call TextClass::read(string, ReadType).
-
- FileName const tempLayout = FileName::tempName("basic_layout");
+
+ TempFile tempfile("basicXXXXXX.layout");
+ FileName const tempLayout = tempfile.name();
ofstream ofs(tempLayout.toFilesystemEncoding().c_str());
// This writes a very basic class, but it also attempts to include
// stdclass.inc. That would give us something moderately usable.
#include "support/lstrings.h"
#include "support/os.h"
#include "support/Package.h"
+#include "support/TempFile.h"
#include "support/userinfo.h"
#include <fstream>
return retval == ReadOK;
LYXERR(Debug::FILES, "Converting LyXRC file to " << LYXRC_FILEFORMAT);
- FileName const tempfile = FileName::tempName("convert_lyxrc");
+ TempFile tmp("convert_lyxrc");
+ FileName const tempfile = tmp.name();
bool const success = prefs2prefs(filename, tempfile, false);
if (!success) {
LYXERR0 ("Unable to convert " << filename.absFileName() <<
LYXERR(Debug::LYXRC, "Reading '" << tempfile << "'...");
retval = read(lexrc2, check_format);
}
- tempfile.removeFile();
return retval == ReadOK;
}
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
+#include "support/TempFile.h"
using namespace std;
using namespace lyx::support;
if (!vcs)
return string();
- FileName const tmpf = FileName::tempName("lyxvclog");
+ TempFile tempfile("lyxvclog");
+ tempfile.setAutoRemove(false);
+ FileName const tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return string();
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/os.h"
+#include "support/TempFile.h"
#include <algorithm>
#include <fstream>
bool TextClass::convertLayoutFormat(support::FileName const & filename, ReadType rt)
{
LYXERR(Debug::TCLASS, "Converting layout file to " << LAYOUT_FORMAT);
- FileName const tempfile = FileName::tempName("convert_layout");
+ TempFile tmp("convertXXXXXX.layout");
+ FileName const tempfile = tmp.name();
bool success = layout2layout(filename, tempfile);
if (success)
success = readWithoutConv(tempfile, rt) == OK;
- tempfile.removeFile();
return success;
}
std::string TextClass::convert(std::string const & str)
{
- FileName const fn = FileName::tempName("locallayout");
+ TempFile tmp1("localXXXXXX.layout");
+ FileName const fn = tmp1.name();
ofstream os(fn.toFilesystemEncoding().c_str());
os << str;
os.close();
- FileName const tempfile = FileName::tempName("convert_locallayout");
+ TempFile tmp2("convert_localXXXXXX.layout");
+ FileName const tempfile = tmp2.name();
bool success = layout2layout(fn, tempfile);
if (!success)
return "";
ret += tmp + '\n';
}
is.close();
- tempfile.removeFile();
return ret;
}
return retval;
// write the layout string to a temporary file
- FileName const tempfile = FileName::tempName("TextClass_read");
+ TempFile tmp("TextClass_read");
+ FileName const tempfile = tmp.name();
ofstream os(tempfile.toFilesystemEncoding().c_str());
if (!os) {
LYXERR0("Unable to create temporary file");
<< LAYOUT_FORMAT);
return ERROR;
}
- tempfile.removeFile();
return OK_OLDFORMAT;
}
#include "support/PathChanger.h"
#include "support/Systemcall.h"
#include "support/regex.h"
+#include "support/TempFile.h"
#include <fstream>
// if (getDiff(file, diff) && diff.empty())
// return false;
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return true;
FileName(owner_->filePath()));
docstring diff = tmpf.fileContents("UTF-8");
- tmpf.removeFile();
if (diff.empty())
return false;
bool RCS::getRevisionInfo()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
if (!VCS::makeRCSRevision(version_, rev))
return false;
- FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
+ TempFile tempfile("lyxvcrev_" + rev + "_");
+ tempfile.setAutoRemove(false);
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
CVS::CvsStatus CVS::getStatus()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return StatusError;
if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
FileName(owner_->filePath()), tmpf)) {
- tmpf.removeFile();
return StatusError;
}
status = NeedsCheckout;
}
}
- tmpf.removeFile();
return status;
}
if (have_rev_info_)
return;
have_rev_info_ = true;
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return;
+ " " + getTarget(File),
FileName(owner_->filePath()), tmpf);
if (rc) {
- tmpf.removeFile();
LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
return;
}
break;
}
}
- tmpf.removeFile();
if (rev_author_cache_.empty())
LYXERR(Debug::LYXVC,
"Could not retrieve revision info for " << version_ <<
{
if (vcstatus != NOLOCKING && edit())
return string();
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return string();
rc = 0;
}
- tmpf.removeFile();
return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
}
string CVS::repoUpdate()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return string();
text, 0, 1, _("&Continue"), _("&Abort"));
hideDialogs("file", 0);
}
- if (ret == 1 ) {
- tmpf.removeFile();
+ if (ret == 1 )
return string();
- }
}
int rc = update(Directory, tmpf);
file, from_local8bit(sres)));
rc = 0;
}
-
- tmpf.removeFile();
return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
}
if (!VCS::makeRCSRevision(version_, rev))
return false;
- FileName tmpf = FileName::tempName("lyxvcrev_" + rev + "_");
+ TempFile tempfile("lyxvcrev_" + rev + "_");
+ tempfile.setAutoRemove(false);
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
}
// Now we check the status of the file.
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return FileName();
bool found = 0 == doVCCommandCall("svn info " + quoteName(fname)
+ " > " + quoteName(tmpf.toFilesystemEncoding()),
file.onlyPath());
- tmpf.removeFile();
LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
return found ? file : FileName();
}
bool SVN::checkLockMode()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()){
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
LyXVC::CommandResult
SVN::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()){
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
log = N_("Error: Could not generate logfile.");
if (!fileLock(false, tmpf, log))
ret = LyXVC::ErrorCommand;
- tmpf.removeFile();
if (!log.empty())
log.insert(0, "SVN: ");
if (ret == LyXVC::VCSuccess && log.empty())
{
// FIXME one day common getDiff and perhaps OpMode for all backends
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return true;
FileName(owner_->filePath()));
docstring diff = tmpf.fileContents("UTF-8");
- tmpf.removeFile();
if (diff.empty())
return false;
string SVN::checkOut()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return N_("Error: Could not generate logfile.");
fileLock(true, tmpf, log);
- tmpf.removeFile();
return log.empty() ? string() : "SVN: " + log;
}
string SVN::repoUpdate()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return N_("Error: Could not generate logfile.");
text, 0, 1, _("&Yes"), _("&No"));
hideDialogs("file", 0);
}
- if (ret == 1 ) {
- tmpf.removeFile();
+ if (ret == 1 )
return string();
- }
}
// Reverting looks too harsh, see bug #6255.
res += "Update log:\n" + tmpf.fileContents("UTF-8");
LYXERR(Debug::LYXVC, res);
- tmpf.removeFile();
return to_utf8(res);
}
string SVN::lockingToggle()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return N_("Error: Could not generate logfile.");
if (ret)
return string();
- tmpf.removeFile();
frontend::Alert::warning(_("SVN File Locking"),
(locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
+ _("Do not forget to commit the locking property into the repository."),
bool SVN::getFileRevisionInfo()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
}
ifs.close();
- tmpf.removeFile();
return !rev.empty();
}
bool SVN::getTreeRevisionInfo()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
string line;
getline(ifs, line);
ifs.close();
- tmpf.removeFile();
rev_tree_cache_ = line;
return !line.empty();
}
string revname = convert<string>(rev);
- FileName tmpf = FileName::tempName("lyxvcrev_" + revname + "_");
+ TempFile tempfile("lyxvcrev_" + revname + "_");
+ tempfile.setAutoRemove(false);
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
}
// Now we check the status of the file.
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return FileName();
quoteName(tmpf.toFilesystemEncoding()),
file.onlyPath());
bool found = !tmpf.isFileEmpty();
- tmpf.removeFile();
LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
return found ? file : FileName();
}
LyXVC::CommandResult
GIT::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()){
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
log = N_("Error: Could not generate logfile.");
ret = LyXVC::ErrorCommand;
}
- tmpf.removeFile();
if (!log.empty())
log.insert(0, "GIT: ");
if (ret == LyXVC::VCSuccess && log.empty())
{
// FIXME one day common getDiff and perhaps OpMode for all backends
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return true;
FileName(owner_->filePath()));
docstring diff = tmpf.fileContents("UTF-8");
- tmpf.removeFile();
if (diff.empty())
return false;
bool GIT::getFileRevisionInfo()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
}
ifs.close();
- tmpf.removeFile();
return !rev_file_cache_.empty();
}
bool GIT::getTreeRevisionInfo()
{
- FileName tmpf = FileName::tempName("lyxvcout");
+ TempFile tempfile("lyxvcout");
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
ifstream ifs(tmpf.toFilesystemEncoding().c_str());
getline(ifs, rev_tree_cache_);
ifs.close();
- tmpf.removeFile();
return !rev_tree_cache_.empty();
}
pointer += ":";
- FileName tmpf = FileName::tempName("lyxvcrev_" + revis + "_");
+ TempFile tempfile("lyxvcrev_" + revis + "_");
+ tempfile.setAutoRemove(false);
+ FileName tmpf = tempfile.name();
if (tmpf.empty()) {
LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
return false;
#include "support/Package.h"
#include "support/PathChanger.h"
#include "support/Systemcall.h"
+#include "support/TempFile.h"
#ifdef Q_WS_MACX
#include "support/AppleScript.h"
if (retval == FormatMismatch) {
LYXERR(Debug::FILES, "Converting ui file to format " << LFUN_FORMAT);
- FileName const tempfile = FileName::tempName("convert_ui");
+ TempFile tmp("convertXXXXXX.ui");
+ FileName const tempfile = tmp.name();
bool const success = prefs2prefs(ui_path, tempfile, true);
if (!success) {
LYXERR0("Unable to convert " << ui_path.absFileName() <<
" to format " << LFUN_FORMAT << ".");
} else {
retval = readUIFile(tempfile);
- tempfile.removeFile();
}
}
#include "support/gettext.h"
#include "support/FileName.h"
#include "support/lassert.h"
+#include "support/TempFile.h"
#include "frontends/Application.h"
#include "frontends/FontMetrics.h"
EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
{
- buffer_ = theBufferList().newInternalBuffer(
- support::FileName::tempName("embedded.internal").absFileName());
+ support::TempFile tempfile("embedded.internal");
+ tempfile.setAutoRemove(false);
+ buffer_ = theBufferList().newInternalBuffer(tempfile.name().absFileName());
buffer_->setUnnamed(true);
buffer_->setFullyLoaded(true);
setBuffer(*buffer_);
#include "support/lassert.h"
#include "support/bind.h"
+#include "support/TempFile.h"
using namespace std;
using namespace lyx::support;
zipped_ = formats.isZippedFile(filename_);
if (zipped_) {
- unzipped_filename_ = FileName::tempName(
- filename_.toFilesystemEncoding());
+ TempFile tempfile(filename_.toFilesystemEncoding());
+ tempfile.setAutoRemove(false);
+ unzipped_filename_ = tempfile.name();
if (unzipped_filename_.empty()) {
status_ = ErrorConverting;
LYXERR(Debug::GRAPHICS, "\tCould not create temporary file.");
// Add some stuff to create a uniquely named temporary file.
// This file is deleted in loadImage after it is loaded into memory.
- FileName const to_file_base = FileName::tempName("CacheItem");
+ TempFile tempfile("CacheItem");
+ tempfile.setAutoRemove(false);
+ FileName const to_file_base = tempfile.name();
remove_loaded_file_ = true;
// Connect a signal to this->imageConverted and pass this signal to
#include "support/os.h"
#include "support/bind.h"
+#include "support/TempFile.h"
#include <sstream>
#include <fstream>
// FIXME THREAD
static int counter = 0;
string const tmp = "gconvert" + convert<string>(counter++);
- string const to_base = FileName::tempName(tmp).toFilesystemEncoding();
+ TempFile tempfile(tmp);
+ tempfile.setAutoRemove(false);
+ string const to_base = tempfile.name().toFilesystemEncoding();
// Create a copy of the file in case the original name contains
// problematic characters like ' or ". We can work around that problem
// If two formats share the same extension we may get identical names
if (outfile == infile && conv.result_file.empty()) {
- string const new_base = FileName::tempName(tmp).toFilesystemEncoding();
+ TempFile tempfile(tmp);
+ tempfile.setAutoRemove(false);
+ string const new_base = tempfile.name().toFilesystemEncoding();
outfile = addExtension(new_base, conv.To->extension());
}
#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
+#include "support/TempFile.h"
#include <sstream>
#include <vector>
namespace external {
-TempName::TempName()
+TempName::TempName() : tempfile_(new support::TempFile("lyxextXXXXXX.tmp"))
{
- FileName const tempname = FileName::tempName("lyxext");
// must have an extension for the converter code to work correctly.
- tempname_ = FileName(tempname.absFileName() + ".tmp");
}
-TempName::TempName(TempName const &)
+TempName::TempName(TempName const & that) : tempfile_(0)
{
- tempname_ = TempName()();
+ *this = that;
}
TempName::~TempName()
{
- tempname_.removeFile();
+ delete tempfile_;
}
TempName & TempName::operator=(TempName const & other)
{
- if (this != &other)
- tempname_ = TempName()();
+ if (this != &other) {
+ delete tempfile_;
+ tempfile_ = new support::TempFile("lyxextXXXXXX.tmp");
+ }
return *this;
}
+
+support::FileName TempName::operator()() const
+{
+ return tempfile_->name();
+}
+
} // namespace external
*/
namespace lyx {
+namespace support {
+class TempFile;
+}
+
namespace external {
class TempName {
TempName(TempName const &);
~TempName();
TempName & operator=(TempName const &);
- support::FileName const & operator()() const { return tempname_; }
+ support::FileName operator()() const;
private:
- support::FileName tempname_;
+ support::TempFile * tempfile_;
};
} // namespace external
bool read(Buffer const &, Lexer &);
/// The name of the tempfile used for manipulations.
- support::FileName const & tempname() const { return tempname_(); }
+ support::FileName tempname() const { return tempname_(); }
/// The template currently in use.
void settemplate(std::string const &);
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/lstrings.h"
+#include "support/TempFile.h"
#include <algorithm>
#include <sstream>
{
// In order to avoid parsing problems with command interpreters
// we pass input data through a file
- FileName const cas_tmpfile = FileName::tempName("casinput");
+ TempFile tempfile("casinput");
+ FileName const cas_tmpfile = tempfile.name();
if (cas_tmpfile.empty()) {
lyxerr << "Warning: cannot create temporary file."
<< endl;
lyxerr << "calling: " << cmd
<< "\ninput: '" << data << "'" << endl;
cmd_ret const ret = runCommand(command);
- cas_tmpfile.removeFile();
return ret.second;
}
}
-static string createTempFile(QString const & mask)
-{
- // FIXME: This is not safe. QTemporaryFile creates a file in open(),
- // but the file is deleted when qt_tmp goes out of scope.
- // Therefore the next call to createTempFile() may create the
- // same file again. To make this safe the QTemporaryFile object
- // needs to be kept for the whole life time of the temp file name.
- // This can be achieved by using the TempFile class.
- QTemporaryFile qt_tmp(mask + ".XXXXXXXXXXXX");
- if (qt_tmp.open()) {
- string const temp_file = fromqstr(qt_tmp.fileName());
- LYXERR(Debug::FILES, "Temporary file `" << temp_file << "' created.");
- return temp_file;
- }
- LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
- << qt_tmp.fileTemplate());
- return string();
-}
-
-
-FileName FileName::tempName(FileName const & temp_dir, string const & mask)
-{
- QFileInfo tmp_fi(QDir(temp_dir.d->fi.absoluteFilePath()), toqstr(mask));
- LYXERR(Debug::FILES, "Temporary file in " << tmp_fi.absoluteFilePath());
- return FileName(createTempFile(tmp_fi.absoluteFilePath()));
-}
-
-
-FileName FileName::tempName(string const & mask)
-{
- return tempName(package().temp_dir(), mask);
-}
-
-
FileName FileName::getcwd()
{
// return makeAbsPath("."); would create an infinite loop
void changeExtension(std::string const & extension);
static FileName fromFilesystemEncoding(std::string const & name);
- /// Create a temporary file with the given mask.
- /// \p mask must be in filesystem encoding, if it contains a
- /// relative path, the template file will be created in the global
- /// temporary directory as given by 'package().temp_dir()'.
- /// CAUTION: This method may create race conditions.
- /// Do not use, use the TempFile class instead.
- static FileName tempName(std::string const & mask);
- static FileName tempName(FileName const & temp_dir,
- std::string const & mask);
/// get the current working directory
static FileName getcwd();
#include "support/qstring_helpers.h"
#include <QDir>
+#include <QTemporaryFile>
#include "support/lassert.h"
#include "support/regex.h"
}
+static string createTempFile(QString const & mask)
+{
+ // FIXME: This is not safe. QTemporaryFile creates a file in open(),
+ // but the file is deleted when qt_tmp goes out of scope.
+ // Therefore the next call to createTempFile() may create the
+ // same file again. To make this safe the QTemporaryFile object
+ // needs to be kept for the whole life time of the temp file name.
+ // This could be achieved by creating a class TempDir (like
+ // TempFile, but using a currentlky non-existing
+ // QTemporaryDirectory object).
+ QTemporaryFile qt_tmp(mask + ".XXXXXXXXXXXX");
+ if (qt_tmp.open()) {
+ string const temp_file = fromqstr(qt_tmp.fileName());
+ LYXERR(Debug::FILES, "Temporary file `" << temp_file << "' created.");
+ return temp_file;
+ }
+ LYXERR(Debug::FILES, "Unable to create temporary file with following template: "
+ << qt_tmp.fileTemplate());
+ return string();
+}
+
+
static FileName createTmpDir(FileName const & tempdir, string const & mask)
{
LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
<< "createTmpDir: mask=`" << mask << '\'');
- FileName const tmpfl = FileName::tempName(tempdir, mask);
+ QFileInfo tmp_fi(QDir(toqstr(tempdir.absFileName())), toqstr(mask));
+ FileName const tmpfl(createTempFile(tmp_fi.absoluteFilePath()));
if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
LYXERR0("LyX could not create temporary directory in " << tempdir