Add MovetoSD()
authorDuyoung Jang <duyoung.jang@samsung.com>
Thu, 24 Jan 2013 11:43:51 +0000 (20:43 +0900)
committerDuyoung Jang <duyoung.jang@samsung.com>
Thu, 24 Jan 2013 11:43:51 +0000 (20:43 +0900)
Change-Id: Ib73f6752d0a8ce0b8567262af3cb40351bb7fded
Signed-off-by: Duyoung Jang <duyoung.jang@samsung.com>
inc/InstallerDefs.h
src/Manager/InstallerManager.cpp
src/Manager/InstallerManager.h
src/backend/backend.cpp

index aac6f41..4f7dae8 100755 (executable)
@@ -21,7 +21,7 @@
 #ifndef _INSTALLER_DEFS_H_
 #define _INSTALLER_DEFS_H_
 
-#define OSP_INSTALLER_VERSION "osp-installer version = 20130124.1"
+#define OSP_INSTALLER_VERSION "osp-installer version = 20130124.2"
 
 #define DIR_BIN                                L"/bin"
 #define DIR_INFO                       L"/info"
index 60db5e6..6b2d3db 100755 (executable)
  */
 
 #include <unistd.h>
+#include <unique_ptr.h>
+
+#include <app2ext_interface.h>
 
 #include <FIoFile.h>
 #include <FIoDirectory.h>
 #include <FBase_StringConverter.h>
+#include <FAppPkgPackageInfo.h>
+#include <FAppPkg_PackageManagerImpl.h>
 #include <FAppPkg_PackageInfoImpl.h>
 #include <FSysSystemTime.h>
 
@@ -545,6 +550,123 @@ InstallerManager::RequestByCommand(int argc, char **argv)
 }
 
 int
+InstallerManager::RequestMove(const PackageId& packageId, int moveType)
+{
+       result r = E_SUCCESS;
+       int res = 0;
+       InstallerError errorType = INSTALLER_ERROR_NONE;
+       app2ext_handle* pHandle = null;
+       app2ext_move_type location = APP2EXT_MOVE_TO_EXT;
+       GList* pDirectoryList = null;
+       Directory* pDir = null;
+       DirEnumerator* pDirEnum = null;
+       PackageInfo* pPackageInfo = null;
+       _PackageInfoImpl* pPackageInfoImpl = null;
+       String rootPath;
+
+       std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
+       TryReturn(pPackageId, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageId is null");
+
+       if (moveType == PM_MOVE_TO_INTERNAL)
+       {
+               location = APP2EXT_MOVE_TO_PHONE;
+       }
+
+       pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId);
+       TryCatch(pPackageInfo != null, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetPackageInfoN() failed");
+
+       pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
+       TryCatch(pPackageInfoImpl, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed");
+
+       rootPath = pPackageInfoImpl->GetAppRootPath();
+
+       pDir = new (std::nothrow) Directory;
+       TryCatch(pDir, errorType = INSTALLER_ERROR_OUT_OF_MEMORY, "pDir is null");
+
+       r = pDir->Construct(rootPath);
+       TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDir->Construct() failed, path = [%ls]", rootPath.GetPointer());
+
+       pDirEnum = pDir->ReadN();
+       TryCatch(pDirEnum, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirEnum is null");
+
+       while (pDirEnum->MoveNext() == E_SUCCESS)
+       {
+               DirEntry entry = pDirEnum->GetCurrentDirEntry();
+
+               String entryName = entry.GetName();
+               String rootDirectory = rootPath;
+               rootDirectory += L"/";
+               rootDirectory += entryName;
+
+               if (entryName == L"." || entryName == L"..")
+               {
+                       continue;
+               }
+
+               int length = 0;
+               app2ext_dir_details* pDirDetails = null;
+
+               pDirDetails = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details));
+               TryCatch(pDirDetails, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirDetails is null");
+
+               length = rootDirectory.GetLength();
+               pDirDetails->name = (char*) calloc(1, (sizeof(char) * length) + 1);
+               snprintf(pDirDetails->name, length + 1, "%ls", rootDirectory.GetPointer());
+
+               String bin(L"bin");
+               String res(L"res");
+               String icons(L"icons");
+
+               if (rootDirectory.Contains(bin) || rootDirectory.Contains(res) || rootDirectory.Contains(icons))
+               {
+                       pDirDetails->type = APP2EXT_DIR_RO;
+               }
+               else
+               {
+                       pDirDetails->type = APP2EXT_DIR_RW;
+               }
+
+               AppLog("------------------------------------------");
+               AppLog("# Root Directory = [%s], Type = [%d]", pDirDetails->name, pDirDetails->type);
+
+               pDirectoryList = g_list_append(pDirectoryList, pDirDetails);
+       }
+
+       pHandle = app2ext_init(APP2EXT_SD_CARD);
+       TryCatch(pHandle, errorType = INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed");
+
+       res = pHandle->interface.move(pPackageId.get(), pDirectoryList, location);
+       TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.move() failed [%d]", res);
+
+       app2ext_deinit(pHandle);
+
+CATCH:
+       if (pDirectoryList)
+       {
+               GList* pList = null;
+               app2ext_dir_details* pDirDetails = null;
+
+               pList = g_list_first(pDirectoryList);
+               while (pList)
+               {
+                       pDirDetails = (app2ext_dir_details*)pList->data;
+                       if (pDirDetails && pDirDetails->name)
+                       {
+                               free(pDirDetails->name);
+                       }
+                       pList = g_list_next(pList);
+               }
+               g_list_free(pDirectoryList);
+       }
+
+       delete pDirEnum;
+       delete pDir;
+       delete pPackageInfo;
+
+       return errorType;
+}
+
+int
 InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output)
 {
        const char* pOpts_str = "u:i:r:v";
index 93300fc..9076d65 100755 (executable)
@@ -51,6 +51,7 @@ public:
 
        int RequestByCommand(int argc, char **argv);
        int ReqeustByTest(void);
+       int RequestMove(const Tizen::App::PackageId& packageId, int moveType);
 
        void PrintPackageInfo(const char* appId);
        void PrintResult(void);
index 46a94a2..9fa264a 100755 (executable)
@@ -150,6 +150,23 @@ main(int argc, char **argv)
                }
                break;
 
+       case PKGMGR_REQ_MOVE:
+               {
+                       if (_pi != 0)
+                       {
+                               int moveType = -1;
+                               moveType = pkgmgr_installer_get_move_type(_pi);
+
+                               manager.RequestMove(path, moveType);
+                       }
+                       else
+                       {
+                               AppLog("_pi is null");
+                       }
+
+               }
+               break;
+
        default:
                ret = -1;
                break;
@@ -161,11 +178,6 @@ main(int argc, char **argv)
        }
 
 CATCH:
-       if (_pi != 0)
-       {
-               pkgmgr_installer_send_signal(_pi, "sample", "abcd", "end", "ok");
-       }
-
        return errorType;
 }