summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-09 20:31:18 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-09 20:31:18 +0100
commit7fbc9d39f3c927a1763d37cc3076fbcb7138b574 (patch)
treeafcf1a8d123ea65f97df1b1f72be80c475240b8a /updater
parentMerge "otautil: Clean up obsolete includes." am: b80d136dca am: b50fa1fc23 am: d9d435cd83 (diff)
parentMerge "updater: Add more testcase for symlink()." am: 1b74e8cea8 am: 2c175c302c (diff)
downloadandroid_bootable_recovery-7fbc9d39f3c927a1763d37cc3076fbcb7138b574.tar
android_bootable_recovery-7fbc9d39f3c927a1763d37cc3076fbcb7138b574.tar.gz
android_bootable_recovery-7fbc9d39f3c927a1763d37cc3076fbcb7138b574.tar.bz2
android_bootable_recovery-7fbc9d39f3c927a1763d37cc3076fbcb7138b574.tar.lz
android_bootable_recovery-7fbc9d39f3c927a1763d37cc3076fbcb7138b574.tar.xz
android_bootable_recovery-7fbc9d39f3c927a1763d37cc3076fbcb7138b574.tar.zst
android_bootable_recovery-7fbc9d39f3c927a1763d37cc3076fbcb7138b574.zip
Diffstat (limited to 'updater')
-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 {