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)
47 struct unitconf uconf;
50 NOTICE("-- UNINSTALLING widget of id %s from %s --", idaver, root);
52 /* find the last '@' of the id */
54 at = strrchr(idaver, '@');
56 ERROR("bad widget id '%s', no @", idaver);
60 id = strndupa(idaver, (size_t)(at - idaver));
61 ver = strdupa(at + 1);
63 /* compute the path */
64 rc = snprintf(path, sizeof path, "%s/%s/%s", root, id, ver);
66 rc = snprintf(path, sizeof path, "%s/%s", root, idaver);
69 if (rc >= (int)sizeof path) {
70 ERROR("bad widget id '%s', too long", idaver);
75 /* removes the units */
76 ifo = wgt_info_createat(AT_FDCWD, path, 1, 1, 1);
78 ERROR("can't read widget config in directory '%s': %m", path);
81 uconf.installdir = path;
82 uconf.icondir = FWK_ICON_DIR;
84 uconf.base_http_ports = 0;
85 unit_uninstall(ifo, &uconf);
88 /* removes the directory of the application */
89 rc = remove_directory(path, 1);
91 ERROR("while removing directory '%s': %m", path);
95 /* removes the icon of the application */
96 rc = snprintf(path, sizeof path, "%s/%s", FWK_ICON_DIR, idaver);
97 assert(rc < (int)sizeof path);
99 if (rc < 0 && errno != ENOENT) {
100 ERROR("can't remove '%s': %m", path);
104 #if DISTINCT_VERSIONS
105 /* removes the parent directory if empty */
106 rc = snprintf(path, sizeof path, "%s/%s", root, id);
107 assert(rc < (int)sizeof path);
109 if (rc < 0 && errno == ENOTEMPTY)
112 ERROR("while removing directory '%s': %m", path);
117 * parent directory removed: last occurrence of the application
118 * uninstall it for the security-manager
120 rc = secmgr_init(id);
122 rc = secmgr_init(idaver);
125 ERROR("can't init security manager context");
128 rc = secmgr_uninstall();
130 ERROR("can't uninstall security manager context");