Changes in uspace/app/bdsh/cmds/modules/cp/cp.c [a6fc88a:6afc9d7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cp/cp.c
ra6fc88a r6afc9d7 35 35 #include <getopt.h> 36 36 #include <str.h> 37 #include <vfs/vfs.h> 37 #include <fcntl.h> 38 #include <sys/stat.h> 38 39 #include <dirent.h> 39 40 #include "config.h" … … 82 83 struct stat s; 83 84 84 int r = vfs_stat_path(path, &s);85 86 if (r != EOK)85 int r = stat(path, &s); 86 87 if (r != 0) 87 88 return TYPE_NONE; 88 89 else if (s.is_directory) … … 234 235 */ 235 236 if (force && !interactive) { 236 if ( vfs_unlink_path(dest_path) != EOK) {237 if (unlink(dest_path) != 0) { 237 238 printf("Unable to remove %s\n", 238 239 dest_path); … … 245 246 if (overwrite) { 246 247 printf("Overwriting file: %s\n", dest_path); 247 if ( vfs_unlink_path(dest_path) != EOK) {248 if (unlink(dest_path) != 0) { 248 249 printf("Unable to remove %s\n", dest_path); 249 250 goto exit; … … 294 295 merge_paths(dest_path, PATH_MAX, src_dirname); 295 296 296 if (vfs_link_path(dest_path, KIND_DIRECTORY, 297 NULL) != EOK) { 297 if (mkdir(dest_path, 0) != 0) { 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 (vfs_link_path(dest_path, KIND_DIRECTORY, 312 NULL) != EOK) { 311 if (mkdir(dest_path, 0) != 0) { 313 312 printf("Unable to create " 314 313 "dest directory %s\n", dest_path); … … 342 341 343 342 /* Check if we are copying a directory into itself */ 344 vfs_stat_path(src_dent, &src_s);345 vfs_stat_path(dest_path, &dest_s);343 stat(src_dent, &src_s); 344 stat(dest_path, &dest_s); 346 345 347 346 if (dest_s.index == src_s.index && … … 378 377 int64_t copied = 0; 379 378 char *buff = NULL; 380 aoff64_t posr = 0, posw = 0;381 struct stat st;382 379 383 380 if (vb) 384 381 printf("Copying %s to %s\n", src, dest); 385 382 386 fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ); 387 if (fd1 < 0) { 383 if (-1 == (fd1 = open(src, O_RDONLY))) { 388 384 printf("Unable to open source file %s\n", src); 389 385 return -1; 390 386 } 391 387 392 fd2 = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE); 393 if (fd2 < 0) { 388 if (-1 == (fd2 = open(dest, O_CREAT))) { 394 389 printf("Unable to open destination file %s\n", dest); 395 vfs_put(fd1);390 close(fd1); 396 391 return -1; 397 392 } 398 393 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; 394 total = lseek(fd1, 0, SEEK_END); 395 407 396 if (vb) 408 397 printf("%" PRIu64 " bytes to copy\n", total); 398 399 lseek(fd1, 0, SEEK_SET); 409 400 410 401 if (NULL == (buff = (char *) malloc(blen))) { … … 415 406 } 416 407 417 while ((bytes = vfs_read(fd1, &posr, buff, blen)) > 0) {418 if ((bytes = vfs_write(fd2, &posw, buff, bytes)) < 0)408 while ((bytes = read(fd1, buff, blen)) > 0) { 409 if ((bytes = write(fd2, buff, bytes)) < 0) 419 410 break; 420 411 copied += bytes; … … 422 413 423 414 if (bytes < 0) { 424 printf("\nError copying %s, (%d)\n", src, bytes);415 printf("\nError copying %s, (%d)\n", src, errno); 425 416 copied = bytes; 426 417 } 427 418 428 419 out: 429 vfs_put(fd1);430 vfs_put(fd2);420 close(fd1); 421 close(fd2); 431 422 if (buff) 432 423 free(buff);
Note:
See TracChangeset
for help on using the changeset viewer.