From 533a5a2cbf9f276821503d8d6c8a2c351a656e3d Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 31 Jul 2013 15:57:37 +0200 Subject: [PATCH] luci2: add backup_restore and backup_clean calls, rename upgrade_abort to upgrade_clean --- luci2.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/luci2.c b/luci2.c index ae36e42..502ef85 100644 --- a/luci2.c +++ b/luci2.c @@ -964,11 +964,35 @@ rpc_luci2_upgrade_start(struct ubus_context *ctx, struct ubus_object *obj, } static int -rpc_luci2_upgrade_abort(struct ubus_context *ctx, struct ubus_object *obj, +rpc_luci2_upgrade_clean(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - unlink("/tmp/firmware.bin"); + if (unlink("/tmp/firmware.bin")) + return rpc_errno_status(); + + return 0; +} + +static int +rpc_luci2_backup_restore(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + const char *cmd[4] = { "sysupgrade", "--restore-backup", + "/tmp/backup.tar.gz", NULL }; + + return rpc_exec(cmd, NULL, NULL, NULL, NULL, ctx, req); +} + +static int +rpc_luci2_backup_clean(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + if (unlink("/tmp/backup.tar.gz")) + return rpc_errno_status(); + return 0; } @@ -1768,7 +1792,9 @@ int rpc_luci2_api_init(struct ubus_context *ctx) UBUS_METHOD_NOARG("upgrade_test", rpc_luci2_upgrade_test), UBUS_METHOD("upgrade_start", rpc_luci2_upgrade_start, rpc_upgrade_policy), - UBUS_METHOD_NOARG("upgrade_abort", rpc_luci2_upgrade_abort) + UBUS_METHOD_NOARG("upgrade_clean", rpc_luci2_upgrade_clean), + UBUS_METHOD_NOARG("backup_restore", rpc_luci2_backup_restore), + UBUS_METHOD_NOARG("backup_clean", rpc_luci2_backup_clean) }; static struct ubus_object_type luci2_system_type =