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>
28 #include <tzplatform_config.h>
30 #include "pkgmgr-info.h"
31 #include "pkgmgr_parser_db.h"
37 #define LOG_TAG "PKG_DB_CREATOR"
43 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
46 static int _remove_file(const char *path)
51 if (access(path, F_OK) != 0)
57 static int _remove_db(uid_t uid)
61 char journal_path[PATH_MAX];
63 parser_db = getUserPkgParserDBPathUID(uid);
65 LOGE("Failed to get parser db path");
69 if (_remove_file(parser_db) != 0) {
70 LOGE("Failed to remove parser db[%s]", parser_db);
75 snprintf(journal_path, sizeof(journal_path), "%s-journal", parser_db);
77 if (_remove_file(journal_path) != 0) {
78 LOGE("Failed to remove journal[%s]", journal_path);
82 if (uid != OWNER_ROOT && uid != GLOBAL_USER)
85 cert_db = getUserPkgCertDBPath();
87 LOGE("Failed to get cet db path");
91 if (_remove_file(cert_db) != 0) {
92 LOGE("Failed to remove parser db[%s]", cert_db);
97 snprintf(journal_path, sizeof(journal_path), "%s-journal", cert_db);
99 if (_remove_file(journal_path) != 0) {
100 LOGE("Failed to remove journal[%s]", journal_path);
107 int main(int argc, char *argv[])
112 if ((int)getuid() > OWNER_ROOT) {
113 LOGE("This cmd is not allowed for regular user");
118 LOGE("argument should be provided");
123 ret = _remove_db((uid_t)uid);
125 LOGE("failed to remove database for uid[%d]", uid);
127 ret = pkgmgr_parser_initialize_parser_db((uid_t)uid);
129 LOGE("failed to create parser db for uid [%d], err[%d]", uid, ret);
135 ret = pkgmgr_parser_initialize_cert_db();
137 LOGE("failed to create cert db for uid [%d], err[%d]", uid, ret);