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>
static int check_temporary_constraints(const struct wgt_desc *desc)
{
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;
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;
if (desc->icons->next) {
ERROR("widget has more than one icon defined (temporary constraints)");
errno = EINVAL;
-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)
- 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");
- 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)
}
static int install_icon(const struct wgt_desc *desc)
{
struct wgt_info *ifo;
const struct wgt_desc *desc;
{
struct wgt_info *ifo;
const struct wgt_desc *desc;
+ char installdir[PATH_MAX];
NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root);
NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root);
if (check_widget(desc))
goto error3;
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))
goto error3;
if (install_icon(desc))