MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / copydir

Function copydir

components/dfs/dfs_v1/src/dfs_file.c:958–1019  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

956
957extern int mkdir(const char *path, mode_t mode);
958static 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 }

Callers 1

copyFunction · 0.70

Calls 10

rt_kprintfFunction · 0.85
rt_memsetFunction · 0.85
rt_freeFunction · 0.85
dfs_file_openFunction · 0.70
dfs_file_getdentsFunction · 0.70
dfs_normalize_pathFunction · 0.70
dfs_file_statFunction · 0.70
mkdirFunction · 0.70
copyfileFunction · 0.70
dfs_file_closeFunction · 0.70

Tested by

no test coverage detected