From baad189f97c525a0ee50be07cd5ac82253b4a2da Mon Sep 17 00:00:00 2001 From: Dongeup Ham Date: Tue, 6 Nov 2012 12:55:34 +0900 Subject: [PATCH] Implementation to remove real directory path. Change-Id: I4aecf97e8be68ef253d730dce38cc324ff592671 --- inc/InstallerDefs.h | 2 +- src/Manager/InstallerManager.cpp | 24 +++++++++--------------- src/Manager/InstallerManager.h | 2 +- src/Step/UninstallStep.cpp | 9 +++++++++ src/Util/InstallerUtil.cpp | 16 ++++++++++++++++ src/Util/InstallerUtil.h | 1 + src/backend/backend.cpp | 8 ++++---- 7 files changed, 41 insertions(+), 21 deletions(-) diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h index dab4b09..f255654 100755 --- a/inc/InstallerDefs.h +++ b/inc/InstallerDefs.h @@ -21,7 +21,7 @@ #ifndef _INSTALLER_DEFS_H_ #define _INSTALLER_DEFS_H_ -#define OSP_INSTALLER_VERSION "osp-installer version = [2012/11/05]" +#define OSP_INSTALLER_VERSION "osp-installer version = [2012/11/06]" #define DIR_BIN L"/bin" #define DIR_INFO L"/info" diff --git a/src/Manager/InstallerManager.cpp b/src/Manager/InstallerManager.cpp index 7c682c8..9f53bcf 100755 --- a/src/Manager/InstallerManager.cpp +++ b/src/Manager/InstallerManager.cpp @@ -656,26 +656,20 @@ InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, b } bool -InstallerManager::RemoveGarbage(const char* pDirectory) +InstallerManager::RemoveGarbage(const String& filePath) { - char pkgname[1024] = {0}; + AppLogTag(OSP_INSTALLER, "RemoveGarbage Directory = [%ls]", filePath.GetPointer()); - if (pDirectory == null) + String realPath; + if (InstallerUtil::IsSymlink(filePath) == true) { - return false; - } - - char* pStart = strrchr(const_cast(pDirectory), '/'); - if (pStart == null) - { - return false; + if (InstallerUtil::GetRealPath(filePath, realPath) == true) + { + InstallerUtil::Remove(realPath); + } } - strcpy(pkgname, pStart + 1); - AppLogTag(OSP_INSTALLER, "pkgname = %s", pkgname); - - AppLogTag(OSP_INSTALLER, "Remove Directory=(%s)", pDirectory); - InstallerUtil::Remove(pDirectory); + InstallerUtil::Remove(filePath); return true; } diff --git a/src/Manager/InstallerManager.h b/src/Manager/InstallerManager.h index f61dcef..9e4a05f 100755 --- a/src/Manager/InstallerManager.h +++ b/src/Manager/InstallerManager.h @@ -47,7 +47,7 @@ public: int Request(const Osp::Base::String& path, InstallerOperation op, RequesterType requesterType, bool hybridService = false); int RequestRecursiveDirectory(const Osp::Base::String& path, int& errorType); - bool RemoveGarbage(const char* pDirectory); + bool RemoveGarbage(const Osp::Base::String& filePath); int RequestByCommand(int argc, char **argv); int ReqeustByTest(void); diff --git a/src/Step/UninstallStep.cpp b/src/Step/UninstallStep.cpp index 1e5f4d2..2b024a4 100755 --- a/src/Step/UninstallStep.cpp +++ b/src/Step/UninstallStep.cpp @@ -205,6 +205,15 @@ UninstallStep::OnStateRemoveDir(void) } else { + String realPath; + if (InstallerUtil::IsSymlink(rootPath) == true) + { + if (InstallerUtil::GetRealPath(rootPath, realPath) == true) + { + InstallerUtil::Remove(realPath); + } + } + InstallerUtil::Remove(rootPath); } diff --git a/src/Util/InstallerUtil.cpp b/src/Util/InstallerUtil.cpp index ef67d72..36fa0cf 100755 --- a/src/Util/InstallerUtil.cpp +++ b/src/Util/InstallerUtil.cpp @@ -188,6 +188,22 @@ InstallerUtil::IsSymlink(const Osp::Base::String& filePath) } bool +InstallerUtil::GetRealPath(const String& filePath, String& realPath) +{ + char* pRealPath = null; + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + + char tmpPath[PATH_MAX] = {0}; + pRealPath = realpath(pFilePath.get(), tmpPath); + TryReturn(pRealPath, false, "[osp-installer] pRealPath is null"); + + realPath = tmpPath; + + return true; +} + +bool InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath) { int err = -1; diff --git a/src/Util/InstallerUtil.h b/src/Util/InstallerUtil.h index 0386ae5..2fae278 100755 --- a/src/Util/InstallerUtil.h +++ b/src/Util/InstallerUtil.h @@ -48,6 +48,7 @@ public: static bool Copy(const Osp::Base::String& srcFilePath, const Osp::Base::String& destFilePath); static bool CopyDirectory(const Osp::Base::String& srcFilePath, const Osp::Base::String& destFilePath); static bool IsSymlink(const Osp::Base::String& filePath); + static bool GetRealPath(const Osp::Base::String& filePath, Osp::Base::String& realPath); static bool CreateSymlink(const Osp::Base::String& oldPath, const Osp::Base::String& newPath); static bool ChangeMode(const Osp::Base::String& filePath, int mode); diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index 320d505..b72cdff 100755 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -109,10 +109,10 @@ main(int argc, char **argv) AppLogTag(OSP_INSTALLER, "_pi is null"); } - if (errorType != 0) - { - manager.RemoveGarbage(pkg_path); - } +// if (errorType != 0) +// { +// manager.RemoveGarbage(path); +// } __osp_installer_report_result(appId, errorType); manager.PrintResult(); -- 2.7.4