diff --git a/src/AppInfo.cpp b/src/AppInfo.cpp index 3c55430..7d09f25 100644 --- a/src/AppInfo.cpp +++ b/src/AppInfo.cpp @@ -1,6 +1,6 @@ #include "AppInfo.h" -#include "FileOps.h" +#include "FileUtils.h" #include "Platform.h" #include "StringUtils.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ebcc1cd..dc6b1c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,7 +26,7 @@ add_definitions(-DTIXML_USE_STL) set (SOURCES AppInfo.cpp DirIterator.cpp - FileOps.cpp + FileUtils.cpp Log.cpp ProcessUtils.cpp UpdateInstaller.cpp @@ -44,7 +44,7 @@ endif() set (HEADERS AppInfo.h DirIterator.h - FileOps.h + FileUtils.h Log.h ProcessUtils.h UpdateInstaller.h diff --git a/src/FileOps.cpp b/src/FileUtils.cpp similarity index 86% rename from src/FileOps.cpp rename to src/FileUtils.cpp index 21d4b49..705ae67 100644 --- a/src/FileOps.cpp +++ b/src/FileUtils.cpp @@ -1,4 +1,4 @@ -#include "FileOps.h" +#include "FileUtils.h" #include "DirIterator.h" #include "Log.h" @@ -20,7 +20,7 @@ #include #endif -FileOps::IOException::IOException(const std::string& error) +FileUtils::IOException::IOException(const std::string& error) : m_errno(0) { m_error = error; @@ -39,11 +39,11 @@ FileOps::IOException::IOException(const std::string& error) #endif } -FileOps::IOException::~IOException() throw () +FileUtils::IOException::~IOException() throw () { } -bool FileOps::fileExists(const char* path) throw (IOException) +bool FileUtils::fileExists(const char* path) throw (IOException) { #ifdef PLATFORM_UNIX struct stat fileInfo; @@ -69,7 +69,7 @@ bool FileOps::fileExists(const char* path) throw (IOException) #endif } -void FileOps::setQtPermissions(const char* path, int qtPermissions) throw (IOException) +void FileUtils::setQtPermissions(const char* path, int qtPermissions) throw (IOException) { #ifdef PLATFORM_UNIX int mode = toUnixPermissions(qtPermissions); @@ -83,7 +83,7 @@ void FileOps::setQtPermissions(const char* path, int qtPermissions) throw (IOExc #endif } -void FileOps::moveFile(const char* src, const char* dest) throw (IOException) +void FileUtils::moveFile(const char* src, const char* dest) throw (IOException) { #ifdef PLATFORM_UNIX if (rename(src,dest) != 0) @@ -98,7 +98,7 @@ void FileOps::moveFile(const char* src, const char* dest) throw (IOException) #endif } -void FileOps::extractFromZip(const char* zipFilePath, const char* src, const char* dest) throw (IOException) +void FileUtils::extractFromZip(const char* zipFilePath, const char* src, const char* dest) throw (IOException) { unzFile zipFile = unzOpen(zipFilePath); int result = unzLocateFile(zipFile,src,0); @@ -138,7 +138,7 @@ void FileOps::extractFromZip(const char* zipFilePath, const char* src, const cha unzClose(zipFile); } -void FileOps::mkdir(const char* dir) throw (IOException) +void FileUtils::mkdir(const char* dir) throw (IOException) { #ifdef PLATFORM_UNIX if (::mkdir(dir,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) @@ -153,7 +153,7 @@ void FileOps::mkdir(const char* dir) throw (IOException) #endif } -void FileOps::rmdir(const char* dir) throw (IOException) +void FileUtils::rmdir(const char* dir) throw (IOException) { #ifdef PLATFORM_UNIX if (::rmdir(dir) != 0) @@ -168,7 +168,7 @@ void FileOps::rmdir(const char* dir) throw (IOException) #endif } -void FileOps::createSymLink(const char* link, const char* target) throw (IOException) +void FileUtils::createSymLink(const char* link, const char* target) throw (IOException) { #ifdef PLATFORM_UNIX if (symlink(target,link) != 0) @@ -182,7 +182,7 @@ void FileOps::createSymLink(const char* link, const char* target) throw (IOExcep #endif } -void FileOps::removeFile(const char* src) throw (IOException) +void FileUtils::removeFile(const char* src) throw (IOException) { #ifdef PLATFORM_UNIX if (unlink(src) != 0) @@ -225,7 +225,7 @@ void FileOps::removeFile(const char* src) throw (IOException) #endif } -std::string FileOps::fileName(const char* path) +std::string FileUtils::fileName(const char* path) { #ifdef PLATFORM_UNIX char* pathCopy = strdup(path); @@ -240,7 +240,7 @@ std::string FileOps::fileName(const char* path) #endif } -std::string FileOps::dirname(const char* path) +std::string FileUtils::dirname(const char* path) { #ifdef PLATFORM_UNIX char* pathCopy = strdup(path); @@ -254,7 +254,7 @@ std::string FileOps::dirname(const char* path) #endif } -void FileOps::touch(const char* path) throw (IOException) +void FileUtils::touch(const char* path) throw (IOException) { #ifdef PLATFORM_UNIX // see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html @@ -285,7 +285,7 @@ void FileOps::touch(const char* path) throw (IOException) #endif } -void FileOps::rmdirRecursive(const char* path) throw (IOException) +void FileUtils::rmdirRecursive(const char* path) throw (IOException) { // remove dir contents DirIterator dir(path); @@ -309,7 +309,7 @@ void FileOps::rmdirRecursive(const char* path) throw (IOException) rmdir(path); } -std::string FileOps::canonicalPath(const char* path) +std::string FileUtils::canonicalPath(const char* path) { #ifdef PLATFORM_UNIX // on Linux and Mac OS 10.6, realpath() can allocate the required @@ -339,7 +339,7 @@ void addFlag(InFlags inFlags, int testBit, OutFlags& outFlags, int setBit) } #ifdef PLATFORM_UNIX -int FileOps::toUnixPermissions(int qtPermissions) +int FileUtils::toUnixPermissions(int qtPermissions) { mode_t result = 0; addFlag(qtPermissions,ReadUser,result,S_IRUSR); @@ -355,7 +355,7 @@ int FileOps::toUnixPermissions(int qtPermissions) } #endif -std::string FileOps::toUnixPathSeparators(const std::string& str) +std::string FileUtils::toUnixPathSeparators(const std::string& str) { std::string result = str; for (size_t i=0; i < result.size(); i++) @@ -368,7 +368,7 @@ std::string FileOps::toUnixPathSeparators(const std::string& str) return result; } -std::string FileOps::tempPath() +std::string FileUtils::tempPath() { #ifdef PLATFORM_UNIX return "/tmp"; diff --git a/src/FileOps.h b/src/FileUtils.h similarity index 98% rename from src/FileOps.h rename to src/FileUtils.h index 050d8d7..f9a8429 100644 --- a/src/FileOps.h +++ b/src/FileUtils.h @@ -8,11 +8,11 @@ /** A set of functions for performing common operations * on files, throwing exceptions if an operation fails. */ -class FileOps +class FileUtils { public: /** Base class for exceptions reported by - * FileOps methods if an operation fails. + * FileUtils methods if an operation fails. */ class IOException : public std::exception { diff --git a/src/ProcessUtils.cpp b/src/ProcessUtils.cpp index 7c88757..00f1646 100644 --- a/src/ProcessUtils.cpp +++ b/src/ProcessUtils.cpp @@ -1,6 +1,6 @@ #include "ProcessUtils.h" -#include "FileOps.h" +#include "FileUtils.h" #include "Platform.h" #include "StringUtils.h" #include "Log.h" @@ -108,7 +108,7 @@ bool ProcessUtils::waitForProcess(PLATFORM_PID pid) int ProcessUtils::runElevatedLinux(const std::string& executable, const std::list& args) { - std::string sudoMessage = FileOps::fileName(executable.c_str()) + " needs administrative privileges. Please enter your password."; + std::string sudoMessage = FileUtils::fileName(executable.c_str()) + " needs administrative privileges. Please enter your password."; std::vector sudos; sudos.push_back("kdesudo"); @@ -421,7 +421,7 @@ int ProcessUtils::runWindows(const std::string& executable, std::string ProcessUtils::currentProcessPath() { #ifdef PLATFORM_LINUX - std::string path = FileOps::canonicalPath("/proc/self/exe"); + std::string path = FileUtils::canonicalPath("/proc/self/exe"); LOG(Info,"Current process path " + path); return path; #elif defined(PLATFORM_MAC) diff --git a/src/UpdateInstaller.cpp b/src/UpdateInstaller.cpp index cf4a516..7bb8024 100644 --- a/src/UpdateInstaller.cpp +++ b/src/UpdateInstaller.cpp @@ -1,6 +1,6 @@ #include "UpdateInstaller.h" -#include "FileOps.h" +#include "FileUtils.h" #include "Log.h" #include "ProcessUtils.h" #include "UpdateObserver.h" @@ -81,7 +81,7 @@ void UpdateInstaller::run() throw () { updaterPath = ProcessUtils::currentProcessPath(); } - catch (const FileOps::IOException& ex) + catch (const FileUtils::IOException& ex) { LOG(Error,"error reading process path with mode " + intToStr(m_mode)); return; @@ -147,7 +147,7 @@ void UpdateInstaller::run() throw () LOG(Info,"Removing backups"); removeBackups(); } - catch (const FileOps::IOException& exception) + catch (const FileUtils::IOException& exception) { error = exception.what(); } @@ -177,9 +177,9 @@ void UpdateInstaller::cleanup() { try { - FileOps::rmdirRecursive(m_packageDir.c_str()); + FileUtils::rmdirRecursive(m_packageDir.c_str()); } - catch (const FileOps::IOException& ex) + catch (const FileUtils::IOException& ex) { LOG(Error,"Error cleaning up updater " + std::string(ex.what())); } @@ -194,11 +194,11 @@ void UpdateInstaller::revert() const std::string& installedFile = iter->first; const std::string& backupFile = iter->second; - if (FileOps::fileExists(installedFile.c_str())) + if (FileUtils::fileExists(installedFile.c_str())) { - FileOps::removeFile(installedFile.c_str()); + FileUtils::removeFile(installedFile.c_str()); } - FileOps::moveFile(backupFile.c_str(),installedFile.c_str()); + FileUtils::moveFile(backupFile.c_str(),installedFile.c_str()); } } @@ -211,32 +211,32 @@ void UpdateInstaller::installFile(const UpdateScriptFile& file) backupFile(destPath); // create the target directory if it does not exist - std::string destDir = FileOps::dirname(destPath.c_str()); - if (!FileOps::fileExists(destDir.c_str())) + std::string destDir = FileUtils::dirname(destPath.c_str()); + if (!FileUtils::fileExists(destDir.c_str())) { - FileOps::mkdir(destDir.c_str()); + FileUtils::mkdir(destDir.c_str()); } if (target.empty()) { // locate the package containing the file std::string packageFile = m_packageDir + '/' + file.package + ".zip"; - if (!FileOps::fileExists(packageFile.c_str())) + if (!FileUtils::fileExists(packageFile.c_str())) { throw "Package file does not exist: " + packageFile; } // extract the file from the package and copy it to // the destination - FileOps::extractFromZip(packageFile.c_str(),file.path.c_str(),destPath.c_str()); + FileUtils::extractFromZip(packageFile.c_str(),file.path.c_str(),destPath.c_str()); // set the permissions on the newly extracted file - FileOps::setQtPermissions(destPath.c_str(),file.permissions); + FileUtils::setQtPermissions(destPath.c_str(),file.permissions); } else { // create the symlink - FileOps::createSymLink(destPath.c_str(),target.c_str()); + FileUtils::createSymLink(destPath.c_str(),target.c_str()); } } @@ -262,9 +262,9 @@ void UpdateInstaller::uninstallFiles() for (;iter != m_script->filesToUninstall().end();iter++) { std::string path = m_installDir + '/' + iter->c_str(); - if (FileOps::fileExists(path.c_str())) + if (FileUtils::fileExists(path.c_str())) { - FileOps::removeFile(path.c_str()); + FileUtils::removeFile(path.c_str()); } else { @@ -275,15 +275,15 @@ void UpdateInstaller::uninstallFiles() void UpdateInstaller::backupFile(const std::string& path) { - if (!FileOps::fileExists(path.c_str())) + if (!FileUtils::fileExists(path.c_str())) { // no existing file to backup return; } std::string backupPath = path + ".bak"; - FileOps::removeFile(backupPath.c_str()); - FileOps::moveFile(path.c_str(), backupPath.c_str()); + FileUtils::removeFile(backupPath.c_str()); + FileUtils::moveFile(path.c_str(), backupPath.c_str()); m_backups[path] = backupPath; } @@ -293,7 +293,7 @@ void UpdateInstaller::removeBackups() for (;iter != m_backups.end();iter++) { const std::string& backupFile = iter->second; - FileOps::removeFile(backupFile.c_str()); + FileUtils::removeFile(backupFile.c_str()); } } @@ -303,20 +303,20 @@ bool UpdateInstaller::checkAccess() try { - FileOps::removeFile(testFile.c_str()); + FileUtils::removeFile(testFile.c_str()); } - catch (const FileOps::IOException& error) + catch (const FileUtils::IOException& error) { LOG(Info,"Removing existing access check file failed " + std::string(error.what())); } try { - FileOps::touch(testFile.c_str()); - FileOps::removeFile(testFile.c_str()); + FileUtils::touch(testFile.c_str()); + FileUtils::removeFile(testFile.c_str()); return true; } - catch (const FileOps::IOException& error) + catch (const FileUtils::IOException& error) { LOG(Info,"checkAccess() failed " + std::string(error.what())); return false;