Create new Output file only for LS Scripts being executed

Creation of output file moved after Slot applet Hash check to make
sure new output files are created only for scripts which will be
executed and not for the one which are already done.

Bug: 109664165
Test: Ls Update
Change-Id: I94c3ff74641269dc6d6ad216dc2ad622bd389bbf
diff --git a/ls_client/src/LsClient.cpp b/ls_client/src/LsClient.cpp
index 57bbf97..50ea3d1 100755
--- a/ls_client/src/LsClient.cpp
+++ b/ls_client/src/LsClient.cpp
@@ -161,15 +161,6 @@
     ALOGD_IF(ese_debug_enabled, "%s File opened %s\n", __func__,
              sourcePath.c_str());
 
-    outPath.assign(ls_script_output_prefix);
-    outPath += ('0' + index);
-    outPath += ls_script_output_suffix;
-
-    FILE* fOut = fopen(outPath.c_str(), "wb+");
-    if (fOut == NULL) {
-      ALOGE("%s Failed to open file %s\n", __func__, outPath.c_str());
-      break;
-    }
     /*Read the script content to a local buffer*/
     fseek(fIn, 0, SEEK_END);
     long lsBufSize = ftell(fIn);
@@ -210,6 +201,18 @@
       continue;
     }
 
+    /*Create output file to write response data*/
+    outPath.assign(ls_script_output_prefix);
+    outPath += ('0' + index);
+    outPath += ls_script_output_suffix;
+
+    FILE* fOut = fopen(outPath.c_str(), "wb+");
+    if (fOut == NULL) {
+      ALOGE("%s Failed to open file %s\n", __func__, outPath.c_str());
+      break;
+    }
+    fclose(fOut);
+
     /*Uptdates current script*/
     status = LSC_Start(sourcePath.c_str(), outPath.c_str(), (uint8_t*)hash,
                        (uint16_t)sizeof(hash), resSW);