AB Cache dir: If device doesn't have /data/cache for FBE, we should
try /persist if in the fstab.
Change-Id: I70dd19538b7f9b8cf61c46f6c8167057eec3342b
diff --git a/data.cpp b/data.cpp
index cf9dd24..9225535 100755
--- a/data.cpp
+++ b/data.cpp
@@ -1043,6 +1043,11 @@
char version[255];
std::string cacheDir = TWFunc::get_cache_dir();
+ if (cacheDir.empty()) {
+ LOGINFO("Unable to find cache directory\n");
+ return;
+ }
+
std::string recoveryCacheDir = cacheDir + "recovery/";
if (cacheDir == NON_AB_CACHE_DIR) {
@@ -1053,7 +1058,7 @@
}
if (!TWFunc::Path_Exists(recoveryCacheDir)) {
LOGINFO("Recreating %s folder.\n", recoveryCacheDir.c_str());
- if (mkdir(recoveryCacheDir.c_str(), S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) {
+ if (!TWFunc::Create_Dir_Recursive(recoveryCacheDir.c_str(), S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP, 0, 0)) {
LOGERR("DataManager::Output_Version -- Unable to make %s: %s\n", recoveryCacheDir.c_str(), strerror(errno));
return;
}
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 26a48e5..34ba6ae 100755
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -2222,7 +2222,13 @@
void TWPartitionManager::Output_Storage_Fstab(void) {
std::vector<TWPartition*>::iterator iter;
char storage_partition[255];
- string Temp;
+ std::string Temp;
+ std::string cacheDir = TWFunc::get_cache_dir();
+
+ if (cacheDir.empty()) {
+ LOGINFO("Unable to find cache directory\n");
+ return;
+ }
std::string storageFstab = TWFunc::get_cache_dir() + "recovery/storage.fstab";
FILE *fp = fopen(storageFstab.c_str(), "w");
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 0730ca8..28a0f0c 100755
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -535,7 +535,7 @@
if (!TWFunc::Path_Exists(recoveryDir)) {
LOGINFO("Recreating %s folder.\n", recoveryDir.c_str());
- if (mkdir(recoveryDir.c_str(), S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) {
+ if (!Create_Dir_Recursive(recoveryDir, S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP, 0, 0)) {
LOGINFO("Unable to create %s folder.\n", recoveryDir.c_str());
}
}
@@ -1171,7 +1171,15 @@
std::string TWFunc::get_cache_dir() {
if (PartitionManager.Find_Partition_By_Path(NON_AB_CACHE_DIR) == NULL) {
- return AB_CACHE_DIR;
+ if (PartitionManager.Find_Partition_By_Path(NON_AB_CACHE_DIR) == NULL) {
+ if (PartitionManager.Find_Partition_By_Path(PERSIST_CACHE_DIR) == NULL) {
+ LOGINFO("Unable to find a directory to store TWRP logs.");
+ return "";
+ }
+ return PERSIST_CACHE_DIR;
+ } else {
+ return AB_CACHE_DIR;
+ }
}
else {
return NON_AB_CACHE_DIR;
diff --git a/twrp-functions.hpp b/twrp-functions.hpp
index 669a9e9..a892e75 100755
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -28,6 +28,7 @@
#define NON_AB_CACHE_DIR "/cache/"
#define AB_CACHE_DIR "/data/cache/"
+#define PERSIST_CACHE_DIR "/persist/cache/"
typedef enum
{