Skip to content

Commit

Permalink
AB Cache dir: If device doesn't have /data/cache for FBE, we should
Browse files Browse the repository at this point in the history
try /persist if in the fstab.

Change-Id: I70dd19538b7f9b8cf61c46f6c8167057eec3342b
  • Loading branch information
bigbiff authored and Dees-Troy committed Apr 3, 2019
1 parent 794e364 commit e4bdb15
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,11 @@ void DataManager::Output_Version(void)
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) {
Expand All @@ -1053,7 +1058,7 @@ void DataManager::Output_Version(void)
}
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;
}
Expand Down
8 changes: 7 additions & 1 deletion partitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,13 @@ int TWPartitionManager::Fstab_Processed(void) {
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");
Expand Down
12 changes: 10 additions & 2 deletions twrp-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ void TWFunc::Update_Log_File(void) {

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());
}
}
Expand Down Expand Up @@ -1171,7 +1171,15 @@ int TWFunc::stream_adb_backup(string &Restore_Name) {

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;
Expand Down
1 change: 1 addition & 0 deletions twrp-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace std;

#define NON_AB_CACHE_DIR "/cache/"
#define AB_CACHE_DIR "/data/cache/"
#define PERSIST_CACHE_DIR "/persist/cache/"

typedef enum
{
Expand Down

0 comments on commit e4bdb15

Please sign in to comment.