pmt: apply version 1.7.0 changes

This commit is contained in:
2024-04-09 23:54:01 +03:00
committed by GitHub
parent dd6c1c9faf
commit c46a65607b

View File

@@ -1,13 +1,3 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include "include/common.h"
/* By YZBruh */ /* By YZBruh */
/* /*
@@ -26,18 +16,33 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include "include/pmt.h"
extern char *out; extern char *out;
extern char *outdir; extern char *outdir;
extern char *cust_cxt; extern char *cust_cxt;
extern bool use_logical; extern bool pmt_use_logical;
extern bool use_cust_cxt; extern bool pmt_use_cust_cxt;
extern bool pmt_force_mode;
/* backupper func */ /* backupper func */
void backup(char *target_backup_partition, char *backup_partition_style) void backup(char *target_backup_partition, char *backup_partition_style)
{ {
static char backupper_path[200]; static char backupper_path[200];
if (strstr(backup_partition_style, "classic") != NULL) { if (strstr(backup_partition_style, "classic") != NULL) {
if (use_cust_cxt) { if (pmt_use_cust_cxt) {
sprintf(backupper_path, "%s/%s", cust_cxt, target_backup_partition); sprintf(backupper_path, "%s/%s", cust_cxt, target_backup_partition);
} else { } else {
sprintf(backupper_path, "/dev/block/by-name/%s", target_backup_partition); sprintf(backupper_path, "/dev/block/by-name/%s", target_backup_partition);
@@ -45,13 +50,19 @@ void backup(char *target_backup_partition, char *backup_partition_style)
} else if (strstr(backup_partition_style, "logical") != NULL) { } else if (strstr(backup_partition_style, "logical") != NULL) {
sprintf(backupper_path, "/dev/block/mapper/%s", target_backup_partition); sprintf(backupper_path, "/dev/block/mapper/%s", target_backup_partition);
} else { } else {
error("İnvalid partition type!\n"); if (!pmt_force_mode) {
error("İnvalid partition type!\n", 28);
} else {
exit(28);
}
} }
if (access(backupper_path, F_OK) == -1) { if (access(backupper_path, F_OK) == -1) {
error("Partition not found!\n"); if (!pmt_force_mode) {
} else { error("Partition not found!\n", 29);
printf("Target partition: %s\nBackupping...\n", target_backup_partition); } else {
exit(29);
}
} }
static char backupper_cmd[256]; static char backupper_cmd[256];
@@ -70,7 +81,11 @@ void backup(char *target_backup_partition, char *backup_partition_style)
} }
if (system(backupper_cmd) != 0) { if (system(backupper_cmd) != 0) {
error("Failed!\n"); if (!pmt_force_mode) {
error("Failed!\n", 99);
} else {
exit(EXIT_FAILURE);
}
} else { } else {
if (outdir != NULL) { if (outdir != NULL) {
if (out != NULL) { if (out != NULL) {
@@ -85,8 +100,11 @@ void backup(char *target_backup_partition, char *backup_partition_style)
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_backup_partition, ANSI_RESET); printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_backup_partition, ANSI_RESET);
} }
} }
} }
} }
#ifdef __cplusplus
}
#endif
/* end of code */ /* end of code */