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

Function copy

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

Source from the content-addressed store, hash-verified

1029}
1030
1031void copy(const char *src, const char *dst)
1032{
1033#define FLAG_SRC_TYPE 0x03
1034#define FLAG_SRC_IS_DIR 0x01
1035#define FLAG_SRC_IS_FILE 0x02
1036#define FLAG_SRC_NON_EXSIT 0x00
1037
1038#define FLAG_DST_TYPE 0x0C
1039#define FLAG_DST_IS_DIR 0x04
1040#define FLAG_DST_IS_FILE 0x08
1041#define FLAG_DST_NON_EXSIT 0x00
1042
1043 struct stat stat;
1044 uint32_t flag = 0;
1045
1046 /* check the staus of src and dst */
1047 if (dfs_file_stat(src, &stat) < 0)
1048 {
1049 rt_kprintf("copy failed, bad %s\n", src);
1050 return;
1051 }
1052 if (S_ISDIR(stat.st_mode))
1053 flag |= FLAG_SRC_IS_DIR;
1054 else
1055 flag |= FLAG_SRC_IS_FILE;
1056
1057 if (dfs_file_stat(dst, &stat) < 0)
1058 {
1059 flag |= FLAG_DST_NON_EXSIT;
1060 }
1061 else
1062 {
1063 if (S_ISDIR(stat.st_mode))
1064 flag |= FLAG_DST_IS_DIR;
1065 else
1066 flag |= FLAG_DST_IS_FILE;
1067 }
1068
1069 /*2. check status*/
1070 if ((flag & FLAG_SRC_IS_DIR) && (flag & FLAG_DST_IS_FILE))
1071 {
1072 rt_kprintf("cp faild, cp dir to file is not permitted!\n");
1073 return ;
1074 }
1075
1076 /*3. do copy*/
1077 if (flag & FLAG_SRC_IS_FILE)
1078 {
1079 if (flag & FLAG_DST_IS_DIR)
1080 {
1081 char *fdst;
1082 fdst = dfs_normalize_path(dst, _get_path_lastname(src));
1083 if (fdst == NULL)
1084 {
1085 rt_kprintf("out of memory\n");
1086 return;
1087 }
1088 copyfile(src, fdst);

Callers 1

cmd_cpFunction · 0.50

Calls 8

rt_kprintfFunction · 0.85
rt_freeFunction · 0.85
dfs_file_statFunction · 0.70
dfs_normalize_pathFunction · 0.70
_get_path_lastnameFunction · 0.70
copyfileFunction · 0.70
mkdirFunction · 0.70
copydirFunction · 0.70

Tested by

no test coverage detected