| 421 | } |
| 422 | |
| 423 | int copyPath(const char *src_path, const char *dst_path, FileProcessParam *param) { |
| 424 | // The source and destination paths are identical |
| 425 | if (strcasecmp(src_path, dst_path) == 0) { |
| 426 | return VITASHELL_ERROR_SRC_AND_DST_IDENTICAL; |
| 427 | } |
| 428 | |
| 429 | // The destination is a subfolder of the source folder |
| 430 | int len = strlen(src_path); |
| 431 | if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len - 1] == '/')) { |
| 432 | return VITASHELL_ERROR_DST_IS_SUBFOLDER_OF_SRC; |
| 433 | } |
| 434 | |
| 435 | SceUID dfd = sceIoDopen(src_path); |
| 436 | if (dfd >= 0) { |
| 437 | SceIoStat stat; |
| 438 | memset(&stat, 0, sizeof(SceIoStat)); |
| 439 | sceIoGetstatByFd(dfd, &stat); |
| 440 | |
| 441 | stat.st_mode |= SCE_S_IWUSR; |
| 442 | |
| 443 | int ret = sceIoMkdir(dst_path, stat.st_mode & 0xFFF); |
| 444 | if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) { |
| 445 | sceIoDclose(dfd); |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | if (ret == SCE_ERROR_ERRNO_EEXIST) { |
| 450 | sceIoChstat(dst_path, &stat, 0x3B); |
| 451 | } |
| 452 | |
| 453 | if (param) { |
| 454 | if (param->value) |
| 455 | (*param->value) += DIRECTORY_SIZE; |
| 456 | |
| 457 | if (param->SetProgress) |
| 458 | param->SetProgress(param->value ? *param->value : 0, param->max); |
| 459 | |
| 460 | if (param->cancelHandler && param->cancelHandler()) { |
| 461 | sceIoDclose(dfd); |
| 462 | return 0; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | int res = 0; |
| 467 | |
| 468 | do { |
| 469 | SceIoDirent dir; |
| 470 | memset(&dir, 0, sizeof(SceIoDirent)); |
| 471 | |
| 472 | res = sceIoDread(dfd, &dir); |
| 473 | if (res > 0) { |
| 474 | char *new_src_path = malloc(strlen(src_path) + strlen(dir.d_name) + 2); |
| 475 | snprintf(new_src_path, MAX_PATH_LENGTH, "%s%s%s", src_path, hasEndSlash(src_path) ? "" : "/", dir.d_name); |
| 476 | |
| 477 | char *new_dst_path = malloc(strlen(dst_path) + strlen(dir.d_name) + 2); |
| 478 | snprintf(new_dst_path, MAX_PATH_LENGTH, "%s%s%s", dst_path, hasEndSlash(dst_path) ? "" : "/", dir.d_name); |
| 479 | |
| 480 | int ret = 0; |
no test coverage detected