3b1ca1a57d955be0b9e741d81b7ce4afd7fb04ca
[platform/framework/native/installer.git] / src / Installer / DirectoryInstaller.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        DirectoryInstaller.cpp
19  * @brief       This is the implementation file for %DirectoryInstaller class.
20  */
21
22 #include <FIoFile.h>
23 #include <FIoDirectory.h>
24 #include <FIo_FileImpl.h>
25
26 #include "DirectoryInstaller.h"
27 #include "InstallerUtil.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Io;
31
32 DirectoryInstaller::DirectoryInstaller(void)
33 {
34 }
35
36 DirectoryInstaller::~DirectoryInstaller(void)
37 {
38 }
39
40 InstallationStep
41 DirectoryInstaller::GetNext(InstallationStep step)
42 {
43         if (step == INSTALLER_STEP_NONE)
44         {
45                 return INSTALLER_STEP_INIT;
46         }
47         else if (step == INSTALLER_STEP_INIT)
48         {
49                 return INSTALLER_STEP_PARSE_MANIFEST;
50         }
51         else if (step == INSTALLER_STEP_PARSE_MANIFEST)
52         {
53                 return INSTALLER_STEP_CHECK_SYSTEM;
54         }
55         else if (step == INSTALLER_STEP_CHECK_SYSTEM)
56         {
57                 return INSTALLER_STEP_PARSE_SIGNATURE;
58         }
59         else if (step == INSTALLER_STEP_PARSE_SIGNATURE)
60         {
61                 return INSTALLER_STEP_END;
62         }
63         else
64         {
65                 step = (InstallationStep)(step + 1);
66                 return step;
67         }
68 }
69
70 InstallerError
71 DirectoryInstaller::OnInit(void)
72 {
73         InstallationContext* pContext = GetContext();
74
75         if ((File::IsFileExist(pContext->GetSignatureXmlPath()) == true) &&
76                         (File::IsFileExist(pContext->GetAuthorSignatureXmlPath()) == true))
77         {
78                 AppLog("[VerifySignature] VerificationMode ON");
79                 pContext->__isVerificationMode = true;
80         }
81
82         String installPath = pContext->__installDir;
83
84         String newInstallPath;
85         InstallerUtil::CreateSymlinkForAppDirectory(installPath, newInstallPath);
86         pContext->__installDir = newInstallPath;
87         pContext->__rootPath = newInstallPath;
88
89         // remove in /info/*.info files
90         RemoveInfoFiles();
91
92         AppLog("installation path = [%ls]", newInstallPath.GetPointer());
93
94         return Installer::OnInit();
95 }
96
97 InstallerError
98 DirectoryInstaller::OnRegister(void)
99 {
100         AppLog("DirectoryInstaller::OnRegister()");
101         return Installer::OnRegister();
102 }
103
104 InstallerError
105 DirectoryInstaller::OnEnd(void)
106 {
107         AppLog("DirectoryInstaller::OnEnd()");
108         return Installer::OnEnd();
109 }
110
111 InstallerError
112 DirectoryInstaller::OnError(void)
113 {
114         AppLog("DirectoryInstaller::OnError()");
115         return Installer::OnError();
116 }
117
118 InstallerError
119 DirectoryInstaller::OnRollback(void)
120 {
121         AppLog("DirectoryInstaller::OnRollback()");
122         return Installer::OnRollback();
123 }
124
125 InstallerError
126 DirectoryInstaller::OnUserCancel(void)
127 {
128         AppLog("DirectoryInstaller::OnUserCancel()");
129         return Installer::OnUserCancel();
130 }
131
132 bool
133 DirectoryInstaller::RemoveInfoFiles(void)
134 {
135         Directory* pDir = null;
136         DirEnumerator* pDirEnum = null;
137         result r = E_SUCCESS;
138         int res = false;
139         String appid;
140         String path;
141         InstallationContext* pContext = null;
142
143         pContext = GetContext();
144         TryCatch(pContext, res = false, "pContext is null");
145
146         path = pContext->__rootPath + DIR_INFO;
147
148         pDir = new (std::nothrow) Directory; // Allocate %Directory instance
149         TryCatch(pDir, res = false, "pDir is null");
150
151         r = pDir->Construct(path);
152         TryCatch(!IsFailed(r), res = false, "pDir->Construct() failed, path = [%ls]", path.GetPointer());
153
154         pDirEnum = pDir->ReadN();
155         TryCatch(pDirEnum, res = false, "pDirEnum is null");
156
157         while (pDirEnum->MoveNext() == E_SUCCESS)
158         {
159                 DirEntry entry = pDirEnum->GetCurrentDirEntry();
160
161                 String entryName = entry.GetName();
162                 String entryDir = path;
163                 entryDir += L"/";
164                 entryDir += entryName;
165
166                 if (entryName == L"." || entryName == L"..")
167                 {
168                         continue;
169                 }
170
171                 // check *.info file
172                 if ((_FileImpl::GetFileExtension(entryDir) == FILE_EXT_INFO) ||
173                                 (entry.IsDirectory() == true))
174                 {
175                         AppLog("Request to delete info file = [%ls]", entryDir.GetPointer());
176                         InstallerUtil::Remove(entryDir);
177                 }
178         }
179
180         delete pDirEnum;
181         delete pDir;
182         return true;
183
184 CATCH:
185         // delete pDirEnum;
186         delete pDir;
187         return false;
188 }