summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-01-26 21:28:17 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-01-26 21:28:17 +0100
commitbfc9c138b1a9e87f9d387e2f900c14807c9da9b9 (patch)
tree14291b3d6f429157b04ff704e5504bfb2d59ac6c /src
parent9680a57f258d4118416104c224153a0292b7328e (diff)
Get the install directory
The function 'move_widget' was the only one that worried about the name of the installation directory. This commit split the function in two and enforce to get the name of the install directory. Change-Id: I6d89b4c94b2898a6ba95a3045b3f5db23d54c499 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/wgtpkg-install.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/wgtpkg-install.c b/src/wgtpkg-install.c
index 550135c..31c9e91 100644
--- a/src/wgtpkg-install.c
+++ b/src/wgtpkg-install.c
@@ -81,13 +81,16 @@ static int check_valid_string(const char *value, const char *name)
static int check_temporary_constraints(const struct wgt_desc *desc)
{
- int result = check_valid_string(desc->id, "id");
+ int result;
+
+ result = check_valid_string(desc->id, "id");
result |= check_valid_string(desc->version, "version");
result |= check_valid_string(desc->ver, "ver");
result |= check_defined(desc->icons, "icon");
result |= check_defined(desc->content_src, "content");
if (result)
return result;
+
if (desc->icons->next) {
ERROR("widget has more than one icon defined (temporary constraints)");
errno = EINVAL;
@@ -141,19 +144,24 @@ static int check_widget(const struct wgt_desc *desc)
return result;
}
-static int move_widget(const char *root, const struct wgt_desc *desc, int force)
+static int get_target_directory(char target[PATH_MAX], const char *root, const struct wgt_desc *desc)
{
- char newdir[PATH_MAX];
int rc;
- rc = snprintf(newdir, sizeof newdir, "%s/%s/%s", root, desc->id, desc->ver);
- if (rc >= (int)sizeof newdir) {
- ERROR("path too long in move_widget");
+ rc = snprintf(target, PATH_MAX, "%s/%s/%s", root, desc->id, desc->ver);
+ if (rc < PATH_MAX)
+ rc = 0;
+ else {
+ ERROR("path too long");
errno = EINVAL;
- return -1;
+ rc = -1;
}
+ return rc;
+}
- return move_workdir(newdir, 1, force);
+static int move_widget_to(const char *destdir, int force)
+{
+ return move_workdir(destdir, 1, force);
}
static int install_icon(const struct wgt_desc *desc)
@@ -269,6 +277,7 @@ struct wgt_info *install_widget(const char *wgtfile, const char *root, int force
{
struct wgt_info *ifo;
const struct wgt_desc *desc;
+ char installdir[PATH_MAX];
NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root);
@@ -294,7 +303,10 @@ struct wgt_info *install_widget(const char *wgtfile, const char *root, int force
if (check_widget(desc))
goto error3;
- if (move_widget(root, desc, force))
+ if (get_target_directory(installdir, root, desc))
+ goto error3;
+
+ if (move_widget_to(installdir, force))
goto error3;
if (install_icon(desc))