Tizen 2.0 Release
[apps/core/preloaded/myfiles.git] / src / common / file-system / mf-fs-oper.c
1 /*
2  * Copyright 2013         Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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
7  *
8  *  http://floralicense.org/license/
9  *
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.
15  */
16
17
18
19
20 #include <libgen.h>
21 #include <glib.h>
22 #include <errno.h>
23
24 #include "mf-fs-util.h"
25 #include "mf-util.h"
26
27 static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
28 static int __mf_fs_oper_sort_by_date_cb_O2R(const void *d1, const void *d2);
29 static int __mf_fs_oper_sort_by_name_cb_A2Z(const void *d1, const void *d2);
30 static int __mf_fs_oper_sort_by_type_cb_A2Z(const void *d1, const void *d2);
31 static int __mf_fs_oper_sort_by_size_cb_S2L(const void *d1, const void *d2);
32 static int __mf_fs_oper_sort_by_name_cb_Z2A(const void *d1, const void *d2);
33 static int __mf_fs_oper_sort_by_date_cb_R2O(const void *d1, const void *d2);
34 static int __mf_fs_oper_sort_by_type_cb_Z2A(const void *d1, const void *d2);
35 static int __mf_fs_oper_sort_by_size_cb_L2S(const void *d1, const void *d2);
36
37 /*********************
38 **Function name:        mf_fs_oper_print_node
39 **Parameter:
40 **      fsNodeInfo *pNode:      the file system node information need to print
41 **
42 **Return value:
43 **      void
44 **
45 **Action:
46 **      printf the file system node information for debug
47 **
48 *********************/
49 void mf_fs_oper_print_node(fsNodeInfo *pNode)
50 {
51         if (pNode) {
52                 /*mf_debug("path is [%s]\nname is [%s]\ndate is [%s]\ntype is [%d]\nsize is [%u]\nextension is [%s]\n\n",pNode->path,
53                    pNode->name,asctime(gmtime(&(pNode->date))),pNode->type,pNode->size, pNode->ext);
54                  */
55         }
56 }
57
58 /*********************
59 **Function name:        mf_fs_oper_get_file
60 **Parameter:
61 **      const char *path:       full path to get file name
62 **
63 **Return value:
64 **      const char*:    file name
65 **
66 **Action:
67 **      get file name from full path
68 **
69 *********************/
70 static const char *mf_fs_oper_get_file(const char *path)
71 {
72         char *result = NULL;
73
74         if (!path) {
75                 return NULL;
76         }
77         if ((result = strrchr(path, '/'))) {
78                 result++;
79         } else {
80                 result = (char *)path;
81         }
82         return result;
83 }
84
85 /*********************
86 **Function name:        mf_fs_oper_error
87 **Parameter:
88 **      const char* src:        source path
89 **      const char* dst:        destination path
90 **      int check_option:       check option
91 **
92 **Return value:
93 **      error code
94 **
95 **Action:
96 **      input parameter checking
97 **
98 *********************/
99 int mf_fs_oper_error(const char *src, const char *dst, int check_option)
100 {
101         if ((check_option & MF_ERROR_CHECK_SRC_ARG_VALID) && (src == NULL)) {
102                 return MYFILE_ERR_SRC_ARG_INVALID;
103         }
104         if ((check_option & MF_ERROR_CHECK_DST_ARG_VALID) && (dst == NULL)) {
105                 return MYFILE_ERR_DST_ARG_INVALID;
106         }
107
108         if ((check_option & MF_ERROR_CHECK_SRC_EXIST) && (!ecore_file_exists(src))) {
109                 return MYFILE_ERR_SRC_NOT_EXIST;
110         }
111         if ((check_option & MF_ERROR_CHECK_DST_EXIST) && (!ecore_file_exists(dst))) {
112                 return MYFILE_ERR_DST_NOT_EXIST;
113         }
114
115         if (check_option & MF_ERROR_CHECK_SRC_PATH_VALID) {
116                 if (!ecore_file_is_dir(src)) {
117                         if (mf_file_attr_is_right_file_path(src)) {
118                                 return MYFILE_ERR_INVALID_FILE_PATH;
119                         }
120                 } else {
121                         if (mf_file_attr_is_right_dir_path(src)) {
122                                 return MYFILE_ERR_INVALID_DIR_PATH;
123                         }
124                 }
125         }
126         if (check_option & MF_ERROR_CHECK_DST_PATH_VALID) {
127                 if (!ecore_file_is_dir(dst)) {
128                         int ret = mf_file_attr_is_right_file_path(dst);
129                         if (ret != 0) {
130                                 return ret;
131                         }
132                 } else {
133                         int ret = mf_file_attr_is_right_dir_path(dst);
134                         if (ret != 0) {
135                                 return ret;
136                         }
137                 }
138         }
139
140         if (check_option & MF_ERROR_CHECK_SRC_PARENT_DIR_EXIST) {
141                 char *parent_path = NULL;
142                 if (mf_file_attr_get_parent_path(src, &parent_path)) {
143                                 if (!ecore_file_exists(parent_path)) {
144                                 SAFE_FREE_CHAR(parent_path);
145                                         return MYFILE_ERR_DIR_NOT_FOUND;
146                                 }
147                         }
148                 SAFE_FREE_CHAR(parent_path);
149         }
150
151         if (check_option & MF_ERROR_CHECK_DST_PARENT_DIR_EXIST) {
152                 char *parent_path = NULL;
153                 if (mf_file_attr_get_parent_path(dst, &parent_path)) {
154                                 if (!ecore_file_exists(parent_path)) {
155                                 SAFE_FREE_CHAR(parent_path);
156                                         return MYFILE_ERR_DIR_NOT_FOUND;
157                                 }
158                         }
159                 SAFE_FREE_CHAR(parent_path);
160         }
161
162         if (check_option & MF_ERROR_CHECK_DUPLICATED) {
163                 char *parent_path = NULL;
164
165                 if (!mf_file_attr_get_parent_path(dst, &parent_path)) {
166                         if (mf_file_attr_is_duplicated_name(parent_path, mf_fs_oper_get_file(dst))) {
167                                 SAFE_FREE_CHAR(parent_path);
168                                 return MYFILE_ERR_DUPLICATED_NAME;
169                         }
170                         SAFE_FREE_CHAR(parent_path);
171                 } else {
172                         SAFE_FREE_CHAR(parent_path);
173                         return MYFILE_ERR_GET_PARENT_PATH_FAIL;
174                 }
175         }
176
177         return MYFILE_ERR_NONE;
178 }
179
180 /*********************
181 **Function name:        mf_fs_oper_read_dir
182 **Parameter:
183 **      char *path:                             path which we need to read
184 **      Eina_List** dir_list:   output parameter of dir list under specified path
185 **      Eina_List** file_list:  output parameter of file list under specified path
186 **
187 **Return value:
188 **      error code
189 **
190 **Action:
191 **      read element under the specified path
192 **
193 *********************/
194 int mf_fs_oper_read_dir(const char *path, Eina_List ** dir_list, Eina_List ** file_list)
195 {
196         DIR *pDir = NULL;
197         struct dirent *ent;
198
199         mf_retvm_if(path == NULL, MYFILE_ERR_INVALID_ARG, "path is null");
200         mf_retvm_if(dir_list == NULL, MYFILE_ERR_INVALID_ARG, "dir_list is null");
201         mf_retvm_if(file_list == NULL, MYFILE_ERR_INVALID_ARG, "file_list is null");
202         int option = MF_ERROR_CHECK_SRC_ARG_VALID | MF_ERROR_CHECK_SRC_EXIST | MF_ERROR_CHECK_SRC_PATH_VALID;
203         int ret = mf_fs_oper_error(path, NULL, option);
204         if (ret != MYFILE_ERR_NONE) {
205                 return ret;
206         }
207
208         pDir = opendir(path);
209
210         if (pDir == NULL) {
211                 return MYFILE_ERR_DIR_OPEN_FAIL;
212         }
213
214         while ((ent = readdir(pDir)) != NULL) {
215                 GString *childpath = NULL;
216                 fsNodeInfo *pNode = NULL;
217
218                 if (strncmp(ent->d_name, ".", strlen(".")) == 0 || strncmp(ent->d_name, "..", strlen("..")) == 0) {
219                         continue;
220                 }
221
222                 if ((ent->d_type & DT_DIR) == 0 && (ent->d_type & DT_REG) == 0) {
223                         continue;
224                 }
225                 if ((ent->d_type & DT_DIR) != 0) {
226                         if ((strlen(path) == strlen(PHONE_FOLDER)) && (strcmp(path, PHONE_FOLDER) == 0)
227                             && (strlen(ent->d_name) == strlen(DEBUG_FOLDER)) && (strcmp(ent->d_name, DEBUG_FOLDER) == 0)) {
228                                 continue;
229                         }
230                 }
231
232                 pNode = (fsNodeInfo *) malloc(sizeof(fsNodeInfo));
233
234                 if (pNode == NULL) {
235                         continue;
236                 }
237                 memset(pNode, 0, sizeof(fsNodeInfo));
238                 /*set path */
239                 pNode->path = g_strdup(path);
240                 /*set name */
241                 pNode->name = g_strdup(ent->d_name);
242                 /*set type */
243                 if (ent->d_type & DT_DIR) {
244                         pNode->type = FILE_TYPE_DIR;
245                 } else if (ent->d_type & DT_REG) {
246                         mf_file_attr_get_file_category(ent->d_name, &(pNode->type));
247                 }
248                 /*set date & size */
249                 childpath = g_string_new(path);
250                 if (childpath == NULL) {
251
252                         free(pNode);
253                         pNode = NULL;
254                         continue;
255                 }
256                 g_string_append_printf(childpath, "/%s", ent->d_name);
257                 mf_file_attr_get_file_stat(childpath->str, &pNode);
258                 if (pNode->type == FILE_TYPE_DIR) {
259                         *dir_list = eina_list_append(*dir_list, pNode);
260                 } else {
261                         ret = mf_file_attr_get_file_ext(childpath->str, &pNode->ext);
262                         if (ret != MYFILE_ERR_NONE) {
263                                 pNode->ext = NULL;
264                         }
265                         *file_list = eina_list_append(*file_list, pNode);
266                 }
267
268                 g_string_free(childpath, TRUE);
269         }
270         closedir(pDir);
271
272         return MYFILE_ERR_NONE;
273 }
274
275
276 static int __mf_fs_oper_sort_by_priority(const void *d1, const void *d2, int sequence_type)
277 {
278         int ret = 0;
279         switch(sequence_type) {
280         case MF_SORT_BY_PRIORITY_TYPE_A2Z:
281                 ret = __mf_fs_oper_sort_by_date_cb_O2R(d1, d2);
282                 if (ret == 0) {
283                         ret = __mf_fs_oper_sort_by_size_cb_S2L(d1, d2);
284                         if (ret == 0) {
285                                 ret = __mf_fs_oper_sort_by_name_cb_A2Z(d1, d2);
286                         }
287                 }
288                 break;
289         case MF_SORT_BY_PRIORITY_TYPE_Z2A:
290                 ret = __mf_fs_oper_sort_by_date_cb_R2O(d1, d2);
291                 if (ret == 0) {
292                         ret = __mf_fs_oper_sort_by_size_cb_L2S(d1, d2);
293                         if (ret == 0) {
294                                 ret = __mf_fs_oper_sort_by_name_cb_Z2A(d1, d2);
295                         }
296                 }
297                 break;
298         case MF_SORT_BY_PRIORITY_DATE_O2R:
299                 ret = __mf_fs_oper_sort_by_size_cb_S2L(d1, d2);
300                 if (ret == 0) {
301                         ret = __mf_fs_oper_sort_by_name_cb_A2Z(d1, d2);
302                 }
303                 break;
304         case MF_SORT_BY_PRIORITY_DATE_R2O:
305                 ret = __mf_fs_oper_sort_by_size_cb_L2S(d1, d2);
306                 if (ret == 0) {
307                         ret = __mf_fs_oper_sort_by_name_cb_Z2A(d1, d2);
308                 }
309                 break;
310         case MF_SORT_BY_PRIORITY_SIZE_S2L:
311                 ret = __mf_fs_oper_sort_by_name_cb_A2Z(d1, d2);
312                 break;
313         case MF_SORT_BY_PRIORITY_SIZE_L2S:
314                 ret = __mf_fs_oper_sort_by_name_cb_Z2A(d1, d2);
315                 break;
316         default:
317                 break;
318         }
319         return ret;
320 }
321 /*********************
322 **Function name:        __sort_by_name_cb
323 **Parameter:
324 **      const void *d1: node1 to compare
325 **      const void *d2: node2 to compare
326 **
327 **Return value:
328 **      -1      if d1 > d2
329 **      0       if d1 = d2
330 **      1       if d1 > d2
331 **
332 **Action:
333 **      sort the list order by the Assic table
334
335 **
336 *********************/
337 static int __mf_fs_oper_sort_by_name_cb_A2Z(const void *d1, const void *d2)
338 {
339         fsNodeInfo *txt1 = (fsNodeInfo *) d1;
340         fsNodeInfo *txt2 = (fsNodeInfo *) d2;
341         gchar *name1 = NULL;
342         gchar *name2 = NULL;
343         int result = 0;
344
345         if (!txt1 || !txt1->name) {
346                 return (1);
347         }
348         if (!txt2 || !txt2->name) {
349                 return (-1);
350         }
351
352         name1 = g_ascii_strdown(txt1->name, strlen(txt1->name));
353         if (name1 == NULL) {
354                 return (-1);
355         }
356         name2 = g_ascii_strdown(txt2->name, strlen(txt2->name));
357         if (name2 == NULL) {
358                 g_free(name1);
359                 name1 = NULL;
360                 return (-1);
361         }
362         result = g_strcmp0(name1, name2);
363
364         g_free(name1);
365         name1 = NULL;
366         g_free(name2);
367         name2 = NULL;
368         return result;
369
370 }
371
372 /*********************
373 **Function name:        __sort_by_date_cb
374 **Parameter:
375 **      const void *d1: node1 to compare
376 **      const void *d2: node2 to compare
377 **
378 **Return value:
379 **      -1      if d1 > d2
380 **      0       if d1 = d2
381 **      1       if d1 > d2
382 **
383 **Action:
384 **      sort the list order by the later created the later shown
385 *********************/
386 static int __mf_fs_oper_sort_by_date_cb_O2R(const void *d1, const void *d2)
387 {
388         int ret = 0;
389         fsNodeInfo *time1 = (fsNodeInfo *) d1;
390         fsNodeInfo *time2 = (fsNodeInfo *) d2;
391
392         if (!d1) {
393                 return 1;
394         }
395         if (!d2) {
396                 return -1;
397         }
398
399         if (time1->date > time2->date) {
400                 ret = 1;
401         } else if (time1->date < time2->date) {
402                 ret = -1;
403         } else {
404                 ret = 0;
405         }
406
407         if (ret == 0) {
408                 ret = __mf_fs_oper_sort_by_priority(d1, d2, MF_SORT_BY_PRIORITY_DATE_O2R);
409         }
410         return ret;
411 }
412
413 /*********************
414 **Function name:        __sort_by_type_cb
415 **Parameter:
416 **      const void *d1: node1 to compare
417 **      const void *d2: node2 to compare
418 **
419 **Return value:
420 **      -1      if d1 < d2
421 **      0       if d1 = d2
422 **      1       if d1 > d2
423 **
424 **Action:
425 **      sort the list order by the category type value
426 *********************/
427 static int __mf_fs_oper_sort_by_type_cb_A2Z(const void *d1, const void *d2)
428 {
429         fsNodeInfo *type1 = (fsNodeInfo *) d1;
430         fsNodeInfo *type2 = (fsNodeInfo *) d2;
431         gchar *ext1 = NULL;
432         gchar *ext2 = NULL;
433         int result = 0;
434
435         if (type1 == NULL || type1->ext == NULL) {
436                 return 1;
437         }
438
439         if (type2 == NULL || type2->ext == NULL) {
440                 return -1;
441         }
442         ext1 = g_ascii_strdown(type1->ext, strlen(type1->ext));
443         if (ext1 == NULL) {
444                 return (-1);
445         }
446         ext2 = g_ascii_strdown(type2->ext, strlen(type2->ext));
447         if (ext2 == NULL) {
448                 g_free(ext1);
449                 ext1 = NULL;
450                 return (-1);
451         }
452         result = g_strcmp0(ext1, ext2);
453
454         g_free(ext1);
455         ext1 = NULL;
456         g_free(ext2);
457         ext2 = NULL;
458
459         if (result == 0) {
460                 result = __mf_fs_oper_sort_by_priority(d1, d2, MF_SORT_BY_PRIORITY_TYPE_A2Z);
461         }
462
463         return result;
464 }
465
466 /*order:        the one with smaller size will be shown earlier*/
467 /*********************
468 **Function name:        __sort_by_name_cb
469 **Parameter:
470 **      const void *d1: node1 to compare
471 **      const void *d2: node2 to compare
472 **
473 **Return value:
474 **      -1      if d1 > d2
475 **      0       if d1 = d2
476 **      1       if d1 > d2
477 **
478 **Action:
479 **      sort the list order by size, rule is the smaller the later shown
480 *********************/
481 static int __mf_fs_oper_sort_by_size_cb_S2L(const void *d1, const void *d2)
482 {
483         int ret = 0;
484         fsNodeInfo *size1 = (fsNodeInfo *) d1;
485         fsNodeInfo *size2 = (fsNodeInfo *) d2;
486
487         if (!d1) {
488                 return 1;
489         }
490
491         if (!d2) {
492                 return -1;
493         }
494
495         if (size1->size > size2->size) {
496                 ret = 1;
497         } else if (size1->size < size2->size) {
498                 ret = -1;
499         } else {
500                 ret = 0;
501         }
502
503         if (ret == 0) {
504                 ret = __mf_fs_oper_sort_by_priority(d1, d2, MF_SORT_BY_PRIORITY_SIZE_S2L);
505         }
506         return ret;
507 }
508
509 /*********************
510 **Function name:        __mf_fs_oper_sort_by_name_cb_Z2A
511 **Parameter:
512 **      const void *d1: node1 to compare
513 **      const void *d2: node2 to compare
514 **
515 **Return value:
516 **      1       if d1 > d2
517 **      -1      if d1 <= d2
518 **
519 **Action:
520 **      sort the list order by the Assic table
521
522 **
523 *********************/
524 static int __mf_fs_oper_sort_by_name_cb_Z2A(const void *d1, const void *d2)
525 {
526         fsNodeInfo *txt1 = (fsNodeInfo *) d1;
527         fsNodeInfo *txt2 = (fsNodeInfo *) d2;
528
529         int result = 0;
530
531         if (!txt1 || !txt1->name) {
532                 return (1);
533         }
534         if (!txt2 || !txt2->name) {
535                 return (-1);
536         }
537         result = strcasecmp(txt1->name, txt2->name);
538
539         if (result < 0) {
540                 return (1);
541         } else {
542                 return (-1);
543         }
544 }
545
546 /*********************
547 **Function name:        __sort_by_date_cb
548 **Parameter:
549 **      const void *d1: node1 to compare
550 **      const void *d2: node2 to compare
551 **
552 **Return value:
553 **      -1      if d1 > d2
554 **      0       if d1 = d2
555 **      1       if d1 < d2
556 **
557 **Action:
558 **      sort the list order by the later created the later shown
559 *********************/
560 static int __mf_fs_oper_sort_by_date_cb_R2O(const void *d1, const void *d2)
561 {
562         int ret = 0;
563         fsNodeInfo *time1 = (fsNodeInfo *) d1;
564         fsNodeInfo *time2 = (fsNodeInfo *) d2;
565
566         if (!d1) {
567                 return -1;
568         }
569         if (!d2) {
570                 return 1;
571         }
572         if (time1->date > time2->date) {
573                 ret = -1;
574         } else if (time1->date < time2->date) {
575                 ret = 1;
576         } else {
577                 ret = 0;
578         }
579
580         if (ret == 0) {
581                 ret = __mf_fs_oper_sort_by_priority(d1, d2, MF_SORT_BY_PRIORITY_DATE_R2O);
582         }
583         return ret;
584 }
585
586 /*********************
587 **Function name:        __sort_by_type_cb
588 **Parameter:
589 **      const void *d1: node1 to compare
590 **      const void *d2: node2 to compare
591 **
592 **Return value:
593 **      -1      if d1 > d2
594 **      0       if d1 = d2
595 **      1       if d1 < d2
596 **
597 **Action:
598 **      sort the list order by the category type value
599 *********************/
600 static int __mf_fs_oper_sort_by_type_cb_Z2A(const void *d1, const void *d2)
601 {
602         fsNodeInfo *type1 = (fsNodeInfo *) d1;
603         fsNodeInfo *type2 = (fsNodeInfo *) d2;
604         gchar *ext1 = NULL;
605         gchar *ext2 = NULL;
606         int result = 0;
607
608         if (type1 == NULL || type1->ext == NULL) {
609                 return -1;
610         }
611
612         if (type2 == NULL || type2->ext == NULL) {
613                 return 1;
614         }
615
616         ext1 = g_ascii_strdown(type1->ext, strlen(type1->ext));
617         if (ext1 == NULL) {
618                 return (1);
619         }
620         ext2 = g_ascii_strdown(type2->ext, strlen(type2->ext));
621         if (ext2 == NULL) {
622                 g_free(ext1);
623                 ext1 = NULL;
624                 return (-1);
625         }
626         result = g_strcmp0(ext1, ext2);
627         g_free(ext1);
628         ext1 = NULL;
629         g_free(ext2);
630         ext2 = NULL;
631         if (result == 0) {
632                 result = __mf_fs_oper_sort_by_priority(d1, d2, MF_SORT_BY_PRIORITY_TYPE_Z2A);
633         }
634
635         return -result;
636 }
637
638 /*order:        the one with smaller size will be shown earlier*/
639 /*********************
640 **Function name:        __sort_by_name_cb
641 **Parameter:
642 **      const void *d1: node1 to compare
643 **      const void *d2: node2 to compare
644 **
645 **Return value:
646 **      -1      if d1 > d2
647 **      0       if d1 = d2
648 **      1       if d1 < d2
649 **
650 **Action:
651 **      sort the list order by size, rule is the smaller the later shown
652 *********************/
653 static int __mf_fs_oper_sort_by_size_cb_L2S(const void *d1, const void *d2)
654 {
655         int ret = 0;
656         fsNodeInfo *size1 = (fsNodeInfo *) d1;
657         fsNodeInfo *size2 = (fsNodeInfo *) d2;
658
659         if (!d1) {
660                 return -1;
661         }
662
663         if (!d2) {
664                 return 1;
665         }
666
667         if (size1->size > size2->size) {
668                 ret = -1;
669         } else if (size1->size < size2->size) {
670                 ret = 1;
671         } else {
672                 ret = 0;
673         }
674
675         if (ret == 0) {
676                 ret = __mf_fs_oper_sort_by_priority(d1, d2, MF_SORT_BY_PRIORITY_SIZE_L2S);
677         }
678         return ret;
679 }
680
681 /*********************
682 **Function name:        mf_fs_oper_sort_list
683 **Parameter:
684 **      Eina_List **list:       the list we need to sort
685 **      int sort_opt:           sort option
686 **
687 **Return value:
688 **      void
689 **
690 **Action:
691 **      sort the list order by sort option with the call back
692 *********************/
693 void mf_fs_oper_sort_list(Eina_List **list, int sort_opt)
694 {
695         Eina_Compare_Cb sort_func = NULL;
696         Eina_List *l = NULL;
697         fsNodeInfo *data = NULL;
698         if (!(*list)) {
699                 return;
700         }
701         switch (sort_opt) {
702         case MYFILE_SORT_BY_NAME_A2Z:
703                 sort_func = __mf_fs_oper_sort_by_name_cb_A2Z;
704                 break;
705         case MYFILE_SORT_BY_TYPE_A2Z:
706                 sort_func = __mf_fs_oper_sort_by_type_cb_A2Z;
707                 break;
708         case MYFILE_SORT_BY_SIZE_S2L:
709                 sort_func = __mf_fs_oper_sort_by_size_cb_S2L;
710                 break;
711         case MYFILE_SORT_BY_DATE_O2R:
712                 sort_func = __mf_fs_oper_sort_by_date_cb_O2R;
713                 break;
714         case MYFILE_SORT_BY_NAME_Z2A:
715                 sort_func = __mf_fs_oper_sort_by_name_cb_Z2A;
716                 break;
717         case MYFILE_SORT_BY_TYPE_Z2A:
718                 sort_func = __mf_fs_oper_sort_by_type_cb_Z2A;
719                 break;
720         case MYFILE_SORT_BY_SIZE_L2S:
721                 sort_func = __mf_fs_oper_sort_by_size_cb_L2S;
722                 break;
723         case MYFILE_SORT_BY_DATE_R2O:
724                 sort_func = __mf_fs_oper_sort_by_date_cb_R2O;
725                 break;
726         default:
727                 sort_func = __mf_fs_oper_sort_by_type_cb_A2Z;
728                 break;
729         }
730         EINA_LIST_FOREACH(*list, l, data) {
731                 mf_fs_oper_print_node(data);
732         }
733         *list = eina_list_sort(*list, eina_list_count(*list), sort_func);
734         EINA_LIST_FOREACH(*list, l, data) {
735                 mf_fs_oper_print_node(data);
736         }
737 }
738
739
740 /*********************
741 **Function name:        mf_fs_oper_create_dir
742 **Parameter:
743 **      const char *file:       dir need to be operation
744 **
745 **Return value:
746 **      error code
747 **
748 **Action:
749 **      create dir
750 *********************/
751 int mf_fs_oper_create_dir(const char *dir)
752 {
753         int option = MF_ERROR_CHECK_SRC_ARG_VALID | MF_ERROR_CHECK_DUPLICATED;
754         int ret = mf_fs_oper_error(dir, dir, option);
755
756         if (ret != 0) {
757                 return ret;
758         }
759
760         ret = mf_file_attr_is_right_dir_path(dir);
761
762         if (ret != 0) {
763                 return ret;
764         }
765
766         if (mkdir(dir, default_mode) < 0) {
767                 return MYFILE_ERR_DIR_CREATE_FAIL;
768         }
769         return MYFILE_ERR_NONE;
770 }
771
772 /*********************
773 **Function name:        mf_fs_oper_rename_file
774 **Parameter:
775 **      const char *src:        source file need to rename
776 **      const char *dst:        destination file which is to be renamed
777
778 **
779 **Return value:
780 **      error code
781 **
782 **Action:
783 **      rename a file
784 *********************/
785 int mf_fs_oper_rename_file(const char *src, const char *dst)
786 {
787         mf_debug();
788         int option = MF_ERROR_CHECK_SRC_ARG_VALID | MF_ERROR_CHECK_DST_ARG_VALID |
789                 MF_ERROR_CHECK_SRC_EXIST | MF_ERROR_CHECK_DST_PATH_VALID |
790                 MF_ERROR_CHECK_SRC_PATH_VALID | MF_ERROR_CHECK_SRC_PATH_VALID | MF_ERROR_CHECK_DST_PARENT_DIR_EXIST | MF_ERROR_CHECK_DUPLICATED;
791         int ret = mf_fs_oper_error(src, dst, option);
792
793         if (ret != 0) {
794                 return ret;
795         }
796
797         mf_debug("src is %s\ndst is %s\n", src, dst);
798         if (rename(src, dst)) {
799                 return MYFILE_ERR_RENAME_FAIL;
800         } else {
801                 return MYFILE_ERR_NONE;
802         }
803 }