Changeset 368ee04 in mainline for uspace/app/bdsh/cmds/modules/cp/cp.c
- Timestamp:
- 2017-04-05T18:10:39Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cp/cp.c
r39f892a9 r368ee04 35 35 #include <getopt.h> 36 36 #include <str.h> 37 #include <fcntl.h> 38 #include <sys/stat.h> 37 #include <vfs/vfs.h> 39 38 #include <dirent.h> 40 39 #include "config.h" … … 83 82 struct stat s; 84 83 85 int r = stat(path, &s);86 87 if (r != 0)84 int r = vfs_stat_path(path, &s); 85 86 if (r != EOK) 88 87 return TYPE_NONE; 89 88 else if (s.is_directory) … … 235 234 */ 236 235 if (force && !interactive) { 237 if ( unlink(dest_path) != 0) {236 if (vfs_unlink_path(dest_path) != EOK) { 238 237 printf("Unable to remove %s\n", 239 238 dest_path); … … 246 245 if (overwrite) { 247 246 printf("Overwriting file: %s\n", dest_path); 248 if ( unlink(dest_path) != 0) {247 if (vfs_unlink_path(dest_path) != EOK) { 249 248 printf("Unable to remove %s\n", dest_path); 250 249 goto exit; … … 295 294 merge_paths(dest_path, PATH_MAX, src_dirname); 296 295 297 if (mkdir(dest_path, 0) != 0) { 296 if (vfs_link_path(dest_path, KIND_DIRECTORY, 297 NULL) != EOK) { 298 298 printf("Unable to create " 299 299 "dest directory %s\n", dest_path); … … 309 309 * e.g. cp -r /src /data/new_dir_src 310 310 */ 311 if (mkdir(dest_path, 0) != 0) { 311 if (vfs_link_path(dest_path, KIND_DIRECTORY, 312 NULL) != EOK) { 312 313 printf("Unable to create " 313 314 "dest directory %s\n", dest_path); … … 341 342 342 343 /* Check if we are copying a directory into itself */ 343 stat(src_dent, &src_s);344 stat(dest_path, &dest_s);344 vfs_stat_path(src_dent, &src_s); 345 vfs_stat_path(dest_path, &dest_s); 345 346 346 347 if (dest_s.index == src_s.index && … … 377 378 int64_t copied = 0; 378 379 char *buff = NULL; 380 aoff64_t posr = 0, posw = 0; 381 struct stat st; 379 382 380 383 if (vb) 381 384 printf("Copying %s to %s\n", src, dest); 382 385 383 if (-1 == (fd1 = open(src, O_RDONLY))) { 386 fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ); 387 if (fd1 < 0) { 384 388 printf("Unable to open source file %s\n", src); 385 389 return -1; 386 390 } 387 391 388 if (-1 == (fd2 = open(dest, O_CREAT))) { 392 fd2 = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE); 393 if (fd2 < 0) { 389 394 printf("Unable to open destination file %s\n", dest); 390 close(fd1);395 vfs_put(fd1); 391 396 return -1; 392 397 } 393 398 394 total = lseek(fd1, 0, SEEK_END); 395 399 if (vfs_stat(fd1, &st) != EOK) { 400 printf("Unable to fstat %d\n", fd1); 401 vfs_put(fd1); 402 vfs_put(fd2); 403 return -1; 404 } 405 406 total = st.size; 396 407 if (vb) 397 408 printf("%" PRIu64 " bytes to copy\n", total); 398 399 lseek(fd1, 0, SEEK_SET);400 409 401 410 if (NULL == (buff = (char *) malloc(blen))) { … … 406 415 } 407 416 408 while ((bytes = read(fd1, buff, blen)) > 0) {409 if ((bytes = write(fd2, buff, bytes)) < 0)417 while ((bytes = vfs_read(fd1, &posr, buff, blen)) > 0) { 418 if ((bytes = vfs_write(fd2, &posw, buff, bytes)) < 0) 410 419 break; 411 420 copied += bytes; … … 413 422 414 423 if (bytes < 0) { 415 printf("\nError copying %s, (%d)\n", src, errno);424 printf("\nError copying %s, (%d)\n", src, bytes); 416 425 copied = bytes; 417 426 } 418 427 419 428 out: 420 close(fd1);421 close(fd2);429 vfs_put(fd1); 430 vfs_put(fd2); 422 431 if (buff) 423 432 free(buff);
Note:
See TracChangeset
for help on using the changeset viewer.