From 627592dfc0e96932dd594ffc53b565dd0a689310 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sat, 6 Jul 2002 12:38:44 +0000 Subject: [PATCH] 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 --- src/graphics/ChangeLog | 5 +++++ src/graphics/PreviewImage.C | 8 ++++++++ src/graphics/PreviewLoader.C | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index a9864a1716..4bb0077236 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -3,6 +3,11 @@ * PreviewLoader.C: ensure that the metrics data is used by the 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 * PreviewImage.h: diff --git a/src/graphics/PreviewImage.C b/src/graphics/PreviewImage.C index 8f90b20379..7b3d14b59a 100644 --- a/src/graphics/PreviewImage.C +++ b/src/graphics/PreviewImage.C @@ -32,6 +32,8 @@ struct PreviewImage::Impl : public boost::signals::trackable { Impl(PreviewImage & p, PreviewLoader & l, string const & s, string const & f, double af); /// + ~Impl(); + /// void startLoading(); /// 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() { if (iloader_->status() != WaitingToLoad) diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 9519bf49fd..d1b748f205 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -29,6 +29,7 @@ #include "support/filetools.h" #include "support/forkedcall.h" +#include "support/forkedcontr.h" #include "support/lstrings.h" #include "support/lyxlib.h" @@ -99,6 +100,8 @@ struct PreviewLoader::Impl : public boost::signals::trackable { /// Impl(PreviewLoader & p, Buffer const & b); /// + ~Impl(); + /// PreviewImage const * preview(string const & latex_snippet) const; /// PreviewLoader::Status status(string const & latex_snippet) const; @@ -148,11 +151,13 @@ private: InProgress() {} /// 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()); } - + + /// + pid_t pid; /// 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 const & snippets = ipit->second.snippets; + vector::const_iterator vit = snippets.begin(); + vector::const_iterator vend = snippets.end(); + for (; vit != vend; ++vit) { + lyx::unlink(vit->second); + } + } +} + + PreviewLoader::Status 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 // (I anticipate that this will be small!) + inprogress.pid = call.pid(); in_progress_[command] = inprogress; } @@ -434,6 +462,9 @@ void PreviewLoader::Impl::finishedGenerating(string const & command, return; } + // Reset the pid to 0 as the process has finished. + git->second.pid = 0; + // Read the metrics file, if it exists PreviewMetrics metrics_file(git->second.metrics_file); -- 2.39.2