From: James Turner Date: Mon, 28 Sep 2015 01:39:58 +0000 (-0500) Subject: Improve package extraction cleanup X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=945cf5d9639aaf9c6060f38d37b0b6308376480a;p=simgear.git Improve package extraction cleanup --- diff --git a/simgear/package/Install.cxx b/simgear/package/Install.cxx index b91d2552..d8896d29 100644 --- a/simgear/package/Install.cxx +++ b/simgear/package/Install.cxx @@ -66,6 +66,17 @@ public: } } + ~PackageArchiveDownloader() + { + // always clean up our extraction dir: if we successfully downloaded + // and installed it will be an empty dir, if we failed it might contain + // (some) of the package files. + Dir d(m_extractPath); + if (d.exists()) { + d.remove(true /* recursive */); + } + } + size_t downloadedBytes() const { return m_downloaded; @@ -138,13 +149,16 @@ protected: } if (m_owner->path().exists()) { - //std::cout << "removing existing path" << std::endl; Dir destDir(m_owner->path()); destDir.remove(true /* recursive */); } - m_extractPath.append(m_owner->package()->dirName()); - bool ok = m_extractPath.rename(m_owner->path()); + // build a path like /path/to/packages/org.some.catalog/Aircraft/extract_xxxx/MyAircraftDir + SGPath extractedPath = m_extractPath; + extractedPath.append(m_owner->package()->dirName()); + + // rename it to path/to/packages/org.some.catalog/Aircraft/MyAircraftDir + bool ok = extractedPath.rename(m_owner->path()); if (!ok) { doFailure(Delegate::FAIL_FILESYSTEM); return;