4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <sys/types.h>
32 #include "media-util.h"
34 GMainLoop * mainloop = NULL;
36 void callback(media_request_result_s * result, void *user_data)
38 printf("db updating done\n");
40 g_main_loop_quit(mainloop);
45 printf("=======================================================================================\n");
47 printf("mediadb-update [option] <directory path> \n");
50 printf(" -r : [only directory] update all directory recursivly under <directory path>\n");
52 printf("mediadb-update --help for check this messages.\n");
54 printf("A file or directory must exists under /opt/usr/media or /opt/storage/sdcard.\n");
55 printf("Using /opt/storage/sdcard is allowed SD card is mounted.\n");
57 printf("=======================================================================================\n");
61 int dir_scan_non_recursive(char *path)
63 return media_directory_scanning_async(path, FALSE, callback, NULL);
66 int dir_scan_recursive(char *path)
68 return media_directory_scanning_async(path, TRUE, callback, NULL);
77 check_result check_path(char *path)
82 /*check the path directory or file*/
83 if (stat(path, &buf) == 0) {
84 if (S_ISDIR(buf.st_mode)) {
85 printf("This is directory\n");
90 /*if openning directory is failed, check it exists. */
91 if (errno == ENOENT) {
92 /* this directory is deleted */
98 printf("[%d]invalid path\n", __LINE__);
102 printf("stat error : %s\n", strerror(errno));
108 int main(int argc, char **argv)
114 if (argc > 3 || argc < 2) {
118 argv1 = strdup(argv[1]);
120 mainloop = g_main_loop_new(NULL, FALSE);
123 if (strcmp(argv1 , "--help") == 0) {
127 if (check_path(argv1) == DIRECTORY_OK) {
128 ret = dir_scan_non_recursive(argv1);
130 printf("error : %d\n", ret);
136 } else if (argc == 3) {
137 argv2 = strdup(argv[2]);
138 if (strcmp(argv1, "-r") == 0) {
139 if (check_path(argv2) == DIRECTORY_OK) {
140 ret = dir_scan_recursive(argv2);
142 printf("error : %d\n", ret);
149 printf("[%d] invalide option\n", __LINE__);
154 g_main_loop_run(mainloop);