Merge "Avoid overwrite of the error message in AbortFn"
This commit is contained in:
@@ -114,9 +114,9 @@ Value* IfElseFn(const char* name, State* state, const std::vector<std::unique_pt
|
|||||||
Value* AbortFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) {
|
Value* AbortFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
if (!argv.empty() && Evaluate(state, argv[0], &msg)) {
|
if (!argv.empty() && Evaluate(state, argv[0], &msg)) {
|
||||||
state->errmsg = msg;
|
state->errmsg += msg;
|
||||||
} else {
|
} else {
|
||||||
state->errmsg = "called abort()";
|
state->errmsg += "called abort()";
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -410,12 +410,15 @@ Value* ErrorAbort(State* state, const char* format, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
|
Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
|
||||||
va_list ap;
|
std::string err_message;
|
||||||
va_start(ap, format);
|
va_list ap;
|
||||||
android::base::StringAppendV(&state->errmsg, format, ap);
|
va_start(ap, format);
|
||||||
va_end(ap);
|
android::base::StringAppendV(&err_message, format, ap);
|
||||||
state->cause_code = cause_code;
|
va_end(ap);
|
||||||
return nullptr;
|
// Ensure that there's exactly one line break at the end of the error message.
|
||||||
|
state->errmsg = android::base::Trim(err_message) + "\n";
|
||||||
|
state->cause_code = cause_code;
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
State::State(const std::string& script, void* cookie)
|
State::State(const std::string& script, void* cookie)
|
||||||
|
|||||||
@@ -817,7 +817,7 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& blockd
|
|||||||
size_t max_stash_size = maxblocks * BLOCKSIZE;
|
size_t max_stash_size = maxblocks * BLOCKSIZE;
|
||||||
|
|
||||||
if (res == -1 && errno != ENOENT) {
|
if (res == -1 && errno != ENOENT) {
|
||||||
ErrorAbort(state, kStashCreationFailure, "stat \"%s\" failed: %s\n", dirname.c_str(),
|
ErrorAbort(state, kStashCreationFailure, "stat \"%s\" failed: %s", dirname.c_str(),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else if (res != 0) {
|
} else if (res != 0) {
|
||||||
@@ -825,19 +825,19 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& blockd
|
|||||||
res = mkdir(dirname.c_str(), STASH_DIRECTORY_MODE);
|
res = mkdir(dirname.c_str(), STASH_DIRECTORY_MODE);
|
||||||
|
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
ErrorAbort(state, kStashCreationFailure, "mkdir \"%s\" failed: %s\n", dirname.c_str(),
|
ErrorAbort(state, kStashCreationFailure, "mkdir \"%s\" failed: %s", dirname.c_str(),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chown(dirname.c_str(), AID_SYSTEM, AID_SYSTEM) != 0) { // system user
|
if (chown(dirname.c_str(), AID_SYSTEM, AID_SYSTEM) != 0) { // system user
|
||||||
ErrorAbort(state, kStashCreationFailure, "chown \"%s\" failed: %s\n", dirname.c_str(),
|
ErrorAbort(state, kStashCreationFailure, "chown \"%s\" failed: %s", dirname.c_str(),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CacheSizeCheck(max_stash_size) != 0) {
|
if (CacheSizeCheck(max_stash_size) != 0) {
|
||||||
ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu needed)\n",
|
ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu needed)",
|
||||||
max_stash_size);
|
max_stash_size);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -869,7 +869,7 @@ static int CreateStash(State* state, size_t maxblocks, const std::string& blockd
|
|||||||
if (max_stash_size > existing) {
|
if (max_stash_size > existing) {
|
||||||
size_t needed = max_stash_size - existing;
|
size_t needed = max_stash_size - existing;
|
||||||
if (CacheSizeCheck(needed) != 0) {
|
if (CacheSizeCheck(needed) != 0) {
|
||||||
ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu more needed)\n",
|
ErrorAbort(state, kStashCreationFailure, "not enough space for stash (%zu more needed)",
|
||||||
needed);
|
needed);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1517,7 +1517,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
|
|||||||
|
|
||||||
std::vector<std::string> lines = android::base::Split(transfer_list_value->data, "\n");
|
std::vector<std::string> lines = android::base::Split(transfer_list_value->data, "\n");
|
||||||
if (lines.size() < 2) {
|
if (lines.size() < 2) {
|
||||||
ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zd]\n",
|
ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zd]",
|
||||||
lines.size());
|
lines.size());
|
||||||
return StringValue("");
|
return StringValue("");
|
||||||
}
|
}
|
||||||
@@ -1533,7 +1533,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
|
|||||||
// Second line in transfer list is the total number of blocks we expect to write.
|
// Second line in transfer list is the total number of blocks we expect to write.
|
||||||
size_t total_blocks;
|
size_t total_blocks;
|
||||||
if (!android::base::ParseUint(lines[1], &total_blocks)) {
|
if (!android::base::ParseUint(lines[1], &total_blocks)) {
|
||||||
ErrorAbort(state, kArgsParsingFailure, "unexpected block count [%s]\n", lines[1].c_str());
|
ErrorAbort(state, kArgsParsingFailure, "unexpected block count [%s]", lines[1].c_str());
|
||||||
return StringValue("");
|
return StringValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1543,7 +1543,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
|
|||||||
|
|
||||||
size_t start = 2;
|
size_t start = 2;
|
||||||
if (lines.size() < 4) {
|
if (lines.size() < 4) {
|
||||||
ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]\n",
|
ErrorAbort(state, kArgsParsingFailure, "too few lines in the transfer list [%zu]",
|
||||||
lines.size());
|
lines.size());
|
||||||
return StringValue("");
|
return StringValue("");
|
||||||
}
|
}
|
||||||
@@ -1554,7 +1554,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
|
|||||||
// Fourth line is the maximum number of blocks that will be stashed simultaneously
|
// Fourth line is the maximum number of blocks that will be stashed simultaneously
|
||||||
size_t stash_max_blocks;
|
size_t stash_max_blocks;
|
||||||
if (!android::base::ParseUint(lines[3], &stash_max_blocks)) {
|
if (!android::base::ParseUint(lines[3], &stash_max_blocks)) {
|
||||||
ErrorAbort(state, kArgsParsingFailure, "unexpected maximum stash blocks [%s]\n",
|
ErrorAbort(state, kArgsParsingFailure, "unexpected maximum stash blocks [%s]",
|
||||||
lines[3].c_str());
|
lines[3].c_str());
|
||||||
return StringValue("");
|
return StringValue("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ Value* FormatFn(const char* name, State* state, const std::vector<std::unique_pt
|
|||||||
|
|
||||||
int64_t size;
|
int64_t size;
|
||||||
if (!android::base::ParseInt(fs_size, &size)) {
|
if (!android::base::ParseInt(fs_size, &size)) {
|
||||||
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s\n", name,
|
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s", name,
|
||||||
fs_size.c_str());
|
fs_size.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,12 +352,12 @@ Value* ShowProgressFn(const char* name, State* state,
|
|||||||
|
|
||||||
double frac;
|
double frac;
|
||||||
if (!android::base::ParseDouble(frac_str.c_str(), &frac)) {
|
if (!android::base::ParseDouble(frac_str.c_str(), &frac)) {
|
||||||
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s\n", name,
|
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s", name,
|
||||||
frac_str.c_str());
|
frac_str.c_str());
|
||||||
}
|
}
|
||||||
int sec;
|
int sec;
|
||||||
if (!android::base::ParseInt(sec_str.c_str(), &sec)) {
|
if (!android::base::ParseInt(sec_str.c_str(), &sec)) {
|
||||||
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s\n", name,
|
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s", name,
|
||||||
sec_str.c_str());
|
sec_str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ Value* SetProgressFn(const char* name, State* state, const std::vector<std::uniq
|
|||||||
|
|
||||||
double frac;
|
double frac;
|
||||||
if (!android::base::ParseDouble(frac_str.c_str(), &frac)) {
|
if (!android::base::ParseDouble(frac_str.c_str(), &frac)) {
|
||||||
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s\n", name,
|
return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s", name,
|
||||||
frac_str.c_str());
|
frac_str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,8 +574,8 @@ Value* ApplyPatchSpaceFn(const char* name, State* state, const std::vector<std::
|
|||||||
|
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
if (!android::base::ParseUint(bytes_str.c_str(), &bytes)) {
|
if (!android::base::ParseUint(bytes_str.c_str(), &bytes)) {
|
||||||
return ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count\n\n",
|
return ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count", name,
|
||||||
name, bytes_str.c_str());
|
bytes_str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip the cache size check if the update is a retry.
|
// Skip the cache size check if the update is a retry.
|
||||||
|
|||||||
Reference in New Issue
Block a user