Fix non-sharing problem of shared directory for OSP compatible application
authorHyunbin Lee <hyunbin.lee@samsung.com>
Thu, 11 Apr 2013 04:23:49 +0000 (13:23 +0900)
committerHyunbin Lee <hyunbin.lee@samsung.com>
Thu, 11 Apr 2013 06:51:28 +0000 (15:51 +0900)
Change-Id: I91f3ce55c8f3f25a02eea580796a47c6672e9a63
Signed-off-by: Hyunbin Lee <hyunbin.lee@samsung.com>
src/io/FIo_FileImpl.cpp
src/io/inc/FIo_FileImpl.h

index eb53de7..5837696 100644 (file)
@@ -869,24 +869,27 @@ _FileImpl::GetAvailableUid(void)
 }
 
 bool
-_FileImpl::CreateOspApplicationDirectories(const String& appRootPath, const String& pkgId) // for 2.1 app
+_FileImpl::CreateOspApplicationDirectories(const String& appRootPath, const String& pkgId) // for 2.0 app
 {
+#if 0
        struct _OspDir appSubDir[] =
        {
-               { "./shared\0",                 0755, false },
-               //{ "./shared/data\0",  0755, true },
-               { "./shared/res\0",             0755, false },
-               { "./shared/trusted\0", 0755, true },
+               //{ "./shared\0",                       0755, false },
+               //{ "./shared/data\0",          0755, true },
+               //{ "./shared/res\0",           0755, false },
+               //{ "./shared/trusted\0",       0755, true },
                //{ "./cache\0", 0700, true }
        };
        int uid = -1;
        int ret = 0;
        unsigned int i = 0;
        result r = E_SUCCESS;
+#endif
 
        SysTryReturn(NID_IO, CleanDirectories(appRootPath, pkgId) == true, false, E_SYSTEM,
                        "[E_SYSTEM] Failed to clean directories for 2.0 application compatibility.");
 
+#if 0
        unique_ptr<char[]> pAppRootPath(_StringConverter::CopyToCharArrayN(appRootPath));
        SysTryReturn(NID_IO, pAppRootPath != null, false, E_SYSTEM, "[E_SYSTEM] The memory is insufficient.");
 
@@ -916,27 +919,6 @@ _FileImpl::CreateOspApplicationDirectories(const String& appRootPath, const Stri
                }
        }
 
-       if (access("./shared/data", F_OK) == 0)
-       {
-               SysTryCatch(NID_IO, system("chown -R 5000:5000 ./shared/data") != -1, , E_SYSTEM,
-                               "[E_SYSTEM] chown() failed");
-       }
-       // XXX: Temp code for supporting old share directory.
-       else if (access("./share", F_OK) == 0)
-       {
-               SysTryCatch(NID_IO, system("rm -rf ./shared/data") != -1, , E_SYSTEM,
-                               "[E_SYSTEM] Failed to remove ./shared/data directory");
-               
-               SysTryCatch(NID_IO, rename("./share", "./shared/data") == 0, , E_SYSTEM,
-                               "[E_SYSTEM] Failed to rename share directory (%d, %s)", errno, strerror(errno));
-
-               SysTryCatch(NID_IO, system("chown -R 5000:5000 ./shared/data") != -1, , E_SYSTEM,
-                               "[E_SYSTEM] chown() failed");
-
-               SysTryCatch(NID_IO, chmod("./shared/data", 0755) == 0, , E_SYSTEM, "[E_SYSTEM] chmod() failed");
-       }
-       // XXX-end
-
        umask(0022);
 
        SysLog(NID_IO, "_FileImpl::CreateOspApplicationDirectories() succeeded.");
@@ -946,6 +928,10 @@ CATCH:
        umask(0022);
 
        return false;
+#else
+       return true;
+#endif
+
 }
 
 bool
@@ -1069,7 +1055,8 @@ _FileImpl::CreateOspInternalDirectories(const String& pkgId) // for 2.0 app
        }
 #endif
 
-       // XXX: shared directory is not supported for 2.0 applications
+       // XXX: OSP compatible application's data packed in shared/data, shared/trusted directory of SDK
+       // cannot be delivered.
 #if 0
        if (access("./shared/data", F_OK) == 0)
        {
@@ -1084,15 +1071,23 @@ _FileImpl::CreateOspInternalDirectories(const String& pkgId) // for 2.0 app
                char chownCmd[256] = { 0, };
                sprintf(chownCmd, "chown -R 5000:5000 /opt/usr/share/.osp-compat/share/%ls/", pkgId.GetPointer());
                SysTryReturn(NID_IO, system(chownCmd) != -1, false, E_SYSTEM, "[E_SYSTEM] chown() failed");
-
-               char symlinkCmd[256] = { 0, };
-               sprintf(symlinkCmd, "ln -s %s ./shared/data", pOspShareAppIdPath.get());
-               SysTryReturn(NID_IO, system(symlinkCmd) != -1, false, E_SYSTEM, "[E_SYSTEM] symlink() failed");
        }
 #endif
-       char symlinkCmd[256] = { 0, };
-       sprintf(symlinkCmd, "ln -s %s ./shared/data", pOspShareAppIdPath.get());
-       SysTryReturn(NID_IO, system(symlinkCmd) != -1, false, E_SYSTEM, "[E_SYSTEM] symlink() failed");
+       ret = remove("./shared/data");
+       SysTryReturn(NID_IO, ret == 0 || errno == ENOENT, false, E_SYSTEM,
+                       "[E_SYSTEM] remove() failed, errno: %d (%s), path: ./shared/data", errno, strerror(errno));
+       ret = remove("./shared/trusted");
+       SysTryReturn(NID_IO, ret == 0 || errno == ENOENT, false, E_SYSTEM,
+                       "[E_SYSTEM] remove() failed, errno: %d (%s), path: ./shared/trusted", errno, strerror(errno));
+
+       ret = symlink(pOspShareAppIdPath.get(), "./shared/data");
+       SysTryReturn(NID_IO, ret == 0, false, E_SYSTEM,
+                       "[E_SYSTEM] symlink() failed, errno: %d (%s), link: ./shared/data -> %s",
+                       errno, strerror(errno), pOspShareAppIdPath.get());
+       ret = symlink(pOspShare2AppIdPath.get(), "./shared/trusted");
+       SysTryReturn(NID_IO, ret == 0, false, E_SYSTEM,
+                       "[E_SYSTEM] symlink() failed, errno: %d (%s), link: ./shared/trusted -> %s",
+                       errno, strerror(errno), pOspShare2AppIdPath.get());
 
        return true;
 }
index e042c06..6ed64c7 100644 (file)
@@ -146,11 +146,11 @@ public:
 
        static bool IsSystemPath(const Tizen::Base::String& filePath);
 
-       static bool PrepareDataCaging(const Tizen::Base::String& appRootPath, const Tizen::Base::String& pkgId); // for 2.0 app
+       static bool PrepareDataCaging(const Tizen::Base::String& appRootPath, const Tizen::Base::String& pkgId); // for OSP compatible app
 
-       static bool FinalizeDataCaging(const Tizen::Base::String& appRootPath); // for 2.0 app
+       static bool FinalizeDataCaging(const Tizen::Base::String& appRootPath); // for OSP compatible app
 
-       static bool CreateOspApplicationDirectories(const Tizen::Base::String& appRootpath, const Tizen::Base::String& pkgId); // for 2.1 app
+       static bool CreateOspApplicationDirectories(const Tizen::Base::String& appRootpath, const Tizen::Base::String& pkgId); // for Tizen 2.0 app
 
        static int GetAvailableUid(void);