diff options
author | Jihoon Jung <jh8801.jung@example.com> | 2019-01-30 15:43:53 +0900 |
---|---|---|
committer | Jihoon Jung <jh8801.jung@example.com> | 2019-01-30 15:44:23 +0900 |
commit | 427418127fa0d6fdfb797121e8c3e45a9e25f82a (patch) | |
tree | f1a476254e9f5face6acb9d094c2605bbdc688ef | |
parent | 05ac2a96a4bf19d7ef82564a17ed803603623bee (diff) | |
download | mtp-responder-427418127fa0d6fdfb797121e8c3e45a9e25f82a.tar.gz mtp-responder-427418127fa0d6fdfb797121e8c3e45a9e25f82a.tar.bz2 mtp-responder-427418127fa0d6fdfb797121e8c3e45a9e25f82a.zip |
MTP responder Bug Fixsubmit/tizen/20190131.014348accepted/tizen/unified/20190131.161440
When folder have images, if you copy the folder into another folder,
Then you can not see the images in the folder.
Cause : Mtp Store is not updated.
Fix : Fix to store to be updated when copying.
Change-Id: Iad3b1b0bce103c37a332e2010777a704e0356f58
Signed-off-by: Jihoon Jung <jh8801.jung@example.com>
-rw-r--r-- | include/util/mtp_fs.h | 2 | ||||
-rw-r--r-- | src/mtp_cmd_handler_util.c | 4 | ||||
-rw-r--r-- | src/util/mtp_fs.c | 57 |
3 files changed, 58 insertions, 5 deletions
diff --git a/include/util/mtp_fs.h b/include/util/mtp_fs.h index ef47e06..7bea5d0 100644 --- a/include/util/mtp_fs.h +++ b/include/util/mtp_fs.h @@ -81,7 +81,7 @@ mtp_bool _util_file_seek(FILE* fhandle, off_t offset, mtp_int32 whence); mtp_bool _util_file_copy(const mtp_char *origpath, const mtp_char *newpath, mtp_int32 *error); mtp_bool _util_copy_dir_children_recursive(const mtp_char *origpath, - const mtp_char *newpath, mtp_int32 *error); + const mtp_char *newpath, mtp_uint32 store_id, mtp_int32 *error); mtp_bool _util_file_move(const mtp_char *origpath, const mtp_char *newpath, mtp_int32 *error); mtp_bool _util_get_file_attrs(const mtp_char *filename, file_attr_t *attrs); diff --git a/src/mtp_cmd_handler_util.c b/src/mtp_cmd_handler_util.c index 56e275b..aa14b0d 100644 --- a/src/mtp_cmd_handler_util.c +++ b/src/mtp_cmd_handler_util.c @@ -778,7 +778,7 @@ mtp_err_t _hutil_copy_object_entries(mtp_uint32 dst_store_id, */ if (FALSE == keep_handle) { if (FALSE == _util_copy_dir_children_recursive(obj->file_path, - new_obj->file_path, &error)) { + new_obj->file_path, dst_store_id, &error)) { ERR_SECURE("Recursive copy Fail [%s]->[%s]", obj->file_path, new_obj->file_path); ret = MTP_ERROR_GENERAL; @@ -832,7 +832,7 @@ mtp_err_t _hutil_copy_object_entries(mtp_uint32 dst_store_id, */ if (!((child_arr.num_ele > 0) || _util_copy_dir_children_recursive(obj->file_path, - new_obj->file_path, &error))) { + new_obj->file_path, dst_store_id, &error))) { ERR_SECURE("Recursive copy Fail [%d], [%s]->[%s]", child_arr.num_ele, obj->file_path, new_obj->file_path); diff --git a/src/util/mtp_fs.c b/src/util/mtp_fs.c index fdc3975..ec3f2c7 100644 --- a/src/util/mtp_fs.c +++ b/src/util/mtp_fs.c @@ -31,6 +31,7 @@ #include "mtp_util.h" #include "mtp_support.h" #include "ptp_datacodes.h" +#include "mtp_device.h" /* * FUNCTIONS @@ -335,7 +336,7 @@ mtp_bool _util_file_copy(const mtp_char *origpath, const mtp_char *newpath, } mtp_bool _util_copy_dir_children_recursive(const mtp_char *origpath, - const mtp_char *newpath, mtp_int32 *error) + const mtp_char *newpath, mtp_uint32 store_id, mtp_int32 *error) { DIR *dir = NULL; struct dirent entry = { 0 }; @@ -376,18 +377,66 @@ mtp_bool _util_copy_dir_children_recursive(const mtp_char *origpath, return FALSE; } + /* Create new mtp object */ + mtp_store_t *store = _device_get_store(store_id); + if (store == NULL) { + ERR("store is NULL"); + closedir(dir); + return FALSE; + } + + mtp_obj_t *orig_obj = _entity_get_object_from_store_by_path(store, old_pathname); + if (orig_obj == NULL) { + ERR("orig_obj is NULL"); + closedir(dir); + return FALSE; + } + + mtp_obj_t *parent_obj = _entity_get_object_from_store_by_path(store, newpath); + if (parent_obj == NULL) { + ERR("orig_obj is NULL"); + closedir(dir); + return FALSE; + } + + mtp_obj_t *new_obj = _entity_alloc_mtp_object(); + if (new_obj == NULL) { + ERR("_entity_alloc_mtp_object Fail"); + closedir(dir); + return FALSE; + } + + memset(new_obj, 0, sizeof(mtp_obj_t)); + + new_obj->child_array.type = UINT32_TYPE; + _entity_copy_mtp_object(new_obj, orig_obj); + if (new_obj->obj_info == NULL) { + _entity_dealloc_mtp_obj(new_obj); + closedir(dir); + return FALSE; + } + + _entity_set_object_file_path(new_obj, new_pathname, CHAR_TYPE); + new_obj->obj_handle = _entity_generate_next_obj_handle(); + new_obj->obj_info->h_parent = parent_obj->obj_handle; + if (S_ISDIR(entryinfo.st_mode)) { if (FALSE == _util_dir_create(new_pathname, error)) { /* dir already exists merge the contents */ if (EEXIST != *error) { ERR("directory[%s] create Fail errno [%d]\n", new_pathname, errno); + _entity_dealloc_mtp_obj(new_obj); closedir(dir); return FALSE; } } + + /* The directory is created. Add object to mtp store */ + _entity_add_object_to_store(store, new_obj); + if (FALSE == _util_copy_dir_children_recursive(old_pathname, - new_pathname, error)) { + new_pathname, store_id, error)) { ERR("Recursive Copy of Children Fail\ [%s]->[%s], errno [%d]\n", old_pathname, new_pathname, errno); closedir(dir); @@ -402,6 +451,7 @@ mtp_bool _util_copy_dir_children_recursive(const mtp_char *origpath, on destination */ if (EACCES == *error) goto DONE; + _entity_dealloc_mtp_obj(new_obj); closedir(dir); return FALSE; } @@ -416,11 +466,14 @@ mtp_bool _util_copy_dir_children_recursive(const mtp_char *origpath, MTP_FILE_ATTR_MODE_READ_ONLY); if (!ret) { ERR("Failed to set directory attributes errno [%d]\n", errno); + _entity_dealloc_mtp_obj(new_obj); closedir(dir); return FALSE; } } #endif /* MTP_SUPPORT_SET_PROTECTION */ + /* The file is created. Add object to mtp store */ + _entity_add_object_to_store(store, new_obj); } DONE: retval = readdir_r(dir, &entry, &entryptr); |