diff options
author | Michael Runge <mrunge@google.com> | 2013-11-07 02:42:20 +0100 |
---|---|---|
committer | Andreas Blaesius <skate4life@gmx.de> | 2017-08-13 20:43:17 +0200 |
commit | 3a0cf82a5d967957a21f5fb0164107e17a494015 (patch) | |
tree | 511ea384dee79b17ce97846068d498b74497d396 /updater/install.c | |
parent | Fix mkexfatfs exclusion when TW_NO_EXFAT enabled (diff) | |
download | android_bootable_recovery-3a0cf82a5d967957a21f5fb0164107e17a494015.tar android_bootable_recovery-3a0cf82a5d967957a21f5fb0164107e17a494015.tar.gz android_bootable_recovery-3a0cf82a5d967957a21f5fb0164107e17a494015.tar.bz2 android_bootable_recovery-3a0cf82a5d967957a21f5fb0164107e17a494015.tar.lz android_bootable_recovery-3a0cf82a5d967957a21f5fb0164107e17a494015.tar.xz android_bootable_recovery-3a0cf82a5d967957a21f5fb0164107e17a494015.tar.zst android_bootable_recovery-3a0cf82a5d967957a21f5fb0164107e17a494015.zip |
Diffstat (limited to 'updater/install.c')
-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 ff4dd5829..48791ede9 100644 --- a/updater/install.c +++ b/updater/install.c @@ -286,6 +286,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*)); @@ -1374,6 +1408,7 @@ void RegisterInstallFunctions() { RegisterFunction("read_file", ReadFileFn); RegisterFunction("sha1_check", Sha1CheckFn); + RegisterFunction("rename", RenameFn); RegisterFunction("wipe_cache", WipeCacheFn); |