Implementation to remove real directory path.
authorDongeup Ham <dongeup.ham@samsung.com>
Tue, 6 Nov 2012 03:55:34 +0000 (12:55 +0900)
committerDongeup Ham <dongeup.ham@samsung.com>
Tue, 6 Nov 2012 03:55:34 +0000 (12:55 +0900)
Change-Id: I4aecf97e8be68ef253d730dce38cc324ff592671

inc/InstallerDefs.h
src/Manager/InstallerManager.cpp
src/Manager/InstallerManager.h
src/Step/UninstallStep.cpp
src/Util/InstallerUtil.cpp
src/Util/InstallerUtil.h
src/backend/backend.cpp

index dab4b09..f255654 100755 (executable)
@@ -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"
index 7c682c8..9f53bcf 100755 (executable)
@@ -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<char*>(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;
 }
index f61dcef..9e4a05f 100755 (executable)
@@ -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);
index 1e5f4d2..2b024a4 100755 (executable)
@@ -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);
        }
 
index ef67d72..36fa0cf 100755 (executable)
@@ -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<char[]> 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;
index 0386ae5..2fae278 100755 (executable)
@@ -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);
index 320d505..b72cdff 100755 (executable)
@@ -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();