2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Junghyun Yeon <jungh.yeon@samsung.com>,
5 * Sangyoon Jang <s89.jang@samsung.com>
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.
24 #include <sys/types.h>
27 #include <tzplatform_config.h>
29 #include "pkgmgr-info.h"
30 #include "pkgmgr_parser_db.h"
36 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
39 static int _remove_file(const char *path)
44 if (access(path, F_OK) != 0)
50 static int _remove_db(uid_t uid)
54 char journal_path[PATH_MAX];
56 parser_db = getUserPkgParserDBPathUID(uid);
58 printf("Failed to get parser db path\n");
62 if (_remove_file(parser_db) != 0) {
63 printf("Failed to remove parser db[%s]\n", parser_db);
68 snprintf(journal_path, sizeof(journal_path), "%s-journal", parser_db);
70 if (_remove_file(journal_path) != 0) {
71 printf("Failed to remove journal[%s]\n", journal_path);
75 if (uid != OWNER_ROOT && uid != GLOBAL_USER)
78 cert_db = getUserPkgCertDBPath();
80 printf("Failed to get cet db path\n");
84 if (_remove_file(cert_db) != 0) {
85 printf("Failed to remove parser db[%s]\n", cert_db);
90 snprintf(journal_path, sizeof(journal_path), "%s-journal", cert_db);
92 if (_remove_file(journal_path) != 0) {
93 printf("Failed to remove journal[%s]\n", journal_path);
100 int main(int argc, char *argv[])
105 if ((int)getuid() > OWNER_ROOT) {
106 printf("This cmd is not allowed for regular user\n");
111 printf("argument should be provided\n");
116 ret = _remove_db((uid_t)uid);
118 printf("failed to remove database for uid[%d]\n", uid);
120 ret = pkgmgr_parser_initialize_parser_db((uid_t)uid);
122 printf("failed to create parser db for uid [%d], err[%d]\n", uid, ret);
128 ret = pkgmgr_parser_initialize_cert_db();
130 printf("failed to create cert db for uid [%d], err[%d]\n", uid, ret);