Code cleanup 78/146378/4
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 28 Aug 2017 07:57:44 +0000 (16:57 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Tue, 29 Aug 2017 04:20:40 +0000 (04:20 +0000)
Remove useless parameters(with libmedia-service)
Change dirent API to glib API
Remove unused APIs

Change-Id: I61d7e0f7df482fa622a8f45985d86e91076ce23e
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
14 files changed:
Makefile.am
lib/include/media-server-ipc.h
src/common/include/media-common-db-svc.h
src/common/include/media-common-utils.h
src/common/media-common-db-svc.c
src/common/media-common-external-storage.c
src/common/media-common-utils.c
src/mediadb-update.c
src/scanner/include/media-scanner-device-block.h [deleted file]
src/scanner/include/media-scanner-scan.h
src/scanner/media-scanner-device-block.c [deleted file]
src/scanner/media-scanner-scan.c
src/scanner/media-scanner.c
src/server/media-server-main.c

index 7f60cc9..e4815c8 100755 (executable)
@@ -150,7 +150,6 @@ media_scanner_SOURCES = src/common/media-common-utils.c \
                        src/common/media-common-system.c \
                        src/common/media-common-external-storage.c \
                        src/common/media-common-db-svc.c \
-                        src/scanner/media-scanner-device-block.c \
                        src/scanner/media-scanner-scan.c \
                        src/scanner/media-scanner-socket.c \
                        src/scanner/media-scanner.c
index 5ac08ed..440f41f 100755 (executable)
@@ -87,11 +87,6 @@ typedef struct {
        char msg[MAX_MSG_SIZE];
 } ms_comm_msg_s;
 
-typedef enum {
-       CLIENT_SOCKET,
-       SERVER_SOCKET
-} ms_socket_type_e;
-
 typedef struct {
        ms_msg_type_e msg_type;
 } ms_thumb_server_msg;
index e71f51b..df0bf35 100755 (executable)
@@ -33,7 +33,6 @@
 typedef struct ms_dir_info_s {
        char *dir_path;
        int modified_time;
-       int item_num;
 } ms_dir_info_s;
 
 typedef struct ms_stg_info_s {
@@ -72,7 +71,7 @@ typedef int (*DELETE_ALL_ITEMS_IN_STORAGE)(void *, const char *, int, uid_t, cha
 typedef int (*DELETE_ALL_INVALID_ITMES_IN_STORAGE)(void *, const char *, int, uid_t, char **);
 typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(void *, const char *, const char *, bool, uid_t, char**);
 typedef int (*COUNT_DELETE_ITEMS_IN_FOLDER)(void *, const char *, const char *, int *, char **);
-typedef int (*GET_FOLDER_LIST)(void *, const char *, char *, char ***, int **, int **, int *, char **);
+typedef int (*GET_FOLDER_LIST)(void *, const char *, char *, char ***, int **, int *, char **);
 typedef int (*UPDATE_FOLDER_TIME)(void *, const char *, const char *, uid_t, char **);
 typedef int (*GET_STORAGE_ID)(void *, const char *, char *, uid_t uid, char **);
 typedef int (*SET_STORAGE_SCAN_STATUS)(void *, const char *, int, uid_t, char **);
index eb0950a..b6d07ed 100755 (executable)
@@ -29,8 +29,6 @@ int ms_strappend(char *res, const int size, const char *pattern, const char *str
 bool ms_config_get_int(const char *key, int *value);
 bool ms_config_set_int(const char *key, int value);
 bool ms_config_get_str(const char *key, char **value);
-bool ms_config_set_str(const char *key, const char *value);
-bool ms_config_get_bool(const char *key, int *value);
 int ms_get_remain_space(double *free_space);
 
 #ifdef _USE_RECORDED_CONTENT
index c4254b6..e5c631b 100755 (executable)
@@ -778,7 +778,6 @@ int ms_get_folder_list(void **handle, const char* storage_id, char* start_path,
 
        char **folder_list = NULL;
        int *modified_time_list = NULL;
-       int *item_num_list = NULL;
        int count = 0;
        int i = 0;
 
@@ -786,7 +785,7 @@ int ms_get_folder_list(void **handle, const char* storage_id, char* start_path,
        MS_DBG("start path: %s", start_path);
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
-               ret = ((GET_FOLDER_LIST)func_array[lib_index][eGET_FOLDER_LIST])(handle[lib_index], storage_id, start_path, &folder_list, &modified_time_list, &item_num_list, &count, &err_msg); /*dlopen*/
+               ret = ((GET_FOLDER_LIST)func_array[lib_index][eGET_FOLDER_LIST])(handle[lib_index], storage_id, start_path, &folder_list, &modified_time_list, &count, &err_msg); /*dlopen*/
                if (ret != 0) {
                        MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
                        MS_SAFE_FREE(err_msg);
@@ -801,7 +800,6 @@ int ms_get_folder_list(void **handle, const char* storage_id, char* start_path,
                        if (dir_info != NULL) {
                                dir_info->dir_path = strdup(folder_list[i]);
                                dir_info->modified_time = modified_time_list[i];
-                               dir_info->item_num = item_num_list[i];
                                g_array_append_val(*dir_array, dir_info);
                        } else {
                                MS_DBG_ERR("malloc failed");
index 20c71cf..71aa79c 100755 (executable)
@@ -63,23 +63,16 @@ void ms_make_default_path_mmc(const char *mount_path)
 {
        int i = 0;
        int ret = 0;
-       DIR *dp = NULL;
-       char *mmc_path = malloc(MS_FILE_NAME_LEN_MAX+1);
-
-       if (mmc_path == NULL) {
-               MS_DBG_ERR("allocation fail");
-               return;
-       }
+       char mmc_path[MS_FILE_NAME_LEN_MAX+1] = {0, };
 
        for (i = 0; i < DIR_NUM; ++i) {
-               memset(mmc_path, 0, MS_FILE_NAME_LEN_MAX+1);
-               snprintf(mmc_path, MS_FILE_NAME_LEN_MAX, "%s/%s", mount_path, default_path[i]);
-               dp = opendir(mmc_path);
-               if (dp == NULL) {
+               memset(mmc_path, 0, sizeof(mmc_path));
+               snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, default_path[i]);
+               if (!g_file_test(mmc_path, G_FILE_TEST_IS_DIR)) {
                        MS_DBG("%s path did not exist", mmc_path);
                        ret = mkdir(mmc_path, 0770);
                        if (ret < 0) {
-                               MS_DBG_ERR("make fail");
+                               MS_DBG_ERR("mkdir failed");
                        }
                        /*this fuction for emulator*/
                        /*at the first time, the directroies are made permission 755*/
@@ -87,12 +80,8 @@ void ms_make_default_path_mmc(const char *mount_path)
                        if (ret != 0) {
                                MS_DBG_STRERROR("chmod failed");
                        }
-               } else {
-                       closedir(dp);
                }
        }
-
-       MS_SAFE_FREE(mmc_path);
 }
 
 static int __get_contents(const char *filename, char *buf)
@@ -168,111 +157,54 @@ int ms_present_mmc_status(ms_sdcard_status_type_t status)
 
 #define DEVICE_INFO_FILE ".device_info_"
 
-struct linux_dirent {
-       ino64_t                 d_ino;   /* 64-bit inode number */
-       off64_t                 d_off;   /* 64-bit offset to next structure */
-       unsigned short  d_reclen; /* Size of this dirent */
-       unsigned char   d_type;  /* File type */
-       char                            d_name[]; /* Filename (null-terminated) */
-};
-
-#define BUF_SIZE 1024
-
-int __ms_check_mount_path(const char *mount_path)
-{
-       DIR *dp = NULL;
-
-       /*check mount path*/
-       dp = opendir(mount_path);
-       if (dp == NULL) {
-               MS_DBG_ERR("Mount path is not exist");
-               return MS_MEDIA_ERR_INVALID_PATH;
-       }
-
-       closedir(dp);
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 int ms_read_device_info(const char *root_path, char **device_uuid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        int len = 0;
+       GDir *dir = NULL;
+       GError *error = NULL;
+       const char *name;
 
-       int fd = -1;
-       int nread = 0;
-       char buf[BUF_SIZE] = {0,};
-       struct linux_dirent *d;
-       int bpos = 0;
-       bool find_uuid = FALSE;
-
-       ret = __ms_check_mount_path(root_path);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("__ms_check_mount_path falied");
-               goto ERROR;
+       if (device_uuid == NULL) {
+               MS_DBG_ERR("device_uuid is NULL");
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       fd = open(root_path, O_RDONLY | O_DIRECTORY);
-       if (fd == -1) {
-               MS_DBG_ERR("open failed [%s]", root_path);
-               MS_DBG_STRERROR();
-               ret = MS_MEDIA_ERR_INVALID_PATH;
-               goto ERROR;
+       if (!g_file_test(root_path, G_FILE_TEST_IS_DIR)) {
+               MS_DBG_ERR("Mount path is not exist");
+               *device_uuid = NULL;
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       for ( ; ; ) {
-               nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
-               if (nread == -1) {
-                       MS_DBG_ERR("getdents");
-                       MS_DBG_STRERROR();
-                       ret = MS_MEDIA_ERR_INTERNAL;
-                       goto ERROR;
-               }
-
-               if (nread == 0)
-                       break;
-
-               for (bpos = 0; bpos < nread;) {
-                       d = (struct linux_dirent *) (buf + bpos);
-
-                       if (d->d_type == DT_REG && (strncmp(d->d_name, DEVICE_INFO_FILE, strlen(DEVICE_INFO_FILE)) == 0)) {
-                               MS_DBG_WARN("FIND DEV INFO : %s", d->d_name);
-                               bpos += d->d_reclen;
-                               find_uuid = TRUE;
-                               goto FIND_UUID;
+       dir = g_dir_open(root_path, 0, &error);
+       if (error == NULL && dir != NULL) {
+               *device_uuid = NULL;
+               while ((name = g_dir_read_name(dir))) {
+                       if (strncmp(name, DEVICE_INFO_FILE, strlen(DEVICE_INFO_FILE)) == 0) {
+                               MS_DBG_WARN("FIND DEV INFO : %s", name);
+                               len = strlen(name + strlen(DEVICE_INFO_FILE));
+                               if (len > 0) {
+                                       *device_uuid = strndup(name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
+                                       MS_DBG_WARN("[%s][DEV ID: %s]", root_path, *device_uuid);
+                               }
+
+                               if (*device_uuid == NULL)
+                                       ret = MS_MEDIA_ERR_INTERNAL;
+
+                               break;
                        }
-
-                       bpos += d->d_reclen;
-               }
-       }
-
-FIND_UUID:
-       if (find_uuid) {
-               len = strlen(d->d_name + strlen(DEVICE_INFO_FILE));
-               if (len > 0) {
-                       *device_uuid = strndup(d->d_name + strlen(DEVICE_INFO_FILE), MS_UUID_SIZE -1);
-                       MS_DBG_WARN("[%s][DEV ID: %s]", root_path, *device_uuid);
                }
        } else {
-               ret = MS_MEDIA_ERR_FILE_NOT_EXIST;
-               MS_DBG_ERR("[%s]DEV INFO NOT EXIST", root_path);
-               goto ERROR;
+               MS_DBG_ERR("g_dir_open failed [%s]", root_path);
+               *device_uuid = NULL;
+               return MS_MEDIA_ERR_INVALID_PATH;
        }
 
-       if (fd > -1) {
-               close(fd);
-               fd = -1;
+       if (dir) {
+               g_dir_close(dir);
+               dir = NULL;
        }
 
-       return MS_MEDIA_ERR_NONE;
-
-ERROR:
-
-       *device_uuid = NULL;
-       if (fd > -1) {
-               close(fd);
-               fd = -1;
-       }
        return ret;
 }
 
index 43bcf1f..2157680 100755 (executable)
 #include "media-common-system.h"
 #include "media-common-utils.h"
 
-/* it's for 32bit file offset */
-struct statvfs_32 {
-       unsigned long int f_bsize;
-       unsigned long int f_frsize;
-       unsigned long int f_blocks;
-       unsigned long int f_bfree;
-       unsigned long int f_bavail;
-       unsigned long int f_files;
-       unsigned long int f_ffree;
-       unsigned long int f_favail;
-       unsigned long int f_fsid;
-#ifdef _STATVFSBUF_F_UNUSED
-       int __f_unused;
-#endif
-       unsigned long int f_flag;
-       unsigned long int f_namemax;
-       int __f_spare[6];
-};
-
 int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2)
 {
        int len = 0;
@@ -145,89 +126,25 @@ bool ms_config_get_str(const char *key, char **value)
        return false;
 }
 
-bool ms_config_set_str(const char *key, const char *value)
-{
-       int err;
-
-       if (!key || !value) {
-               MS_DBG_ERR("Arguments key or value is NULL");
-               return false;
-       }
-
-       err = vconf_set_str(key, value);
-       if (err == 0)
-               return true;
-       else
-               MS_DBG_ERR("fail to vconf_set_str %d", err);
-
-       return false;
-}
-
-bool ms_config_get_bool(const char *key, int *value)
-{
-       int err;
-
-       if (!key || !value) {
-               MS_DBG_ERR("Arguments key or value is NULL");
-               return false;
-       }
-
-       err = vconf_get_bool(key, value);
-       if (err == 0)
-               return true;
-       else if (err == -1)
-               return false;
-       else
-               MS_DBG_ERR("Unexpected error code: %d", err);
-
-       return false;
-}
-
-static int get_memory_size(const char *path, struct statvfs_32 *buf)
+int ms_get_remain_space(double *free_space)
 {
+       int ret = MS_MEDIA_ERR_NONE;
+       const char *path = "/opt";
        struct statvfs s;
-       int ret;
 
        ret = statvfs(path, &s);
-       if (ret) {
+       if (ret != 0) {
                MS_DBG_ERR("statvfs failed[%d]", ret);
                MS_DBG_STRERROR();
                return MS_MEDIA_ERR_INTERNAL;
        }
 
-       buf->f_bsize = s.f_bsize;
-       buf->f_frsize = s.f_frsize;
-       buf->f_blocks = (unsigned long)s.f_blocks;
-       buf->f_bfree = (unsigned long)s.f_bfree;
-       buf->f_bavail = (unsigned long)s.f_bavail;
-       buf->f_files = (unsigned long)s.f_files;
-       buf->f_ffree = (unsigned long)s.f_ffree;
-       buf->f_favail = (unsigned long)s.f_favail;
-       buf->f_fsid = s.f_fsid;
-       buf->f_flag = s.f_flag;
-       buf->f_namemax = s.f_namemax;
+       /* f_bsize:unsigned long, f_bavail:fsblkcnt_t(unsigned long) */
+       *free_space = (double)(s.f_bsize * s.f_bavail);
 
        return MS_MEDIA_ERR_NONE;
 }
 
-int ms_get_remain_space(double *free_space)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       struct statvfs_32 temp;
-
-       ret = get_memory_size("/opt", &temp);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("fail to get memory size");
-               return ret;
-       }
-
-//     MS_DBG_ERR("Total mem : %lf, Avail mem : %lf", (double)temp.f_frsize*temp.f_blocks, (double)temp.f_bsize*temp.f_bavail);
-
-       *free_space = (double)temp.f_bsize*temp.f_bavail;
-
-       return ret;
-}
-
 #ifdef _USE_RECORDED_CONTENT
 bool ms_is_support_pvr(void)
 {
@@ -262,8 +179,6 @@ bool ms_is_support_senior_mode()
 
 int ms_check_file_path(const char *file_path, uid_t uid)
 {
-       int exist;
-       struct stat file_st;
        ms_user_storage_type_e storage_type = -1;
        int ret = MS_MEDIA_ERR_NONE;
 
@@ -272,30 +187,11 @@ int ms_check_file_path(const char *file_path, uid_t uid)
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       /* check location of file */
-       /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
        ret = ms_user_get_storage_type(uid, file_path, &storage_type);
        MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PATH, "Invalid path");
 
-       /* check the file exits actually */
-       exist = open(file_path, O_RDONLY);
-       if (exist < 0) {
-               MS_DBG_SERR("open file fail [%s]", file_path);
-               return MS_MEDIA_ERR_INVALID_PATH;
-       }
-       close(exist);
-
-       /* check type of the path */
-       /* It must be a regular file */
-       memset(&file_st, 0, sizeof(struct stat));
-       if (stat(file_path, &file_st) == 0) {
-               if (!S_ISREG(file_st.st_mode)) {
-                       /* In this case, it is not a regula file */
-                       MS_DBG_ERR("this path is not a file");
-                       return MS_MEDIA_ERR_INVALID_PATH;
-               }
-       } else {
-               MS_DBG_STRERROR("stat failed");
+       if (!g_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+               MS_DBG_SERR("g_file_test fail [%s]", file_path);
                return MS_MEDIA_ERR_INVALID_PATH;
        }
 
@@ -369,80 +265,41 @@ int ms_check_ignore_dir(const char *full_path, uid_t uid)
 
 int ms_check_scan_ignore(char * path)
 {
-       int fd = -1;
-       int exist = -1;
-       const char *ignore_path = "/.scan_ignore";
-       char *check_ignore_file = NULL;
        int ret = MS_MEDIA_ERR_NONE;
+       const char *ignore_file = ".scan_ignore";
+       char ignore_path[MS_FILE_PATH_LEN_MAX] = {0, };
 
        if (strstr(path, "/.")) {
                MS_DBG_ERR("hidden path");
-               ret = MS_MEDIA_ERR_INVALID_PATH;
-               goto ERROR;
+               return MS_MEDIA_ERR_INVALID_PATH;
        }
 
-       fd = open(path, O_RDONLY | O_DIRECTORY);
-       if (fd == -1) {
-               MS_DBG_ERR("%s folder opendir fails", path);
+       if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
+               memset(ignore_path, 0, sizeof(ignore_path));
+               snprintf(ignore_path, sizeof(ignore_path), "%s/%s", path, ignore_file);
+
+               if (g_file_test(ignore_path, G_FILE_TEST_EXISTS)) {
+                       MS_DBG_WARN("scan ignore file exist [%s]", ignore_path);
+                       return MS_MEDIA_ERR_INVALID_PATH;
+               }
+       } else {
+               MS_DBG_ERR("g_file_test fails[%s]", path);
                ret = MS_MEDIA_ERR_INVALID_PATH;
 
                if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
                        MS_DBG_ERR("Fail to get USB path");
-                       goto ERROR;
+                       return ret;
                }
 
                if (strstr(path, MEDIA_ROOT_PATH_USB) != NULL) {
-                       if (errno == ENOENT) {
-                               /*if the directory does not exist, check the device is unmounted*/
-                               if (!ms_storage_mount_status(path)) {
-                                       MS_DBG_ERR("Device is unmounted[%s]", path);
-                                       ret = MS_MEDIA_ERR_USB_UNMOUNTED;
-                                       goto ERROR;
-                               }
-                       }
-               }
-
-               struct stat folder_st;
-               if (stat(path, &folder_st) == 0) {
-                       MS_DBG_WARN("DEV[%ld] INODE[%lld] UID[%ld] GID[%ld] MODE[%lo] PATH[%s]", (long)folder_st.st_dev, (long long)folder_st.st_ino,
-                               (long)folder_st.st_uid, (long)folder_st.st_gid, (unsigned long) folder_st.st_mode, path);
-               } else {
-                       MS_DBG_ERR("%s folder stat fails", path);
-               }
-
-               goto ERROR;
-       } else {
-               /* check the file exits actually */
-               int path_len = 0;
-
-               path_len = strlen(path) + strlen(ignore_path) + 1;
-               check_ignore_file = malloc(path_len);
-               if (check_ignore_file != NULL) {
-                       memset(check_ignore_file, 0x0, path_len);
-                       snprintf(check_ignore_file, path_len, "%s%s", path, ignore_path);
-
-                       exist = open(check_ignore_file, O_RDONLY);
-                       if (exist >= 0) {
-                               MS_DBG_WARN("scan_ignore exists [%s]", check_ignore_file);
-                               ret = MS_MEDIA_ERR_INVALID_PATH;
+                       /*if the directory does not exist, check the device is unmounted*/
+                       if (!ms_storage_mount_status(path)) {
+                               MS_DBG_ERR("Device is unmounted[%s]", path);
+                               return MS_MEDIA_ERR_USB_UNMOUNTED;
                        }
-
-                       MS_SAFE_FREE(check_ignore_file);
-               } else {
-                       MS_DBG_ERR("malloc failed");
-                       ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
                }
        }
 
-ERROR:
-
-       if (fd != -1) {
-               close(fd);
-               fd = -1;
-       }
-
-       if (exist >= 0) close(exist);
-
        return ret;
 }
 
index 67ab44d..edef8e4 100755 (executable)
@@ -74,8 +74,6 @@ int (*svc_insert_storage)             (void *handle, const char *storage_id, int storage_ty
 int (*svc_delete_storage)              (void * handle, const char *storage_id, uid_t uid, char **err_msg);
 int (*svc_set_storage_validity)        (void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg);
 
-
-
 void callback(media_request_result_s * result, void *user_data)
 {
        if (result->result != MEDIA_REQUEST_SCAN_PARTIAL) {
@@ -101,7 +99,6 @@ void print_help()
        printf("=======================================================================================\n");
 }
 
-
 static int __get_contents(const char *filename, char *buf)
 {
        FILE *fp;
@@ -451,43 +448,6 @@ int dir_scan_recursive(char *path)
        return media_directory_scanning_async(path, storage_id, TRUE, callback, NULL, tzplatform_getuid(TZ_USER_NAME));
 }
 
-typedef enum {
-       DIRECTORY_OK,
-       FILE_OK,
-       NOT_OK,
-} check_result;
-
-check_result check_path(char *path)
-{
-       struct stat buf;
-       DIR *dp = NULL;
-
-       /*check the path directory or file*/
-       if (stat(path, &buf) == 0) {
-               if (S_ISDIR(buf.st_mode)) {
-                       printf("This is directory\n");
-                       return DIRECTORY_OK;
-               } else {
-                       dp = opendir(path);
-                       if (dp == NULL) {
-                               /*if openning directory is failed, check it exists. */
-                               if (errno == ENOENT) {
-                                       /* this directory is deleted */
-                                       return DIRECTORY_OK;
-                               }
-                       } else {
-                               closedir(dp);
-                       }
-                       print_help();
-                       return NOT_OK;
-               }
-       } else {
-               printf("stat error");
-       }
-
-       return NOT_OK;
-}
-
 int main(int argc, char **argv)
 {
        int ret;
@@ -529,7 +489,7 @@ int main(int argc, char **argv)
                        exit(0);
                }
 
-               if (check_path(argv1) == DIRECTORY_OK) {
+               if (g_file_test(argv1, G_FILE_TEST_IS_DIR)) {
                        len = strlen(argv1);
 
                        if (argv1[len - 1] == '/')
@@ -550,7 +510,7 @@ int main(int argc, char **argv)
        } else if (argc == 3) {
                argv2 = strdup(argv[2]);
                if (strcmp(argv1, "-r") == 0) {
-                       if ((argv2 != NULL) && (check_path(argv2) == DIRECTORY_OK)) {
+                       if ((argv2 != NULL) && (g_file_test(argv2, G_FILE_TEST_IS_DIR))) {
                                len = strlen(argv2);
 
                                if (argv2[len - 1] == '/')
diff --git a/src/scanner/include/media-scanner-device-block.h b/src/scanner/include/media-scanner-device-block.h
deleted file mode 100755 (executable)
index 01eb87c..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _MEDIA_SCANNER_DEVICE_BLOCK_H_
-#define _MEDIA_SCANNER_DEVICE_BLOCK_H_
-
-#include "media-common-system.h"
-
-#ifdef _USE_DEVICED_DBUS
-void msc_device_block_changed_cb(ms_block_info_s *block_info, void *user_data);
-#else
-void msc_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data);
-#endif
-
-#endif
\ No newline at end of file
index f3876bc..c7dae47 100755 (executable)
@@ -38,8 +38,6 @@ int msc_check_remain_task(void);
 ms_db_status_type_t msc_check_scanning_status(void);
 int msc_set_cancel_path(const char *cancel_path);
 int msc_del_cancel_path(void);
-int msc_set_blocked_path(const char *blocked_path);
-int msc_del_blocked_path(void);
 void msc_metadata_update_thread(ms_comm_msg_s *recv_msg);
 int msc_init_scanner(void);
 int msc_deinit_scanner(void);
diff --git a/src/scanner/media-scanner-device-block.c b/src/scanner/media-scanner-device-block.c
deleted file mode 100755 (executable)
index 5ac258c..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <vconf.h>
-
-#include "media-util.h"
-
-#include "media-common-utils.h"
-#include "media-common-db-svc.h"
-#include "media-common-external-storage.h"
-
-#include "media-util-err.h"
-#include "media-scanner-dbg.h"
-#include "media-scanner-scan.h"
-#include "media-scanner-device-block.h"
-
-extern GAsyncQueue * storage_queue;
-extern bool g_directory_scan_processing;
-
-#ifdef _USE_DEVICED_DBUS
-static void __msc_usb_remove_event(const char *mount_path)
-{
-       return;
-}
-
-int msc_mmc_remove_handler(const char *mount_path)
-{
-       return MS_MEDIA_ERR_NONE;
-}
-
-void _msc_mmc_changed_event(const char *mount_path, ms_stg_status_e mount_status)
-{
-       /* If scanner is not working, media server executes media scanner and sends request. */
-       /* If scanner is working, it detects changing status of SD card. */
-       if (mount_status == MS_STG_INSERTED) {
-               /*DO NOT THING*/
-       } else if (mount_status == MS_STG_REMOVED) {
-               msc_mmc_remove_handler(mount_path);
-       }
-
-       return;
-}
-
-
-void msc_device_block_changed_cb(ms_block_info_s *block_info, void *user_data)
-{
-       if (block_info->block_type == 0) {
-               MS_DBG_WARN("GET THE USB EVENT");
-               if (block_info->state == MS_STG_INSERTED) {
-                       /*DO NOT THING*/
-               } else {
-                       __msc_usb_remove_event(block_info->mount_path);
-               }
-       } else {
-               MS_DBG_WARN("GET THE MMC EVENT");
-               _msc_mmc_changed_event(block_info->mount_path, block_info->state);
-       }
-}
-#else
-void msc_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data)
-{
-       char *mount_path = NULL;
-
-       if (!usb_device) {
-               MS_DBG_ERR("usb_device is NULL");
-               return;
-       }
-
-       if (usb_device_get_class(usb_device) != USB_MASS_STORAGE) {
-               free_usb_device_h(usb_device);
-               MS_DBG_ERR("usb_device is NOT STORAGE");
-               return;
-       }
-
-       mount_path = usb_device_get_mountpath(usb_device);
-
-       if (!strcmp(action, "blocked")) {
-               MS_DBG_WARN("===========================================================");
-               MS_DBG_WARN("USB BLOCKED, mountpath : %s", mount_path);
-               MS_DBG_WARN("===========================================================");
-               int status = -1;
-
-               if (!ms_config_get_int(VCONFKEY_FILEMANAGER_DB_STATUS, &status)) {
-                       MS_DBG_ERR("ms_config_get_int[VCONFKEY_FILEMANAGER_DB_STATUS]");
-               }
-               if (!(g_async_queue_length(storage_queue) == 0 && status == VCONFKEY_FILEMANAGER_DB_UPDATED)) {
-                       msc_set_blocked_path(mount_path);
-               }
-
-               if (g_directory_scan_processing == true) {
-                       MS_DBG_WARN("Doing directory scanning. Set cancel path");
-                       msc_set_cancel_path(mount_path);
-               }
-       }
-
-       free_usb_device_h(usb_device);
-
-       return;
-}
-#endif
index 29c5693..3003328 100755 (executable)
@@ -43,11 +43,7 @@ GAsyncQueue * storage_queue;
 GAsyncQueue *scan_queue;
 GAsyncQueue *reg_queue;
 GMutex scan_req_mutex;
-GMutex blocked_mutex;
 char *g_cancel_path;
-char *g_blocked_path;
-bool g_directory_scan_processing;
-int stg_scan_status;
 
 static int __msc_check_stop_status(ms_storage_type_t storage_type);
 static int __msc_stg_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, uid_t uid);
@@ -58,7 +54,6 @@ static int __msc_batch_insert(ms_msg_type_e current_msg, int pid, GArray *path_a
 static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **register_data);
 static int __msc_clear_file_list(GArray *path_array);
 static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
-static int __msc_set_storage_scan_status(ms_storage_scan_status_e status);
 
 static int __msc_check_stop_status(ms_storage_type_t storage_type)
 {
@@ -549,7 +544,7 @@ _POWEROFF:
 }
 
 /* this thread process only the request of media-server */
-static int _check_folder_from_list(char *folder_path, int item_num, GArray *dir_array)
+static int _check_folder_from_list(char *folder_path, GArray *dir_array)
 {
        int i = 0;
        int array_len = dir_array->len;
@@ -567,8 +562,7 @@ static int _check_folder_from_list(char *folder_path, int item_num, GArray *dir_
        for (i = 0; i < array_len; i++) {
                dir_info = g_array_index(dir_array, ms_dir_info_s*, i);
                if (strcmp(folder_path, dir_info->dir_path) == 0) {
-                       /* if modified time is same, the folder does not need updating */
-                       if ((mtime == dir_info->modified_time) && (item_num == dir_info->item_num)) {
+                       if (mtime == dir_info->modified_time) {
                                if (mtime == 0)
                                        continue;
 
@@ -609,7 +603,6 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
        char *current_path = NULL;
        char path[MS_FILE_PATH_LEN_MAX] = { 0 };
        char * start_path = strdup(update_path);
-       int item_num = 0;
 
        MS_DBG_FENTER();
 
@@ -632,7 +625,6 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
 
        /*start db update. the number of element in the array , db update is complete.*/
        while (read_dir_array->len != 0) {
-               /* get the current path from directory array */
                current_path = g_array_index(read_dir_array , char*, 0);
                g_array_remove_index(read_dir_array, 0);
 
@@ -658,14 +650,11 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
                                        /* add new directory to dir_array */
                                        new_path = strdup(path);
                                        g_array_append_val(read_dir_array, new_path);
-                               } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
-                                       item_num++;
                                }
                        }
 
                        /* find and compare modified time */
-                       _check_folder_from_list(current_path, item_num, *dir_array);
-                       item_num = 0;
+                       _check_folder_from_list(current_path, *dir_array);
                } else {
                        MS_DBG_ERR("g_dir_open fails [%s]", current_path);
                }
@@ -739,14 +728,12 @@ gboolean msc_storage_scan_thread(void *data)
        char *storage_id = NULL;
 
        while (1) {
-               __msc_set_storage_scan_status(MS_STORAGE_SCAN_PREPARE);
                scan_data = g_async_queue_pop(storage_queue);
                if (scan_data->pid == POWEROFF) {
                        MS_DBG_WARN("power off");
                        goto _POWEROFF;
                }
 
-               __msc_set_storage_scan_status(MS_STORAGE_SCAN_PROCESSING);
                MS_DBG_WARN("STORAGE SCAN START [%s][%s]", scan_data->msg, scan_data->storage_id);
 
                scan_type = scan_data->msg_type;
@@ -758,7 +745,6 @@ gboolean msc_storage_scan_thread(void *data)
                        goto NEXT;
                }
 
-               /*connect to media db, if connecting is failed, db updating is stopped*/
                err = ms_connect_db(&handle, scan_data->uid);
                if (err != MS_MEDIA_ERR_NONE)
                        continue;
@@ -770,20 +756,18 @@ gboolean msc_storage_scan_thread(void *data)
                update_path = strndup(scan_data->msg, scan_data->msg_size);
 
                if (strlen(scan_data->storage_id) > 0) {
-                       /*MS_DBG("path : [%s], storage_id : [%s]", scan_data->msg, scan_data->storage_id);*/
-                       storage_id = strdup(scan_data->storage_id);
+                       storage_id = g_strdup(scan_data->storage_id);
+                       if (storage_id == NULL) {
+                               MS_DBG_ERR("storage_id NULL");
+                               ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+                               goto NEXT;
+                       }
                } else {
                        MS_DBG_ERR("storage_id length is 0. There is no information of your request [%s]", scan_data->msg);
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                        goto NEXT;
                }
 
-               if (storage_id == NULL) {
-                       MS_DBG_ERR("storage_id NULL");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto NEXT;
-               }
-
                ret = ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_PROCESSING, scan_data->uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_set_storage_scan_status[%d]", ret);
@@ -808,7 +792,6 @@ gboolean msc_storage_scan_thread(void *data)
 
                        if (dir_array->len != 0) {
                                MS_DBG_INFO("DB UPDATING IS NEEDED");
-
                                ret = _msc_db_update_partial(handle, storage_id, storage_type, dir_array, scan_data->uid);
                        } else {
                                MS_DBG_INFO("THERE IS NO UPDATE");
@@ -819,11 +802,6 @@ gboolean msc_storage_scan_thread(void *data)
                                if (!ms_delete_all_items(handle, storage_id, storage_type, scan_data->uid)) {
                                        MS_DBG_ERR("msc_delete_all_record fails");
                                }
-
-                               if (storage_type == MS_USER_STORAGE_EXTERNAL) {
-                                       /*storage info updated in media-server*/
-                                       /*ms_update_mmc_info();*/
-                               }
                        } else if (scan_type == MS_MSG_STORAGE_PARTIAL) {
                                ms_validaty_change_all_items(handle, storage_id, storage_type, false, scan_data->uid);
                        }
@@ -853,13 +831,9 @@ gboolean msc_storage_scan_thread(void *data)
 
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_STOP, scan_data->uid);
-                       __msc_set_storage_scan_status(MS_STORAGE_SCAN_STOP);
-                       /*set vconf key mmc loading for indicator */
                        ms_set_db_status(MS_DB_STOPPED, storage_type);
                } else {
                        ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_COMPLETE, scan_data->uid);
-                       __msc_set_storage_scan_status(MS_STORAGE_SCAN_COMPLETE);
-                       /*set vconf key mmc loading for indicator */
                        ms_set_db_status(MS_DB_UPDATED, storage_type);
                }
 
@@ -1215,7 +1189,6 @@ static int __msc_dir_scan_meta_update(void **handle, const char*start_path, cons
                /* get the current path from directory array */
                current_path = g_array_index(dir_array , char*, 0);
                g_array_remove_index(dir_array, 0);
-//             MS_DBG_SLOG("%d", dir_array->len);
 
                if (ms_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
@@ -1373,20 +1346,6 @@ void msc_metadata_update_thread(ms_comm_msg_s *recv_msg)
         g_thread_new("update_thread", (GThreadFunc)msc_metadata_update, recv_msg);
 }
 
-static int __msc_set_storage_scan_status(ms_storage_scan_status_e status)
-{
-       int res = MS_MEDIA_ERR_NONE;
-#if 0
-       if (!ms_config_set_int(MS_SCANNER_STATUS, status)) {
-               res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-               MS_DBG_ERR("ms_config_set_int failed");
-       }
-#else
-       stg_scan_status = status;
-#endif
-       return res;
-}
-
 int msc_init_scanner(void)
 {
        if (!scan_queue) scan_queue = g_async_queue_new();
@@ -1515,38 +1474,3 @@ END_REMOVE_REQUEST:
 
        return MS_MEDIA_ERR_NONE;
 }
-
-int msc_set_blocked_path(const char *blocked_path)
-{
-       MS_DBG_FENTER();
-       g_mutex_lock(&blocked_mutex);
-
-       if (g_blocked_path != NULL) {
-               MS_DBG_WARN("g_blocked_path is not NULL [%s]", g_blocked_path);
-               free(g_blocked_path);
-               g_blocked_path = NULL;
-       }
-
-       g_blocked_path = strdup(blocked_path);
-
-       g_mutex_unlock(&blocked_mutex);
-       MS_DBG_FLEAVE();
-       return MS_MEDIA_ERR_NONE;
-}
-
-int msc_del_blocked_path(void)
-{
-       MS_DBG_FENTER();
-       g_mutex_lock(&blocked_mutex);
-
-       if (g_blocked_path != NULL) {
-               MS_DBG_WARN("g_blocked_path is not NULL [%s]", g_blocked_path);
-               free(g_blocked_path);
-               g_blocked_path = NULL;
-       }
-
-       g_mutex_unlock(&blocked_mutex);
-       MS_DBG_FLEAVE();
-       return MS_MEDIA_ERR_NONE;
-}
-
index 58542da..faaca22 100755 (executable)
@@ -33,7 +33,6 @@
 
 #include "media-util.h"
 #include "media-scanner-dbg.h"
-#include "media-scanner-device-block.h"
 #include "media-scanner-scan.h"
 #include "media-scanner-socket.h"
 
@@ -167,12 +166,10 @@ static void __msc_add_event_receiver(void *data)
 {
        /*set power off callback function*/
        ms_sys_set_poweroff_cb(__msc_power_off_cb, NULL);
-       ms_sys_set_device_block_event_cb(msc_device_block_changed_cb, NULL);
 }
 
 static void __msc_remove_event_receiver(void)
 {
-       ms_sys_unset_device_block_event_cb();
        ms_sys_unset_poweroff_cb();
 }
 
index dfef975..a0e42e4 100755 (executable)
@@ -407,26 +407,6 @@ void _ms_change_lang_vconf_cb(keynode_t *key, void* data)
        return;
 }
 
-static int _mkdir(const char *dir, mode_t mode)
-{
-       char tmp[256];
-       char *p = NULL;
-       size_t len;
-
-       snprintf(tmp, sizeof(tmp), "%s", dir);
-       len = strlen(tmp);
-       if (tmp[len - 1] == '/')
-               tmp[len - 1] = 0;
-       for (p = tmp + 1; *p; p++)
-               if (*p == '/') {
-                       *p = 0;
-                       mkdir(tmp, mode);
-                       *p = '/';
-               }
-
-       return mkdir(tmp, mode);
-}
-
 int main(int argc, char **argv)
 {
        GThread *db_thread = NULL;
@@ -540,7 +520,7 @@ static void __ms_add_request_receiver(GMainLoop *mainloop, GIOChannel **channel)
 
        /*prepare socket*/
        /* create dir socket */
-       _mkdir(tzplatform_mkpath(TZ_SYS_RUN, "media-server"), S_IRWXU | S_IRWXG | S_IRWXO);
+       g_mkdir_with_parents(tzplatform_mkpath(TZ_SYS_RUN, "media-server"), S_IRWXU | S_IRWXG | S_IRWXO);
 
        /* Create and bind new UDP socket */
        if (ms_ipc_create_server_socket(MS_SCANNER_PORT, &sockfd) != MS_MEDIA_ERR_NONE) {