2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
22 #include <media_util_private.h>
23 #include <media_info_private.h>
24 #include <media_content_type.h>
26 int _media_util_check_file(const char *path)
30 /* check the file exits actually */
31 exist = open(path, O_RDONLY);
33 media_content_sec_debug("path [%s]", path);
34 media_content_stderror("open file fail");
35 if (errno == EACCES || errno == EPERM) {
36 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
38 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
44 return MEDIA_CONTENT_ERROR_NONE;
47 int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
49 int ret = MEDIA_CONTENT_ERROR_NONE;
50 media_svc_storage_type_e storage_type = 0;
51 const char *scan_ignore = ".scan_ignore";
54 media_content_sec_debug("dir_path : %s", dir_path);
56 media_content_retvm_if(!STRING_VALID(dir_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dir_path");
59 /*1. Check Hidden Directory*/
60 if(strstr(dir_path, "/."))
63 media_content_debug("hidden path");
64 return MEDIA_CONTENT_ERROR_NONE;
67 /*2. Check Scan Ignore Directory*/
68 ret = media_svc_get_storage_type(dir_path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
69 if(ret != MS_MEDIA_ERR_NONE)
71 media_content_error("media_svc_get_storage_type failed : %d", ret);
72 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
77 struct dirent *result = NULL;
79 char *leaf_path = NULL;
80 char search_path[4096] = {0, };
82 strncpy(search_path, dir_path, strlen(dir_path));
83 while(STRING_VALID(search_path))
85 dp = opendir(search_path);
86 media_content_retvm_if(dp == NULL, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "Open Directory fail");
88 while (!readdir_r(dp, &entry, &result))
93 if(STRING_VALID(entry.d_name) && (strcmp(entry.d_name, scan_ignore) == 0))
95 media_content_info("Find Ignore path");
96 media_content_sec_debug("Ignore path[%s]", search_path);
102 //media_content_sec_debug("entry.d_name[%s]", entry.d_name);
107 if (dp) closedir(dp);
117 /*If root path, Stop Scanning*/
118 if((storage_type == MEDIA_SVC_STORAGE_INTERNAL) && (strcmp(search_path, tzplatform_getenv(TZ_USER_CONTENT)) == 0))
120 //media_content_debug("Internal root path. Stop Scanning. Not found Ignore information");
123 else if((storage_type == MEDIA_SVC_STORAGE_EXTERNAL) && (strcmp(search_path, MEDIA_ROOT_PATH_SDCARD) == 0))
125 //media_content_debug("Enternal root path. Stop Scanning. Not found Ignore information");
129 leaf_path = strrchr(search_path, '/');
130 if(leaf_path != NULL)
132 int seek_len = leaf_path -search_path;
133 search_path[seek_len] = '\0';
134 //media_content_sec_debug("go to other dir [%s]", search_path);
138 media_content_debug("Fail to find leaf path");
144 return MEDIA_CONTENT_ERROR_NONE;