[Archive] Fixes for TCTs
authorPiotr Kosko <p.kosko@samsung.com>
Tue, 30 Dec 2014 11:08:19 +0000 (12:08 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Tue, 30 Dec 2014 11:37:28 +0000 (12:37 +0100)
[Verification] TCT passrate 97/105

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

index 3dd131700a9273ee6d23736c02ca10f2e9696150..80931e64d72d4fc7449d9fe707436bc2eeea67fb 100644 (file)
@@ -72,6 +72,12 @@ CommonFS.toRealPath = function(aPath) {
     return _fileRealPath;
 };
 
+CommonFS.isVirtualPath = function(aPath) {
+    var root = aPath.split("/")[0];
+
+    return this.cacheVirtualToReal[root] != undefined;
+};
+
 /**
  * Returns new unique opId
  */
@@ -173,6 +179,9 @@ ArchiveFileEntry.prototype.extract = function () {
     ]),
     opId = getNextOpId();
 
+    if (!CommonFS.isVirtualPath(args.destinationDirectory)) //TODO: add FileReferece validation
+        throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+                "Destination directory should be virtual path or file.");
     bridge.async({
         cmd: 'ArchiveFileEntry_extract',
         args: {
@@ -248,6 +257,10 @@ ArchiveFile.prototype.add = function () {
     ]),
     opId = getNextOpId();
 
+    if (!CommonFS.isVirtualPath(args.sourceFile)) //TODO: add FileReferece validation
+        throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+                "sourceFile should be virtual path or file.");
+
     var optionsAttributes = ["destination", "stripSourceDirectory", "compressionLevel"],
         options = args.options || {};
 
@@ -307,6 +320,10 @@ ArchiveFile.prototype.extractAll = function () {
     ]),
     opId = getNextOpId();
 
+    if (!CommonFS.isVirtualPath(args.destinationDirectory)) //TODO: add FileReferece validation
+        throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+                "destinationDirectory should be virtual path or file.");
+
     bridge.async({
         cmd: 'ArchiveFile_extractAll',
         args: {
@@ -453,6 +470,10 @@ ArchiveManager.prototype.open = function () {
         }
     }
 
+    if (!CommonFS.isVirtualPath(args.file)) //TODO: add FileReferece validation
+        throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+                "file should be virtual path or file.");
+
     bridge.async({
         cmd: 'ArchiveManager_open',
         args: {
index c8cc7f4e7e5d9936f276ee2babae19b473927243..a7bf62ca52c7dd99edda9a7f6bbd2dc7735ae755 100644 (file)
@@ -394,10 +394,13 @@ void ArchiveInstance::Close(const picojson::value& args, picojson::object& out)
 
     const long handle = static_cast<long>(v_handle.get<double>());
 
-    ArchiveFilePtr priv = ArchiveManager::getInstance().getPrivData(handle);
-    priv->close();
-    ArchiveManager::getInstance().erasePrivData(handle);
-
+    try {
+        ArchiveFilePtr priv = ArchiveManager::getInstance().getPrivData(handle);
+        priv->close();
+        ArchiveManager::getInstance().erasePrivData(handle);
+    } catch (...) {
+        LoggerD("Close method was called on already closed archive. Just end execution");
+    }
     ReportSuccess(out);
 }