extract-utils: Improve KEEP_DUMP logic when extracting from OTA

Change-Id: Ib5ad6e1bc3a7cefd6ffdee3bf1e0ff9840233129
diff --git a/extract_utils.sh b/extract_utils.sh
index 7211848..ef25afc 100644
--- a/extract_utils.sh
+++ b/extract_utils.sh
@@ -1543,7 +1543,14 @@
     local KEEP_DUMP_DIR="$SRC"
 
     if [ -f "$SRC" ] && [ "${SRC##*.}" == "zip" ]; then
+        local BASENAME=$(basename "$SRC")
+        local DIRNAME=$(dirname "$SRC")
         DUMPDIR="$EXTRACT_TMP_DIR"/system_dump
+        KEEP_DUMP_DIR="$DIRNAME"/"${BASENAME%.zip}"
+        if [ "$KEEP_DUMP" == "true" ] || [ "$KEEP_DUMP" == "1" ]; then
+            rm -rf "$KEEP_DUMP_DIR"
+            mkdir "$KEEP_DUMP_DIR"
+        fi
 
         # Check if we're working with the same zip that was passed last time.
         # If so, let's just use what's already extracted.
@@ -1583,11 +1590,6 @@
             done
         fi
 
-        if [ "$KEEP_DUMP" == "true" ] || [ "$KEEP_DUMP" == "1" ]; then
-            rm -rf "$KEEP_DUMP_DIR"/system_dump
-            cp -a "$DUMPDIR" "$KEEP_DUMP_DIR"/system_dump
-        fi
-
         SRC="$DUMPDIR"
     fi