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.
29 #include "utils-dir.h"
30 #include "secmgr-wrap.h"
32 /* uninstall the widget of idaver */
33 int uninstall_widget(const char *idaver, const char *root)
41 NOTICE("-- UNINSTALLING widget of id %s from %s --", idaver, root);
43 /* find the last '@' of the id */
44 at = strrchr(idaver, '@');
46 ERROR("bad widget id '%s', no @", idaver);
50 id = strndupa(idaver, (size_t)(at - idaver));
51 ver = strdupa(at + 1);
53 /* compute the path */
54 rc = snprintf(path, sizeof path, "%s/%s/%s", root, id, ver);
55 if (rc >= (int)sizeof path) {
56 ERROR("bad widget id '%s', too long", idaver);
61 /* removes the directory of the application */
62 rc = remove_directory(path, 1);
64 ERROR("error while removing directory '%s': %m", path);
68 /* removes the icon of the application */
69 rc = snprintf(path, sizeof path, "%s/%s", FWK_ICON_DIR, idaver);
70 assert(rc < (int)sizeof path);
73 ERROR("can't removing '%s': %m", path);
75 /* removes the parent directory if empty */
76 rc2 = snprintf(path, sizeof path, "%s/%s", root, id);
77 assert(rc2 < (int)sizeof path);
79 if (rc < 0 && errno == ENOTEMPTY)
82 ERROR("error while removing directory '%s': %m", path);
87 * parent directory removed: last occurrence of the application
88 * uninstall it for the security-manager
90 rc2 = secmgr_init(id);
92 ERROR("can't init security manager context");
95 rc2 = secmgr_uninstall();
97 ERROR("can't uninstall security manager context");