mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix file locking problem on windows (bug 9925)
External processes cannot access files which are open in LyX. Therefore the
temp files created by the external inset need to be closed right after
creation. The symptom was that the date inset did not produce any outout on
windows (bug 9925). This change reverts a small part of f09a9fe2
.
Although the date inset is unimportant and will probably be removed, this
change is important for all external insets that make use of temp files.
This commit is contained in:
parent
4ab1d77577
commit
8171272d1f
@ -69,13 +69,20 @@ namespace Alert = frontend::Alert;
|
||||
|
||||
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;
|
||||
}
|
||||
@ -83,15 +90,17 @@ TempName::TempName(TempName const & that) : tempfile_(0)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -99,7 +108,7 @@ TempName & TempName::operator=(TempName const & other)
|
||||
|
||||
support::FileName TempName::operator()() const
|
||||
{
|
||||
return tempfile_->name();
|
||||
return tempname_;
|
||||
}
|
||||
|
||||
} // namespace external
|
||||
|
@ -24,10 +24,6 @@
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace support {
|
||||
class TempFile;
|
||||
}
|
||||
|
||||
namespace external {
|
||||
|
||||
/** No two InsetExternalParams variables can have the same temporary file.
|
||||
@ -45,7 +41,7 @@ public:
|
||||
TempName & operator=(TempName const &);
|
||||
support::FileName operator()() const;
|
||||
private:
|
||||
support::TempFile * tempfile_;
|
||||
support::FileName tempname_;
|
||||
};
|
||||
|
||||
} // namespace external
|
||||
|
@ -24,6 +24,13 @@ class FileName;
|
||||
* 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
|
||||
|
Loading…
Reference in New Issue
Block a user