diff options
author | Michael Runge <mrunge@google.com> | 2013-11-07 23:55:51 +0100 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-11-07 23:55:51 +0100 |
commit | c64e76c75088b951f61a7f7bacf8af6eccd2ccfa (patch) | |
tree | 9a07575896cd084298b65bf9c35fe3d8e50e03bc /updater | |
parent | merge in klp-release (no-op) (diff) | |
parent | Enable incremental builder to find files that moved, and (diff) | |
download | android_bootable_recovery-c64e76c75088b951f61a7f7bacf8af6eccd2ccfa.tar android_bootable_recovery-c64e76c75088b951f61a7f7bacf8af6eccd2ccfa.tar.gz android_bootable_recovery-c64e76c75088b951f61a7f7bacf8af6eccd2ccfa.tar.bz2 android_bootable_recovery-c64e76c75088b951f61a7f7bacf8af6eccd2ccfa.tar.lz android_bootable_recovery-c64e76c75088b951f61a7f7bacf8af6eccd2ccfa.tar.xz android_bootable_recovery-c64e76c75088b951f61a7f7bacf8af6eccd2ccfa.tar.zst android_bootable_recovery-c64e76c75088b951f61a7f7bacf8af6eccd2ccfa.zip |
Diffstat (limited to 'updater')
-rw-r--r-- | updater/install.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/updater/install.c b/updater/install.c index 0a859452a..9fb1b63d7 100644 --- a/updater/install.c +++ b/updater/install.c @@ -285,6 +285,40 @@ done: return StringValue(result); } +Value* RenameFn(const char* name, State* state, int argc, Expr* argv[]) { + char* result = NULL; + if (argc != 2) { + return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc); + } + + char* src_name; + char* dst_name; + + if (ReadArgs(state, argv, 2, &src_name, &dst_name) < 0) { + return NULL; + } + if (strlen(src_name) == 0) { + ErrorAbort(state, "src_name argument to %s() can't be empty", name); + goto done; + } + if (strlen(dst_name) == 0) { + ErrorAbort(state, "dst_name argument to %s() can't be empty", + name); + goto done; + } + + if (rename(src_name, dst_name) != 0) { + ErrorAbort(state, "Rename of %s() to %s() failed, error %s()", + src_name, dst_name, strerror(errno)); + } else { + result = dst_name; + } + +done: + free(src_name); + if (result != dst_name) free(dst_name); + return StringValue(result); +} Value* DeleteFn(const char* name, State* state, int argc, Expr* argv[]) { char** paths = malloc(argc * sizeof(char*)); @@ -1425,6 +1459,7 @@ void RegisterInstallFunctions() { RegisterFunction("read_file", ReadFileFn); RegisterFunction("sha1_check", Sha1CheckFn); + RegisterFunction("rename", RenameFn); RegisterFunction("wipe_cache", WipeCacheFn); |