From 859bfc56597827ac7136cdd31c1b8e5469c81d18 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 25 Apr 2018 23:00:27 -0700 Subject: applypatch: Move to libbase logging. Test: mmma -j bootable/recovery Test: Run recovery_component_test on marlin. Change-Id: I3a4e32eb2c1e231c6690a50571edc66341b8d50a --- applypatch/applypatch_modes.cpp | 84 +++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 41 deletions(-) (limited to 'applypatch/applypatch_modes.cpp') diff --git a/applypatch/applypatch_modes.cpp b/applypatch/applypatch_modes.cpp index aa32d57ef..0728db9e3 100644 --- a/applypatch/applypatch_modes.cpp +++ b/applypatch/applypatch_modes.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -54,14 +55,14 @@ static bool ParsePatchArgs(int argc, const char** argv, std::vector for (int i = 0; i < argc; ++i) { std::vector pieces = android::base::Split(argv[i], ":"); if (pieces.size() != 2) { - printf("failed to parse patch argument \"%s\"\n", argv[i]); - return false; + LOG(ERROR) << "Failed to parse patch argument \"" << argv[i] << "\""; + return false; } uint8_t digest[SHA_DIGEST_LENGTH]; if (ParseSha1(pieces[0].c_str(), digest) != 0) { - printf("failed to parse sha1 \"%s\"\n", argv[i]); - return false; + LOG(ERROR) << "Failed to parse SHA-1 \"" << argv[i] << "\""; + return false; } sha1s->push_back(pieces[0]); @@ -85,8 +86,8 @@ static int PatchMode(int argc, const char** argv) { if (argc >= 3 && strcmp(argv[1], "-b") == 0) { if (LoadFileContents(argv[2], &bonusFc) != 0) { - printf("failed to load bonus file %s\n", argv[2]); - return 1; + LOG(ERROR) << "Failed to load bonus file " << argv[2]; + return 1; } bonus.type = VAL_BLOB; bonus.data = std::string(bonusFc.data.cbegin(), bonusFc.data.cend()); @@ -100,15 +101,15 @@ static int PatchMode(int argc, const char** argv) { size_t target_size; if (!android::base::ParseUint(argv[4], &target_size) || target_size == 0) { - printf("can't parse \"%s\" as byte count\n\n", argv[4]); - return 1; + LOG(ERROR) << "Failed to parse \"" << argv[4] << "\" as byte count"; + return 1; } // If no : is provided, it is in flash mode. if (argc == 5) { if (bonus.type != VAL_INVALID) { - printf("bonus file not supported in flash mode\n"); - return 1; + LOG(ERROR) << "bonus file not supported in flash mode"; + return 1; } return FlashMode(argv[1], argv[2], argv[3], target_size); } @@ -116,8 +117,8 @@ static int PatchMode(int argc, const char** argv) { std::vector sha1s; std::vector files; if (!ParsePatchArgs(argc-5, argv+5, &sha1s, &files)) { - printf("failed to parse patch args\n"); - return 1; + LOG(ERROR) << "Failed to parse patch args"; + return 1; } std::vector> patches; @@ -156,33 +157,34 @@ static int PatchMode(int argc, const char** argv) { // LoadPartitionContents() function for the format of such a filename. int applypatch_modes(int argc, const char** argv) { - if (argc < 2) { - usage: - printf( - "usage: %s [-b ] " - "[: ...]\n" - " or %s -c [ ...]\n" - " or %s -l\n" - "\n" - "Filenames may be of the form\n" - " EMMC::::::...\n" - "to specify reading from or writing to an EMMC partition.\n\n", - argv[0], argv[0], argv[0]); - return 2; - } - - int result; - - if (strncmp(argv[1], "-l", 3) == 0) { - result = ShowLicenses(); - } else if (strncmp(argv[1], "-c", 3) == 0) { - result = CheckMode(argc, argv); - } else { - result = PatchMode(argc, argv); - } - - if (result == 2) { - goto usage; - } - return result; + if (argc < 2) { + usage: + // clang-format off + LOG(INFO) << "Usage: \n" + << " " << argv[0] << " [-b ] " + " [: ...]\n" + << " " << argv[0] << " -c [ ...]\n" + << " " << argv[0] << " -l\n" + << "\n" + << "Filenames may be of the form\n" + << " EMMC::::::...\n" + << "to specify reading from or writing to an EMMC partition.\n\n"; + // clang-format on + return 2; + } + + int result; + + if (strncmp(argv[1], "-l", 3) == 0) { + result = ShowLicenses(); + } else if (strncmp(argv[1], "-c", 3) == 0) { + result = CheckMode(argc, argv); + } else { + result = PatchMode(argc, argv); + } + + if (result == 2) { + goto usage; + } + return result; } -- cgit v1.2.3