| 956 | |
| 957 | extern int mkdir(const char *path, mode_t mode); |
| 958 | static void copydir(const char *src, const char *dst) |
| 959 | { |
| 960 | struct dirent dirent; |
| 961 | struct stat stat; |
| 962 | int length; |
| 963 | struct dfs_file cpfd; |
| 964 | if (dfs_file_open(&cpfd, src, O_DIRECTORY) < 0) |
| 965 | { |
| 966 | rt_kprintf("open %s failed\n", src); |
| 967 | return ; |
| 968 | } |
| 969 | |
| 970 | do |
| 971 | { |
| 972 | rt_memset(&dirent, 0, sizeof(struct dirent)); |
| 973 | |
| 974 | length = dfs_file_getdents(&cpfd, &dirent, sizeof(struct dirent)); |
| 975 | if (length > 0) |
| 976 | { |
| 977 | char *src_entry_full = NULL; |
| 978 | char *dst_entry_full = NULL; |
| 979 | |
| 980 | if (strcmp(dirent.d_name, "..") == 0 || strcmp(dirent.d_name, ".") == 0) |
| 981 | continue; |
| 982 | |
| 983 | /* build full path for each file */ |
| 984 | if ((src_entry_full = dfs_normalize_path(src, dirent.d_name)) == NULL) |
| 985 | { |
| 986 | rt_kprintf("out of memory!\n"); |
| 987 | break; |
| 988 | } |
| 989 | if ((dst_entry_full = dfs_normalize_path(dst, dirent.d_name)) == NULL) |
| 990 | { |
| 991 | rt_kprintf("out of memory!\n"); |
| 992 | rt_free(src_entry_full); |
| 993 | break; |
| 994 | } |
| 995 | |
| 996 | rt_memset(&stat, 0, sizeof(struct stat)); |
| 997 | if (dfs_file_stat(src_entry_full, &stat) != 0) |
| 998 | { |
| 999 | rt_kprintf("open file: %s failed\n", dirent.d_name); |
| 1000 | continue; |
| 1001 | } |
| 1002 | |
| 1003 | if (S_ISDIR(stat.st_mode)) |
| 1004 | { |
| 1005 | mkdir(dst_entry_full, 0); |
| 1006 | copydir(src_entry_full, dst_entry_full); |
| 1007 | } |
| 1008 | else |
| 1009 | { |
| 1010 | copyfile(src_entry_full, dst_entry_full); |
| 1011 | } |
| 1012 | rt_free(src_entry_full); |
| 1013 | rt_free(dst_entry_full); |
| 1014 | } |
| 1015 | } |
no test coverage detected