Changeset 2954 for trunk/Nebulous/nebclient
- Timestamp:
- Jan 10, 2005, 6:36:40 PM (22 years ago)
- Location:
- trunk/Nebulous/nebclient
- Files:
-
- 2 edited
-
idataclient.c (modified) (6 diffs)
-
idataclient.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous/nebclient/idataclient.c
r2943 r2954 4 4 * Copyright (C) 2005 Joshua Hoblitt 5 5 * 6 * $Id: idataclient.c,v 1. 3 2005-01-10 22:11:12jhoblitt Exp $6 * $Id: idataclient.c,v 1.4 2005-01-11 04:36:40 jhoblitt Exp $ 7 7 */ 8 8 … … 80 80 int idataReplicate(idataServer *server, char *key, char *volume, char **URI ) 81 81 { 82 83 return 0; 82 struct ns1__replicate_USCOREobjectResponse response; 83 char *filename; 84 int file; 85 86 if (soap_call_ns1__replicate_USCOREobject(server, NULL, NULL, key, volume, &response) == SOAP_OK) { 87 *URI = xmalloc(strlen(response.result)); 88 strcpy(*URI,response.result); 89 90 if (!idataParseURI(*URI, &filename)) { 91 fprintf(stderr, "can not parse URI\n"); 92 93 return 0; 94 } 95 96 //idataOpen(key, "read"); 97 //idataCopyFilehandle( 98 99 } 100 101 // server error 102 return -1; 84 103 } 85 104 … … 164 183 int status; 165 184 int matchStart, matchEnd; 185 int matchLength; 166 186 167 187 status = regcomp(&myregex, pattern, REG_EXTENDED); … … 185 205 matchStart = (int)mymatch[1].rm_so; 186 206 matchEnd = (int)mymatch[1].rm_eo; 207 matchLength = matchEnd - matchStart; 187 208 188 209 if (matchStart == -1) { … … 190 211 } 191 212 192 sprintf(*filename, "%.*s", matchEnd - matchStart, URI + matchStart); 213 *filename = xmalloc(matchLength + 1); 214 215 sprintf(*filename, "%.*s", matchLength, URI + matchStart); 193 216 194 217 return strlen(*filename); … … 198 221 xfree(ptr); 199 222 } 223 224 int idataCopyFile(char *source, char *dest) 225 { 226 int sourceFH; 227 int destFH; 228 size_t bytesCopied; 229 230 sourceFH = open(source, O_RDONLY); 231 if (sourceFH == -1) { 232 fprintf(stderr, "can not open %s: %s\n", source, strerror(errno)); 233 234 return -1; 235 } 236 237 destFH = open(dest, O_WRONLY|O_CREAT|O_CREAT, 0600); 238 if (destFH == -1) { 239 fprintf(stderr, "can not open %s: %s\n", dest, strerror(errno)); 240 241 return -1; 242 } 243 244 bytesCopied = idataCopyFilehandle(sourceFH, destFH); 245 if (bytesCopied < 0) { 246 return -1; 247 } 248 249 if (close(sourceFH) == -1) { 250 fprintf(stderr, "can not close %s: %s", source, strerror(errno)); 251 252 return -1; 253 } 254 255 if (close(destFH) == -1) { 256 fprintf(stderr, "can not close %s: %s", dest, strerror(errno)); 257 258 return -1; 259 } 260 261 return bytesCopied; 262 } 263 264 int idataCopyFilehandle(int sourceFH, int destFH) 265 { 266 size_t bytesTotal; 267 size_t bytesRemaining; 268 size_t writeSize; 269 char writeBuf[1024 * 1024]; 270 struct stat sourceStat; 271 272 if( !fstat(sourceFH, &sourceStat)) { 273 fprintf(stderr, "can not stat filehandles: %s\n", strerror(errno)); 274 275 return -1; 276 } 277 278 // the size of the file to copied 279 bytesTotal = sourceStat.st_size; 280 281 /* 282 * If the file size is <= the buffer size call write(2) with the 283 * file size. If the file size is > the buffer call write with the 284 * buffer size and loop until file size <= buffer size is true. 285 */ 286 287 bytesRemaining = bytesTotal; 288 289 while (bytesRemaining) { 290 if (bytesRemaining <= sizeof(writeBuf)) { 291 writeSize = bytesRemaining; 292 } else { 293 writeSize = sizeof(writeBuf); 294 } 295 296 if (read(sourceFH, writeBuf, writeSize) != writeSize) { 297 fprintf(stderr, "can not read filehandle: %s", strerror(errno)); 298 299 return -1; 300 } 301 302 if (write(destFH, writeBuf, writeSize) != writeSize) { 303 fprintf(stderr, "can not write filehandles: %s", strerror(errno)); 304 305 return -1; 306 } 307 308 bytesRemaining -= writeSize; 309 } 310 311 return bytesTotal; 312 } -
trunk/Nebulous/nebclient/idataclient.h
r2934 r2954 4 4 * Copyright (C) 2005 Joshua Hoblitt 5 5 * 6 * $Id: idataclient.h,v 1. 2 2005-01-08 00:57:59jhoblitt Exp $6 * $Id: idataclient.h,v 1.3 2005-01-11 04:36:40 jhoblitt Exp $ 7 7 */ 8 8 … … 49 49 50 50 void idataFree(void *ptr); 51 52 int idataCopyFile(char *source, char *dest); 53 54 int idataCopyFilehandle(int sourceFH, int destFH);
Note:
See TracChangeset
for help on using the changeset viewer.
