2 Copyright 2015, 2016, 2017 IoT.bzh
4 author: José Bollo <jose.bollo@iot.bzh>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
30 #include "utils-dir.h"
31 #include "secmgr-wrap.h"
32 #include "wgtpkg-unit.h"
36 /* uninstall the widget of idaver */
37 int uninstall_widget(const char *idaver, const char *root)
44 struct unitconf uconf;
47 NOTICE("-- UNINSTALLING widget of id %s from %s --", idaver, root);
49 /* find the last '@' of the id */
50 at = strrchr(idaver, '@');
52 ERROR("bad widget id '%s', no @", idaver);
56 id = strndupa(idaver, (size_t)(at - idaver));
57 ver = strdupa(at + 1);
59 /* compute the path */
60 rc = snprintf(path, sizeof path, "%s/%s/%s", root, id, ver);
61 if (rc >= (int)sizeof path) {
62 ERROR("bad widget id '%s', too long", idaver);
67 /* removes the units */
68 ifo = wgt_info_createat(AT_FDCWD, path, 1, 1, 1);
70 ERROR("can't read widget config in directory '%s': %m", path);
73 uconf.installdir = path;
74 uconf.icondir = FWK_ICON_DIR;
76 unit_uninstall(ifo, &uconf);
79 /* removes the directory of the application */
80 rc = remove_directory(path, 1);
82 ERROR("while removing directory '%s': %m", path);
86 /* removes the icon of the application */
87 rc = snprintf(path, sizeof path, "%s/%s", FWK_ICON_DIR, idaver);
88 assert(rc < (int)sizeof path);
90 if (rc < 0 && errno != ENOENT)
91 ERROR("can't remove '%s': %m", path);
93 /* removes the parent directory if empty */
94 rc2 = snprintf(path, sizeof path, "%s/%s", root, id);
95 assert(rc2 < (int)sizeof path);
97 if (rc < 0 && errno == ENOTEMPTY)
100 ERROR("while removing directory '%s': %m", path);
105 * parent directory removed: last occurrence of the application
106 * uninstall it for the security-manager
108 rc2 = secmgr_init(id);
110 ERROR("can't init security manager context");
113 rc2 = secmgr_uninstall();
115 ERROR("can't uninstall security manager context");