namespace external {
-TempName::TempName() : tempfile_(new support::TempFile("lyxextXXXXXX.tmp"))
+TempName::TempName()
{
// must have an extension for the converter code to work correctly.
+ support::TempFile f("lyxextXXXXXX.tmp");
+ // Let f go out of scope here and delete the file ourselves in
+ // ~TempName(), since otherwise external processes would not be able
+ // to use the file on windows (bug 9925). This is not as safe as
+ // keeping a support::TempFile member would be, but the best we can do.
+ f.setAutoRemove(false);
+ tempname_ = f.name();
}
-TempName::TempName(TempName const & that) : tempfile_(0)
+TempName::TempName(TempName const & that)
{
*this = that;
}
TempName::~TempName()
{
- delete tempfile_;
+ tempname_.removeFile();
}
TempName & TempName::operator=(TempName const & other)
{
if (this != &other) {
- delete tempfile_;
- tempfile_ = new support::TempFile("lyxextXXXXXX.tmp");
+ tempname_.removeFile();
+ support::TempFile f("lyxextXXXXXX.tmp");
+ f.setAutoRemove(false);
+ tempname_ = f.name();
}
return *this;
}
support::FileName TempName::operator()() const
{
- return tempfile_->name();
+ return tempname_;
}
} // namespace external
namespace lyx {
-namespace support {
-class TempFile;
-}
-
namespace external {
/** No two InsetExternalParams variables can have the same temporary file.
TempName & operator=(TempName const &);
support::FileName operator()() const;
private:
- support::TempFile * tempfile_;
+ support::FileName tempname_;
};
} // namespace external
* The file is created in the constructor, and deleted in the destructor.
* You may do anything with the file (including deletion), but the instance
* of this class must stay alive as long as the file is needed.
+ * There is only one exception to this rule:
+ * If the file is supposed to be used by a different process then you need
+ * to be aware of OS specific file locking semantics: On windows, the file
+ * is opened with exclusive rights for the process which opened it. This
+ * is not the case on other OSes. Therefore, if the file is supposed to be
+ * used by a different process you need to sometheing similar to TempName
+ * in InsetExternal.cpp.
*/
class TempFile {
/// noncopyable