2 Copyright (C) 2015-2020 IoT.bzh
3 Copyright (C) 2020 Konsulko Group
5 author: José Bollo <jose.bollo@iot.bzh>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
31 #include "utils-dir.h"
32 #include "secmgr-wrap.h"
33 #include "wgtpkg-unit.h"
37 /* uninstall the widget of idaver */
38 int uninstall_widget(const char *idaver, const char *root)
45 struct unitconf uconf;
48 NOTICE("-- UNINSTALLING widget of id %s from %s --", idaver, root);
50 /* find the last '@' of the id */
51 at = strrchr(idaver, '@');
53 ERROR("bad widget id '%s', no @", idaver);
57 id = strndupa(idaver, (size_t)(at - idaver));
58 ver = strdupa(at + 1);
60 /* compute the path */
61 rc = snprintf(path, sizeof path, "%s/%s/%s", root, id, ver);
62 if (rc >= (int)sizeof path) {
63 ERROR("bad widget id '%s', too long", idaver);
68 /* removes the units */
69 ifo = wgt_info_createat(AT_FDCWD, path, 1, 1, 1);
71 ERROR("can't read widget config in directory '%s': %m", path);
74 uconf.installdir = path;
75 uconf.icondir = FWK_ICON_DIR;
77 uconf.base_http_ports = 0;
78 unit_uninstall(ifo, &uconf);
81 /* removes the directory of the application */
82 rc = remove_directory(path, 1);
84 ERROR("while removing directory '%s': %m", path);
88 /* removes the icon of the application */
89 rc = snprintf(path, sizeof path, "%s/%s", FWK_ICON_DIR, idaver);
90 assert(rc < (int)sizeof path);
92 if (rc < 0 && errno != ENOENT) {
93 ERROR("can't remove '%s': %m", path);
97 /* removes the parent directory if empty */
98 rc = snprintf(path, sizeof path, "%s/%s", root, id);
99 assert(rc < (int)sizeof path);
101 if (rc < 0 && errno == ENOTEMPTY)
104 ERROR("while removing directory '%s': %m", path);
109 * parent directory removed: last occurrence of the application
110 * uninstall it for the security-manager
112 rc = secmgr_init(id);
114 ERROR("can't init security manager context");
117 rc = secmgr_uninstall();
119 ERROR("can't uninstall security manager context");