[Archive] Added support to options in ArchiveFile.add() method
authorPiotr Kosko <p.kosko@samsung.com>
Fri, 17 Apr 2015 09:15:46 +0000 (11:15 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 21 Apr 2015 08:42:58 +0000 (17:42 +0900)
[Feature] Options for ArchiveFile.add() method was not supported.
  Added support for destination, stripSourceDirectory and compressionLevel.

[Verification] Code compiles without errors.
  TCT passrate increased to 98.11%.

Change-Id: Iff1af6ef0e9e704b3820795b3c969d1c7ad331ff
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/archive/archive_instance.cc

index c6227538ab9b77347cf68b736aaf937e78ae1ac9..566d4ddebe7ad24c1c8b5e6dd684d5078fb134bc 100644 (file)
@@ -30,6 +30,15 @@ const std::string kPrivilegeFilesystemWrite  = "http://tizen.org/privilege/files
 const std::string kWgtPackagePathName = "wgt-package";
 const std::string kWgtPrivatePathName = "wgt-private";
 const std::string kWgtPrivateTmpPathName = "wgt-private-tmp";
+
+const std::string kArchiveFileEntryOptDest = "destination";
+const std::string kArchiveFileEntryOptStrip = "stripSourceDirectory";
+const std::string kArchiveFileEntryOptCompressionLevel = "compressionLevel";
+
+const std::string kNoCompressionStr = "STORE";
+const std::string kFastCompressionStr = "FAST";
+const std::string kNormalCompressionStr = "NORMAL";
+const std::string kBestCompressionStr = "BEST";
 } // namespace
 
 ArchiveInstance::ArchiveInstance() {
@@ -222,6 +231,18 @@ void ArchiveInstance::Abort(const picojson::value& args, picojson::object& out)
     ReportSuccess(out);
 }
 
+unsigned int ConvertStringToCompressionLevel(const std::string& level) {
+  if (kNoCompressionStr == level) {
+      return Z_NO_COMPRESSION;
+  } else if (kFastCompressionStr == level) {
+      return Z_BEST_SPEED;
+  } else if (kBestCompressionStr == level) {
+      return Z_BEST_COMPRESSION;
+  } else {
+      return Z_DEFAULT_COMPRESSION;
+  }
+}
+
 void ArchiveInstance::Add(const picojson::value& args, picojson::object& out)
 {
     LoggerD("Entered");
@@ -231,7 +252,7 @@ void ArchiveInstance::Add(const picojson::value& args, picojson::object& out)
 
     picojson::object data = args.get(JSON_DATA).get<picojson::object>();
     picojson::value v_source = data.at(PARAM_SOURCE_FILE);
-    //picojson::value v_options = data.at(PARAM_OPTIONS);
+    picojson::value v_options = data.at(PARAM_OPTIONS);
     picojson::value v_op_id = data.at(PARAM_OPERATION_ID);
     picojson::value v_handle = data.at(ARCHIVE_FILE_HANDLE);
 
@@ -259,6 +280,30 @@ void ArchiveInstance::Add(const picojson::value& args, picojson::object& out)
     callback->setFileEntry(afep);
 
     callback->setBasePath(file_ptr->getNode()->getPath()->getPath());
+
+    // check and set options
+    LoggerD("Processing OPTIONS dictionary: %s", v_options.serialize().c_str());
+    const auto& dest = v_options.get(kArchiveFileEntryOptDest);
+    if (dest.is<std::string>()) {
+      std::string dic_destination = dest.get<std::string>();
+      LoggerD("Setting destination path to: \"%s\"",dic_destination.c_str());
+      afep->setDestination(dic_destination);
+    }
+
+    const auto& strip = v_options.get(kArchiveFileEntryOptStrip);
+    if (strip.is<bool>()) {
+      bool dic_strip = strip.get<bool>();
+      LoggerD("Setting strip option to: %d", dic_strip);
+      afep->setStriped(dic_strip);
+    }
+
+    const auto& level = v_options.get(kArchiveFileEntryOptCompressionLevel);
+    if (level.is<std::string>()) {
+      std::string dic_compression_level = level.get<std::string>();
+      LoggerD("Setting compression level to: \"%s\"", dic_compression_level.c_str());
+      afep->setCompressionLevel(ConvertStringToCompressionLevel(dic_compression_level));
+    }
+
     LoggerD("base path:%s base virt:%s", callback->getBasePath().c_str(),
             callback->getBaseVirtualPath().c_str());