Remove all generated files that still exist (perhaps because the process was

curtailed before the images were loaded.)


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4540 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-07-06 12:38:44 +00:00
parent 9e8b8fe2d8
commit 627592dfc0
3 changed files with 46 additions and 2 deletions

View File

@ -3,6 +3,11 @@
* PreviewLoader.C: ensure that the metrics data is used by the * PreviewLoader.C: ensure that the metrics data is used by the
correct image! correct image!
* PreviewLoader.C:
* PreviewImage.C: (Impl d-tor): remove all generated files that still
exist (perhaps because the process was curtailed before the images
were loaded.)
2002-07-05 Angus Leeming <leeming@lyx.org> 2002-07-05 Angus Leeming <leeming@lyx.org>
* PreviewImage.h: * PreviewImage.h:

View File

@ -32,6 +32,8 @@ struct PreviewImage::Impl : public boost::signals::trackable {
Impl(PreviewImage & p, PreviewLoader & l, Impl(PreviewImage & p, PreviewLoader & l,
string const & s, string const & f, double af); string const & s, string const & f, double af);
/// ///
~Impl();
///
void startLoading(); void startLoading();
/// ///
Image const * image() const { return iloader_->image(); } Image const * image() const { return iloader_->image(); }
@ -116,6 +118,12 @@ PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
{} {}
PreviewImage::Impl::~Impl()
{
lyx::unlink(iloader_->filename());
}
void PreviewImage::Impl::startLoading() void PreviewImage::Impl::startLoading()
{ {
if (iloader_->status() != WaitingToLoad) if (iloader_->status() != WaitingToLoad)

View File

@ -29,6 +29,7 @@
#include "support/filetools.h" #include "support/filetools.h"
#include "support/forkedcall.h" #include "support/forkedcall.h"
#include "support/forkedcontr.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
@ -99,6 +100,8 @@ struct PreviewLoader::Impl : public boost::signals::trackable {
/// ///
Impl(PreviewLoader & p, Buffer const & b); Impl(PreviewLoader & p, Buffer const & b);
/// ///
~Impl();
///
PreviewImage const * preview(string const & latex_snippet) const; PreviewImage const * preview(string const & latex_snippet) const;
/// ///
PreviewLoader::Status status(string const & latex_snippet) const; PreviewLoader::Status status(string const & latex_snippet) const;
@ -148,11 +151,13 @@ private:
InProgress() {} InProgress() {}
/// ///
InProgress(string const & f, PendingMap const & m) InProgress(string const & f, PendingMap const & m)
: metrics_file(f), snippets(m.begin(), m.end()) : pid(0), metrics_file(f), snippets(m.begin(), m.end())
{ {
sort(snippets.begin(), snippets.end(), CompSecond()); sort(snippets.begin(), snippets.end(), CompSecond());
} }
///
pid_t pid;
/// ///
string metrics_file; string metrics_file;
@ -267,6 +272,28 @@ PreviewLoader::Impl::preview(string const & latex_snippet) const
} }
PreviewLoader::Impl::~Impl()
{
InProgressMap::const_iterator ipit = in_progress_.begin();
InProgressMap::const_iterator ipend = in_progress_.end();
for (; ipit != ipend; ++ipit) {
pid_t pid = ipit->second.pid;
if (pid)
ForkedcallsController::get().kill(pid, 0);
lyx::unlink(ipit->second.metrics_file);
vector<StrPair> const & snippets = ipit->second.snippets;
vector<StrPair>::const_iterator vit = snippets.begin();
vector<StrPair>::const_iterator vend = snippets.end();
for (; vit != vend; ++vit) {
lyx::unlink(vit->second);
}
}
}
PreviewLoader::Status PreviewLoader::Status
PreviewLoader::Impl::status(string const & latex_snippet) const PreviewLoader::Impl::status(string const & latex_snippet) const
{ {
@ -412,6 +439,7 @@ void PreviewLoader::Impl::startLoading()
// Store the generation process in a list of all generating processes // Store the generation process in a list of all generating processes
// (I anticipate that this will be small!) // (I anticipate that this will be small!)
inprogress.pid = call.pid();
in_progress_[command] = inprogress; in_progress_[command] = inprogress;
} }
@ -434,6 +462,9 @@ void PreviewLoader::Impl::finishedGenerating(string const & command,
return; return;
} }
// Reset the pid to 0 as the process has finished.
git->second.pid = 0;
// Read the metrics file, if it exists // Read the metrics file, if it exists
PreviewMetrics metrics_file(git->second.metrics_file); PreviewMetrics metrics_file(git->second.metrics_file);