Changeset 31018
- Timestamp:
- Apr 17, 2008, 12:55:07 AM (16 years ago)
- Location:
- grass/branches/releasebranch_6_3
- Files:
-
- 1 added
- 1 deleted
- 3 edited
-
general/manage/lib/Makefile (modified) (1 diff)
-
general/manage/lib/copyfile.c (deleted)
-
general/manage/lib/do_copy.c (modified) (5 diffs)
-
include/gisdefs.h (modified) (1 diff)
-
lib/gis/copy_dir.c (added)
Legend:
- Unmodified
- Added
- Removed
-
grass/branches/releasebranch_6_3/general/manage/lib/Makefile
r24848 r31018 4 4 5 5 LIB_NAME = $(MANAGE_LIBNAME) 6 7 LIB_OBJS = add_elem.o ask.o copyfile.o do_copy.o do_list.o do_remove.o \8 do_rename.o empty.o find.o get_len.o menu.o read_list.o \9 show_elem.o sighold.o10 6 11 7 LOCAL_HEADERS = $(wildcard *.h) ../list.h -
grass/branches/releasebranch_6_3/general/manage/lib/do_copy.c
r23024 r31018 1 1 #include <stdio.h> 2 2 #include <string.h> 3 #include <fcntl.h>4 3 #include <unistd.h> 5 #include <dirent.h>6 #include <sys/types.h>7 #include <sys/stat.h>8 4 #include <grass/gis.h> 9 5 #include <grass/Vect.h> 10 6 #include "list.h" 11 12 static int recursive_copy(const char *src, const char *dst);13 7 14 8 /* … … 19 13 { 20 14 int i, ret, len; 21 char path[ 1024], path2[1024];15 char path[GPATH_MAX], path2[GPATH_MAX]; 22 16 int result = 0; 23 17 … … 51 45 } 52 46 G__file_name (path2, list[n].element[i], new, G_mapset()); 53 if ( recursive_copy(path, path2) == 1 )47 if ( G_recursive_copy(path, path2) == 1 ) 54 48 { 55 49 result = 1; … … 66 60 if (G_strcasecmp (list[n].element[0], "cell") == 0) 67 61 { 68 char colr2[ 50];62 char colr2[GNAME_MAX]; 69 63 70 64 sprintf (colr2, "colr2/%s", G_mapset()); … … 76 70 } 77 71 78 /* RULE:79 * 1. If destination does not exist, copy source to destination as expected.80 * 2. If destination already exists and it's a file, destination will be81 * deleted first and apply RULE 1.82 * 3. If destination already exists which is a directory and source is a file,83 * try to copy source to destination directory.84 * 4. If destination already exists which is a directory and source is also a85 * directory, try to copy all contents in source to destination directory.86 *87 * This rule is designed according to general/manage/lib/copy.sh.88 *89 * POSSIBLE CASES:90 * if src is a file:91 * if dst does not exist:92 * copy src to dst RULE 193 * if dst is a file:94 * delete dst and copy src to dst RULE 295 * if dst is a directory:96 * try recursive_copy(src, dst/src) RULE 397 * if src is a directory:98 * if dst does not exist:99 * copy src to dst RULE 1100 * if dst is a file:101 * delete dst and copy src to dst RULE 2102 * if dst is a directory:103 * try RULE 4104 * for i in `ls src`105 * do106 * recursive_copy(src/$i, dst/$i)107 * done108 *109 * RETURN: 0 if successful, otherwise 1110 */111 static int112 recursive_copy(const char *src, const char *dst)113 {114 DIR *dirp;115 struct dirent *dp;116 struct stat sb;117 char buf[1024], buf2[1024];118 int fd, fd2;119 size_t len, len2;120 mode_t mode;121 122 if(G_lstat(src, &sb))123 return 1;124 125 /* src is a file */126 if(!S_ISDIR((mode = sb.st_mode)))127 {128 if(!G_lstat(dst, &sb) && S_ISDIR(sb.st_mode))129 {130 const char *p = strrchr(src, '/');131 /* src => dst/src */132 sprintf(buf, "%s/%s", dst, (p?p+1:src));133 134 return recursive_copy(src, buf);135 }136 137 /* src => dst */138 if((fd = open(src, O_RDONLY)) < 0)139 return 1;140 141 if((fd2 = open(dst, O_CREAT|O_TRUNC|O_WRONLY, mode & 0777)) < 0)142 {143 close(fd);144 return 1;145 }146 while((len = read(fd, buf, 1024)) > 0)147 {148 while(len && (len2 = write(fd2, buf, len)) >= 0)149 len -= len2;150 }151 close(fd);152 close(fd2);153 154 return 0;155 }156 157 /* src is a directory */158 159 if(G_lstat(dst, &sb))160 {161 if(G_mkdir(dst))162 return 1;163 }else164 /* if dst already exists and it's a file, try to remove it */165 if(!S_ISDIR(sb.st_mode))166 {167 if(remove(dst) || G_mkdir(dst))168 return 1;169 }170 171 if((dirp = opendir(src)) == NULL)172 return 1;173 while((dp = readdir(dirp)) != NULL)174 {175 /* do not copy hidden files */176 if(dp->d_name[0] == '.')177 continue;178 sprintf(buf, "%s/%s", src, dp->d_name);179 sprintf(buf2, "%s/%s", dst, dp->d_name);180 if(recursive_copy(buf, buf2))181 return 1;182 }183 closedir(dirp);184 185 return 0;186 } -
grass/branches/releasebranch_6_3/include/gisdefs.h
r25396 r31018 373 373 374 374 /* copy_file.c */ 375 int G_copy_file(const char *infile, const char *outfile); 375 int G_copy_file(const char *, const char *); 376 int G_recursive_copy(const char *, const char *); 376 377 377 378 /* dalloc.c */
Note:
See TracChangeset
for help on using the changeset viewer.
