/* The entrance point to the copy operation. */ void DCOPY_do_copy(DCOPY_operation_t* op, \ CIRCLE_handle* handle) { off64_t offset = DCOPY_CHUNK_SIZE * op->chunk; int in_fd = DCOPY_open_input_fd(op, offset, DCOPY_CHUNK_SIZE); if(in_fd < 0) { DCOPY_retry_failed_operation(COPY, handle, op); return; } int out_fd = DCOPY_open_output_fd(op); if(out_fd < 0) { /* * If the force option is specified, try to unlink the destination and * reopen before doing the optional requeue. */ if(DCOPY_user_opts.force) { DCOPY_unlink_destination(op); out_fd = DCOPY_open_output_fd(op); if(out_fd < 0) { DCOPY_retry_failed_operation(COPY, handle, op); return; } } else { DCOPY_retry_failed_operation(COPY, handle, op); return; } } if(DCOPY_perform_copy(op, in_fd, out_fd, offset) < 0) { DCOPY_retry_failed_operation(COPY, handle, op); return; } if(close(in_fd) < 0) { LOG(DCOPY_LOG_DBG, "Close on source file failed. errno=%d %s", errno, strerror(errno)); } if(close(out_fd) < 0) { LOG(DCOPY_LOG_DBG, "Close on destination file failed. errno=%d %s", errno, strerror(errno)); } DCOPY_enqueue_cleanup_stage(op, handle); return; }
void DCOPY_truncate_file(DCOPY_operation_t* op, \ CIRCLE_handle* handle) { char dest_path_recursive[PATH_MAX]; char dest_path_file_to_file[PATH_MAX]; if(op->dest_base_appendix == NULL) { sprintf(dest_path_recursive, "%s/%s", \ DCOPY_user_opts.dest_path, \ op->operand + op->source_base_offset + 1); strncpy(dest_path_file_to_file, DCOPY_user_opts.dest_path, PATH_MAX); } else { sprintf(dest_path_recursive, "%s/%s/%s", \ DCOPY_user_opts.dest_path, \ op->dest_base_appendix, \ op->operand + op->source_base_offset + 1); sprintf(dest_path_file_to_file, "%s/%s", \ DCOPY_user_opts.dest_path, \ op->dest_base_appendix); } LOG(DCOPY_LOG_DBG, "Truncating file to `%" PRId64 "'.", op->file_size); /* * Try the recursive file before file-to-file. The cast below requires us * to have a maximum file_size of 2^63, not 2^64. */ if(truncate64(dest_path_recursive, op->file_size) < 0) { /* LOG(DCOPY_LOG_DBG, "Failed to truncate destination file (recursive)."); */ if(truncate64(dest_path_file_to_file, op->file_size) < 0) { LOG(DCOPY_LOG_ERR, "Failed to truncate destination file."); DCOPY_retry_failed_operation(COPY, handle, op); return; } } }