#include <errno.h>
#include <unique_ptr.h>
+#include <FIoFile.h>
#include <FIoDirectory.h>
#include <FBase_StringConverter.h>
#include <FSys_EnvironmentImpl.h>
}
bool
+CompatibilityManager::PrepareVirtualRoot(const Tizen::Base::String& rootPath, const Tizen::App::PackageId& packageId)
+{
+ result r = E_SUCCESS;
+ bool res = true;
+ int result = 0;
+ char* pCwd = null;
+ String destPath = rootPath + DIR_VIRTUAL_ROOT;
+ SmackManager smackManager;
+
+ std::unique_ptr<char[]> pVirtualRootPath(_StringConverter::CopyToCharArrayN(destPath));
+ TryCatch(pVirtualRootPath != null, res = false, "The memory is insufficient.");
+
+ pCwd = get_current_dir_name();
+ TryCatch(pCwd != null, res = false, "get_current_dir_name() failed. [errno = %d(%s)]", errno, strerror(errno));
+
+ // appRoot/virtual-root
+ if (File::IsFileExist(destPath) == false)
+ {
+ r = Directory::Create(destPath, false);
+ TryCatch(!IsFailed(r), res = false, "Directory::Create() failed");
+ }
+
+ InstallerUtil::ChangeDirectoryPermission(destPath, PERM_BASE, true);
+
+ result = chdir(pVirtualRootPath.get());
+ TryCatch(result == 0, res = false, "chdir(%s) failed. [errno = %d(%s)]", pVirtualRootPath.get(), errno, strerror(errno));
+
+ res = CreateVirtualRootDirectories();
+ TryCatch(res == true, , "CreateVirtualRootDirectories() failed.");
+
+ smackManager.AddLabelDir(packageId, destPath);
+
+ res = CreateSymbolicLink();
+ TryCatch(res == true, , "CreateSymbolicLink() failed.");
+
+ result = chdir(pCwd);
+ TryCatch(result == 0, res = false, "chdir(%s) failed. [errno = %d(%s)]", pCwd, errno, strerror(errno));
+
+CATCH:
+ if (pCwd)
+ {
+ free(pCwd);
+ }
+
+ AppLog("[Tizen::Io] result = [%s]", res?"true":"false");
+
+ return res;
+}
+
+bool
+CompatibilityManager::FinalizeVirtualRoot(const String& rootPath)
+{
+ int res = 0;
+ unsigned int i = 0;
+ String destPath = rootPath + DIR_VIRTUAL_ROOT;
+ static const struct _PathInfo mountPath[] =
+ {
+ { "./bin" },
+ { "./cache" },
+ { "./csa" },
+ { "./data" },
+ { "./dev" },
+ { "./etc" },
+ { "./lib" },
+ { "./media" },
+ { "./mnt" },
+ { "./opt" },
+ { "./proc" },
+ { "./run" },
+ { "./sbin" },
+ { "./smack" },
+ { "./srv" },
+ { "./sys" },
+ { "./system" },
+ { "./tmp" },
+ { "./usr" },
+ { "./var" }
+ };
+
+ std::unique_ptr<char[]> pVirtualRootPath(_StringConverter::CopyToCharArrayN(destPath));
+ TryReturn(pVirtualRootPath, false, "The memory is insufficient.");
+
+ res = chdir(pVirtualRootPath.get());
+ TryReturn(res == 0, false, "chdir() failed. (%d, %s), path = [%ls]", errno, strerror(errno), destPath.GetPointer());
+
+ for (i = 0; i < sizeof(mountPath) / sizeof(struct _PathInfo); ++i)
+ {
+ res = umount2(mountPath[i].destPath, MNT_DETACH);
+ TryReturn((res == 0) || (errno == EINVAL) || (errno == ENOENT), false, "umount2() failed. (%d, %s), path = [%s]", errno, strerror(errno), mountPath[i].destPath);
+ }
+
+ AppLog("[Tizen::Io] FinalizeVirtualRoot() succeeded, path: %ls", destPath.GetPointer());
+ return true;
+}
+
+bool
CompatibilityManager::CreateOspInternalDirectories(const String& rootPath, const PackageId& packageId)
{
result r = E_SUCCESS;
AppLog("[Tizen::Io] CreateSymbolicLink() succeeded.");
return true;
}
+
+bool
+CompatibilityManager::CreateVirtualRootDirectories(void)
+{
+ unsigned int i = 0;
+ int ret = 0;
+ struct _OspDir virtualRootDir[] =
+ {
+ { "./bin", 0000, false },
+ { "./cache", 0000, false },
+ { "./csa", 0000, false },
+ { "./data", 0000, false },
+ { "./dev", 0000, false },
+ { "./etc", 0000, false },
+ { "./lib", 0000, false },
+ { "./media", 0000, false },
+ { "./mnt", 0000, false },
+ { "./opt", 0000, false },
+ { "./proc", 0000, false },
+ { "./run", 0000, false },
+ { "./sbin", 0000, false },
+ { "./smack", 0000, false },
+ { "./srv", 0000, false },
+ { "./sys", 0000, false },
+ { "./system", 0000, false },
+ { "./tmp", 0000, false },
+ { "./usr", 0000, false },
+ { "./var", 0000, false }
+ };
+
+ for (i = 0; i < sizeof(virtualRootDir) / sizeof(struct _OspDir); i++)
+ {
+ ret = mkdir(virtualRootDir[i].path, virtualRootDir[i].mode);
+ if (ret == -1 && errno != 17) // EEXIST
+ {
+ AppLog("mkdir() failed (%s), path: %s, mode: 0%o", strerror(errno), virtualRootDir[i].path, virtualRootDir[i].mode);
+ return false;
+ }
+ }
+
+ AppLog("[Tizen::Io] CreateVirtualRootDirectories() succeeded.");
+ return true;
+}
PermissionManager::SetDirectory(InstallationContext* pContext)
{
result r = E_SUCCESS;
+ bool res = true;
String destPath;
String appRootPath;
{
AppLog("[Tizen::Io] OSP 2.0 application");
- if (CompatibilityManager::PrepareDataCaging(appRootPath, packageId) == false)
- {
- AppLog("[Tizen::Io] CompatibilityManager::PrepareDataCaging() failed.");
- return false;
- }
+ res = CompatibilityManager::PrepareDataCaging(appRootPath, packageId);
+ TryReturn(res == true, false, "[Tizen::Io] CompatibilityManager::PrepareDataCaging() failed.");
SetSymLink(pContext);
}
{
AppLog("[Tizen::Io] apiVersion is equal to or greater than Tizen 2.0");
- if (CompatibilityManager::CleanDirectories(appRootPath, packageId) == false)
- {
- AppLog("[Tizen::Io] CompatibilityManager::CleanDirectories() failed.");
- return false;
- }
+ res = CompatibilityManager::CleanDirectories(appRootPath, packageId);
+ TryReturn(res == true, false, "[Tizen::Io] CompatibilityManager::CleanDirectories() failed.");
- if (CompatibilityManager::LinkOspSharePath(appRootPath, packageId) == false)
- {
- AppLog("[Tizen::Io] CompatibilityManager::LinkOspSharePath() failed.");
- return false;
- }
+ res = CompatibilityManager::LinkOspSharePath(appRootPath, packageId);
+ TryReturn(res == true, false, "[Tizen::Io] CompatibilityManager::LinkOspSharePath() failed.");
}
if (pContext->__isVirtualRoot == true)
{
- if (pContext->__pSymbolicLinkList->GetCount() > 0)
- {
- std::unique_ptr< IMapEnumeratorT<String*, String*> > pEnum(pContext->__pSymbolicLinkList->GetMapEnumeratorN());
- TryReturn(pEnum, false, "pSymbolicLinkList->GetMapEnumeratorN() failed.");
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- String* pKey = null;
- String* pValue = null;
-
- pEnum->GetKey(pKey);
- pEnum->GetValue(pValue);
-
- AppLog("SymbolicLink - Src = [%ls], Des = [%ls]", pKey->GetPointer(), pValue->GetPointer());
- }
- }
+ res = CompatibilityManager::PrepareVirtualRoot(appRootPath, packageId);
+ TryReturn(res == true, false, "[Tizen::Io] CompatibilityManager::PrepareVirtualRoot() failed.");
}
AppLog("------------------------------------------");