Fix installation of NPRuntime plug-ins.
authorZbigniew Kostrzewa <z.kostrzewa@samsung.com>
Fri, 14 Jun 2013 10:56:53 +0000 (12:56 +0200)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Fri, 14 Jun 2013 13:08:06 +0000 (13:08 +0000)
[Issue#] N/A
[Problem] All NPRuntime plug-ins are installed with a widget instead of
only those that match target architecture.
See "Tizen Web Runtime Core Specification 2.1", section
"Web Application Installation", requirements 0102 and 0103.
[Cause] N/A
[Solution] Install from widget package from sub-directory
"plugins/" only those files that are in sub-directory for target
architecture.
[SCMRequest] Depends on: https://review.tizenrsa.org/74219

[Verification]
1. Build repository.
2. Install widget npruntime-all-on-arm-x86.wgt from
RSA/test/wrt/wrt-package-management-tests/resources/ on the device.
3. Check if only plug-ins for arm architecture have been installed.

Change-Id: Iaa5ddca79f8cb1bc0237531869841864ee0e4625

src/jobs/widget_install/widget_unzip.cpp

index bcf29e8..e78cdba 100644 (file)
@@ -34,6 +34,8 @@
 using namespace WrtDB;
 
 namespace {
+const char* const NPRUNTIME_PLUGINS_DIR = "plugins/";
+
 struct PathAndFilePair
 {
     std::string path;
@@ -60,6 +62,34 @@ PathAndFilePair SplitFileAndPath(const std::string &filePath)
                                            position),
                            filePath.substr(position + 1));
 }
+
+inline bool isNPPlugin(const std::string& filePath)
+{
+    std::string::size_type pos = filePath.find(NPRUNTIME_PLUGINS_DIR);
+    // Not specified if a plug-in name MUST end with a specific extension
+    // (e.g. .so)
+    return ((std::string::npos != pos) &&
+            ('/' != filePath[filePath.length() - 1]));
+}
+
+// precondition: isNPPlugin(filePath) == true
+inline bool isValidNPPlugin(const std::string& filePath)
+{
+    return (filePath.find(GlobalConfig::GetNPRuntimePluginsPath()) == 0);
+}
+
+bool shouldBeInstalled(const std::string& filePath)
+{
+    if (isNPPlugin(filePath))
+    {
+        if (!isValidNPPlugin(filePath))
+        {
+            LogDebug("Not a valid NPRuntime plug-in: " << filePath);
+            return false;
+        }
+    }
+    return true;
+}
 }
 
 namespace Jobs {
@@ -98,44 +128,51 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
     // Extract file or path
     std::string fileName = m_zipIterator->name;
 
-    if (fileName[fileName.size() - 1] == '/') {
-        // This is path
-        std::string newPath = destination + "/" +
-            fileName.substr(0, fileName.size() - 1);
-        LogPedantic("Path to extract: " << newPath);
-
-        // Create path in case of it is empty
-        createTempPath(newPath);
-    } else {
-        // This is regular file
-        std::string fileExtractPath = destination + "/" + fileName;
-
-        LogPedantic("File to extract: " << fileExtractPath);
-
-        // Split into pat & file pair
-        PathAndFilePair pathAndFile = SplitFileAndPath(fileExtractPath);
-
-        LogPedantic("Path and file: " <<
-                    pathAndFile.path <<
-                    " : " << pathAndFile.file);
-
-        // First, ensure that path exists
-        createTempPath(pathAndFile.path);
-
-        Try
-        {
-            // Open file
-            std::unique_ptr<DPL::ZipInput::File> file(
-                m_zip->OpenFile(fileName));
-
-            // Extract single file
-            ExtractFile(file.get(), fileExtractPath);
-        }
-        Catch(DPL::ZipInput::Exception::OpenFileFailed)
-        {
-            ThrowMsg(Exceptions::ExtractFileFailed, fileName);
+    if (shouldBeInstalled(m_zipIterator->name))
+    {
+        if (fileName[fileName.size() - 1] == '/') {
+            // This is path
+            std::string newPath = destination + "/" +
+                fileName.substr(0, fileName.size() - 1);
+            LogPedantic("Path to extract: " << newPath);
+
+            // Create path in case of it is empty
+            createTempPath(newPath);
+        } else {
+            // This is regular file
+            std::string fileExtractPath = destination + "/" + fileName;
+
+            LogPedantic("File to extract: " << fileExtractPath);
+
+            // Split into pat & file pair
+            PathAndFilePair pathAndFile = SplitFileAndPath(fileExtractPath);
+
+            LogPedantic("Path and file: " <<
+                        pathAndFile.path <<
+                        " : " << pathAndFile.file);
+
+            // First, ensure that path exists
+            createTempPath(pathAndFile.path);
+
+            Try
+            {
+                // Open file
+                std::unique_ptr<DPL::ZipInput::File> file(
+                    m_zip->OpenFile(fileName));
+
+                // Extract single file
+                ExtractFile(file.get(), fileExtractPath);
+            }
+            Catch(DPL::ZipInput::Exception::OpenFileFailed)
+            {
+                ThrowMsg(Exceptions::ExtractFileFailed, fileName);
+            }
         }
     }
+    else
+    {
+        LogDebug("Skipping file: " << m_zipIterator->name);
+    }
 
     // Check whether there are more files to extract
     if (++m_zipIterator == m_zip->end()) {