AB/Non AB Devices: updates for moving cache

This patchset updates all the places we touch cache on AB devices
and non AB devices so that we can write to the appropriate
location. AB devices removed the cache partition and moved it to
/data/cache.

Change-Id: I485ec205a604f1f07ceb7700ae9c4e720fd55c3e
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
old mode 100644
new mode 100755
index 45460d1..b8a95ff
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -1343,9 +1343,14 @@
 		return false;
 
 	dir.push_back("/data/dalvik-cache");
-	if (Mount_By_Path("/cache", false)) {
-		dir.push_back("/cache/dalvik-cache");
-		dir.push_back("/cache/dc");
+
+	std::string cacheDir = TWFunc::get_cache_dir();
+	if (cacheDir == NON_AB_CACHE_DIR) {
+		if (!PartitionManager.Mount_By_Path(NON_AB_CACHE_DIR, false)) {
+			LOGINFO("Unable to mount %s for wiping cache.\n", NON_AB_CACHE_DIR);
+		}
+		dir.push_back(cacheDir + "dalvik-cache");
+		dir.push_back(cacheDir + "/dc");
 	}
 
 	TWPartition* sdext = Find_Partition_By_Path("/sd-ext");
@@ -1357,14 +1362,24 @@
 		}
 	}
 
-	gui_msg("wiping_dalvik=Wiping Dalvik Cache Directories...");
+	if (cacheDir == NON_AB_CACHE_DIR) {
+		gui_msg("wiping_cache_dalvik=Wiping Dalvik Cache Directories...");
+	} else {
+		gui_msg("wiping_dalvik=Wiping Dalvik Directory...");
+	}
 	for (unsigned i = 0; i < dir.size(); ++i) {
 		if (stat(dir.at(i).c_str(), &st) == 0) {
 			TWFunc::removeDir(dir.at(i), false);
 			gui_msg(Msg("cleaned=Cleaned: {1}...")(dir.at(i)));
 		}
 	}
-	gui_msg("dalvik_done=-- Dalvik Cache Directories Wipe Complete!");
+
+	if (cacheDir == NON_AB_CACHE_DIR) {
+		gui_msg("cache_dalvik_done=-- Dalvik Cache Directories Wipe Complete!");
+	} else {
+		gui_msg("dalvik_done=-- Dalvik Directory Wipe Complete!");
+	}
+
 	return true;
 }
 
@@ -2194,10 +2209,12 @@
 	std::vector<TWPartition*>::iterator iter;
 	char storage_partition[255];
 	string Temp;
-	FILE *fp = fopen("/cache/recovery/storage.fstab", "w");
+
+	std::string storageFstab = TWFunc::get_cache_dir() + "recovery/storage.fstab";
+	FILE *fp = fopen(storageFstab.c_str(), "w");
 
 	if (fp == NULL) {
-		gui_msg(Msg(msg::kError, "unable_to_open=Unable to open '{1}'.")("/cache/recovery/storage.fstab"));
+		gui_msg(Msg(msg::kError, "unable_to_open=Unable to open '{1}'.")(storageFstab));
 		return;
 	}