Implement temp package directory removal on Unix. Untested.

This commit is contained in:
Robert Knight 2011-08-20 12:11:05 +01:00
parent 8a29ffd55b
commit 44c1937d96
6 changed files with 102 additions and 1 deletions

View File

@ -4,6 +4,7 @@ find_package(Boost REQUIRED)
add_definitions(-DTIXML_USE_STL)
set (SOURCES
Dir.cpp
FileOps.cpp
Log.cpp
ProcessUtils.cpp
@ -14,6 +15,7 @@ set (SOURCES
)
set (HEADERS
Dir.h
FileOps.h
Log.h
ProcessUtils.h

39
src/Dir.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "Dir.h"
#ifdef PLATFORM_UNIX
#include <dirent.h>
#endif
Dir::Dir(const char* path)
: m_dir(0)
{
m_path = path;
m_dir = opendir(path);
}
Dir::~Dir()
{
closedir(m_dir);
}
bool Dir::next()
{
m_entry = readdir(m_dir);
return m_entry != 0;
}
std::string Dir::fileName() const
{
return m_entry->d_name;
}
std::string Dir::filePath() const
{
return m_path + '/' + fileName();
}
bool Dir::isDir() const
{
return m_entry->d_type == DT_DIR;
}

34
src/Dir.h Normal file
View File

@ -0,0 +1,34 @@
#pragma once
#include "Platform.h"
#include <string>
#ifdef PLATFORM_UNIX
#include <dirent.h>
#endif
class Dir
{
public:
Dir(const char* path);
~Dir();
// iterate to the next entry in the directory
bool next();
// methods to return information about
// the current entry
std::string fileName() const;
std::string filePath() const;
bool isDir() const;
private:
std::string m_path;
#ifdef PLATFORM_UNIX
DIR* m_dir;
dirent* m_entry;
#endif
};

View File

@ -1,5 +1,6 @@
#include "FileOps.h"
#include "Dir.h"
#include "Platform.h"
#include "StringUtils.h"
@ -208,3 +209,27 @@ void FileOps::touch(const char* path) throw (IOException)
#endif
}
void FileOps::rmdirRecursive(const char* path) throw (IOException)
{
// remove dir contents
Dir dir(path);
while (dir.next())
{
std::string name = dir.fileName();
if (name != "." && name != "..")
{
if (dir.isDir())
{
rmdir(dir.filePath().c_str());
}
else
{
removeFile(dir.filePath().c_str());
}
}
}
// remove the directory itself
rmdir(path);
}

View File

@ -35,5 +35,6 @@ class FileOps
static void createSymLink(const char* link, const char* target) throw (IOException);
static void touch(const char* path) throw (IOException);
static std::string dirname(const char* path);
static void rmdirRecursive(const char* dir) throw (IOException);
};

View File

@ -119,7 +119,7 @@ void UpdateInstaller::run() throw ()
void UpdateInstaller::cleanup()
{
// TODO - Remove the temp dir which the installer was copied to
FileOps::rmdirRecursive(m_packageDir.c_str());
}
void UpdateInstaller::revert()