fix dir scanning bug during step unzip 98/32898/1
authorWonguk Jeong <wonguk.jeong@samsung.com>
Tue, 30 Dec 2014 08:40:08 +0000 (17:40 +0900)
committerWonguk Jeong <wonguk.jeong@samsung.com>
Tue, 30 Dec 2014 09:03:57 +0000 (18:03 +0900)
Scan iterator has been stopped on directory.
"unzGoToNextFile" was never invoked in case of directory file.

Change-Id: I66cf31eb7fa56720d1be7b0b56072780e1c2f542
Signed-off-by: Wonguk Jeong <wonguk.jeong@samsung.com>
common/src/step/step_unzip.cc

index 25d0e1c..be61d90 100644 (file)
@@ -94,30 +94,28 @@ int StepUnzip::ExtractToTmpDir(const char* src,
       return APPINST_R_ERROR;
     }
 
-    // Do not treat directory
-    if (is_directory(filename_in_zip_path))
-      continue;
-
-    FILE *out = fopen(raw_file_name_in_zip, "wb");
-    if (!out) {
-      ERR("Failed to open destination ");
-      unzCloseCurrentFile(zip_file);
-      return APPINST_R_ERROR;
-    }
-
-    int ret = UNZ_OK;
-    do {
-      ret = unzReadCurrentFile(zip_file, read_buffer, ZIPBUFSIZE);
-      if (ret < 0) {
-        ERR("Failed to read data: " << ret);
+    if (!is_directory(filename_in_zip_path)) {
+      FILE *out = fopen(raw_file_name_in_zip, "wb");
+      if (!out) {
+        ERR("Failed to open destination ");
         unzCloseCurrentFile(zip_file);
         return APPINST_R_ERROR;
-      } else {
-        fwrite(read_buffer, sizeof(char), ret, out);
       }
-    } while (ret > 0);
 
-    fclose(out);
+      int ret = UNZ_OK;
+      do {
+        ret = unzReadCurrentFile(zip_file, read_buffer, ZIPBUFSIZE);
+        if (ret < 0) {
+          ERR("Failed to read data: " << ret);
+          unzCloseCurrentFile(zip_file);
+          return APPINST_R_ERROR;
+        } else {
+          fwrite(read_buffer, sizeof(char), ret, out);
+        }
+      } while (ret > 0);
+
+      fclose(out);
+    }
 
     if ((i+1) < info.number_entry) {
       if (unzGoToNextFile(zip_file) != UNZ_OK) {