diff options
-rw-r--r-- | twrp-functions.cpp | 27 | ||||
-rw-r--r-- | updater/updater.c | 2 |
2 files changed, 20 insertions, 9 deletions
diff --git a/twrp-functions.cpp b/twrp-functions.cpp index 50df2ed9b..c39a6b242 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -261,6 +261,7 @@ unsigned long TWFunc::Get_File_Size(string Path) { } void TWFunc::Copy_Log(string Source, string Destination) { + PartitionManager.Mount_By_Path(Destination, false); FILE *destination_log = fopen(Destination.c_str(), "a"); if (destination_log == NULL) { LOGERR("TWFunc::Copy_Log -- Can't open destination log file: '%s'\n", Destination.c_str()); @@ -282,11 +283,20 @@ void TWFunc::Copy_Log(string Source, string Destination) { void TWFunc::Update_Log_File(void) { // Copy logs to cache so the system can find out what happened. - Copy_Log(TMP_LOG_FILE, "/cache/recovery/log"); - copy_file("/cache/recovery/log", "/cache/recovery/last_log", 600); - chown("/cache/recovery/log", 1000, 1000); - chmod("/cache/recovery/log", 0600); - chmod("/cache/recovery/last_log", 0640); + if (PartitionManager.Mount_By_Path("/cache", false)) { + if (!TWFunc::Path_Exists("/cache/recovery/.")) { + LOGINFO("Recreating /cache/recovery folder.\n"); + if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) + LOGINFO("Unable to create /cache/recovery folder.\n"); + } + Copy_Log(TMP_LOG_FILE, "/cache/recovery/log"); + copy_file("/cache/recovery/log", "/cache/recovery/last_log", 600); + chown("/cache/recovery/log", 1000, 1000); + chmod("/cache/recovery/log", 0600); + chmod("/cache/recovery/last_log", 0640); + } else { + LOGINFO("Failed to mount /cache for TWFunc::Update_Log_File\n"); + } // Reset bootloader message TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc"); @@ -304,11 +314,12 @@ void TWFunc::Update_Log_File(void) { } } - if (!PartitionManager.Mount_By_Path("/cache", true) || (unlink("/cache/recovery/command") && errno != ENOENT)) { - LOGINFO("Can't unlink %s\n", "/cache/recovery/command"); + if (PartitionManager.Mount_By_Path("/cache", true)) { + if (unlink("/cache/recovery/command") && errno != ENOENT) { + LOGINFO("Can't unlink %s\n", "/cache/recovery/command"); + } } - PartitionManager.UnMount_By_Path("/cache", true); sync(); } diff --git a/updater/updater.c b/updater/updater.c index 15d3d412f..7aa95e761 100644 --- a/updater/updater.c +++ b/updater/updater.c @@ -91,7 +91,7 @@ int main(int argc, char** argv) { script[script_entry->uncompLen] = '\0'; const ZipEntry* file_contexts_entry = mzFindZipEntry(&za, SELINUX_CONTEXTS_ZIP); - if (script_entry != NULL) { + if (file_contexts_entry != NULL) { int file_contexts_fd = creat(SELINUX_CONTEXTS_TMP, 0644); if (file_contexts_fd < 0) { fprintf(stderr, "Could not extract %s to '%s'\n", SELINUX_CONTEXTS_ZIP, SELINUX_CONTEXTS_TMP); |