summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-09 20:13:43 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-09 20:13:43 +0100
commit2c175c302cb0fefe3474ca6bc7d3c910d6289208 (patch)
tree110082ab1470a025b565fb4bd78ec14fefd967d8 /updater
parentMerge "otautil: Clean up obsolete includes." (diff)
parentMerge "updater: Add more testcase for symlink()." (diff)
downloadandroid_bootable_recovery-2c175c302cb0fefe3474ca6bc7d3c910d6289208.tar
android_bootable_recovery-2c175c302cb0fefe3474ca6bc7d3c910d6289208.tar.gz
android_bootable_recovery-2c175c302cb0fefe3474ca6bc7d3c910d6289208.tar.bz2
android_bootable_recovery-2c175c302cb0fefe3474ca6bc7d3c910d6289208.tar.lz
android_bootable_recovery-2c175c302cb0fefe3474ca6bc7d3c910d6289208.tar.xz
android_bootable_recovery-2c175c302cb0fefe3474ca6bc7d3c910d6289208.tar.zst
android_bootable_recovery-2c175c302cb0fefe3474ca6bc7d3c910d6289208.zip
Diffstat (limited to '')
-rw-r--r--updater/install.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/updater/install.cpp b/updater/install.cpp
index cba95f5b0..59c54dd4c 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -566,8 +566,9 @@ Value* PackageExtractFileFn(const char* name, State* state,
}
}
-// symlink target src1 src2 ...
-// unlinks any previously existing src1, src2, etc before creating symlinks.
+// symlink(target, [src1, src2, ...])
+// Creates all sources as symlinks to target. It unlinks any previously existing src1, src2, etc
+// before creating symlinks.
Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc == 0) {
return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1+ args, got %d", name, argc);
@@ -579,33 +580,29 @@ Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) {
std::vector<std::string> srcs;
if (!ReadArgs(state, argc-1, argv+1, &srcs)) {
- return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name);
+ return ErrorAbort(state, kArgsParsingFailure, "%s(): Failed to parse the argument(s)",
+ name);
}
- int bad = 0;
- for (int i = 0; i < argc-1; ++i) {
- if (unlink(srcs[i].c_str()) < 0) {
- if (errno != ENOENT) {
- printf("%s: failed to remove %s: %s\n",
- name, srcs[i].c_str(), strerror(errno));
- ++bad;
- }
- }
- if (!make_parents(srcs[i])) {
+ size_t bad = 0;
+ for (const auto& src : srcs) {
+ if (unlink(src.c_str()) == -1 && errno != ENOENT) {
+ printf("%s: failed to remove %s: %s\n", name, src.c_str(), strerror(errno));
+ ++bad;
+ } else if (!make_parents(src)) {
printf("%s: failed to symlink %s to %s: making parents failed\n",
- name, srcs[i].c_str(), target.c_str());
+ name, src.c_str(), target.c_str());
++bad;
- }
- if (symlink(target.c_str(), srcs[i].c_str()) < 0) {
+ } else if (symlink(target.c_str(), src.c_str()) == -1) {
printf("%s: failed to symlink %s to %s: %s\n",
- name, srcs[i].c_str(), target.c_str(), strerror(errno));
+ name, src.c_str(), target.c_str(), strerror(errno));
++bad;
}
}
- if (bad) {
- return ErrorAbort(state, kSymlinkFailure, "%s: some symlinks failed", name);
+ if (bad != 0) {
+ return ErrorAbort(state, kSymlinkFailure, "%s: Failed to create %zu symlink(s)", name, bad);
}
- return StringValue("");
+ return StringValue("t");
}
struct perm_parsed_args {