Example #1
0
void DCOPY_do_cleanup(DCOPY_operation_t* op, \
                      CIRCLE_handle* handle)
{
    char* newop;

    /*
     * Truncate file on last chunk (synchronous mode can write past end of file)
     */
    int64_t bytes_written = (int64_t)(op->chunk + 1) * (int64_t)DCOPY_user_opts.chunk_size;
    if(bytes_written >= op->file_size) {
        /* truncate file to appropriate size, to do this before
         * setting permissions in case file does not have write permission */
        DCOPY_truncate_file(op, handle);

        /* since we still may access the file in the compare step,
         * delay setting permissions and timestamps until final phase */
    }

    /*
     * Add work item to compare source and destination if user requested it.
     */
    if(DCOPY_user_opts.compare) {
        newop = DCOPY_encode_operation(COMPARE, op->chunk, op->operand, \
                                       op->source_base_offset, \
                                       op->dest_base_appendix, op->file_size);

        handle->enqueue(newop);
        free(newop);
    }

    return;
}
Example #2
0
void DCOPY_do_cleanup(DCOPY_operation_t* op, \
                      CIRCLE_handle* handle)
{
    char* newop;
    bool ownership_preserved;

    /*
     * Only bother truncating and setting permissions on the first chunk of
     * the file.
     */
    if(op->chunk == 0) {

        if(DCOPY_user_opts.preserve) {
            /* build destination object name */
            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);
            }

            /* get stat of source object */
            struct stat64 statbuf;

            if(lstat64(op->operand, &statbuf) == 0) {
                ownership_preserved = DCOPY_set_preserve_ownership(op, handle, &statbuf, dest_path_recursive);
                DCOPY_set_preserve_permissions(op, handle, ownership_preserved, &statbuf, dest_path_recursive);
                DCOPY_set_preserve_timestamps(op, handle, &statbuf, dest_path_recursive);
            }
            else {
                /*
                        LOG(DCOPY_LOG_ERR, "Could not determine if `%s' is a directory. %s", path, strerror(errno));
                */
            }
        }

        DCOPY_truncate_file(op, handle);
    }

    /*
     * If the user is feeling brave, this is where we let them skip the
     * comparison stage.
     */
    if(!DCOPY_user_opts.skip_compare) {
        newop = DCOPY_encode_operation(COMPARE, op->chunk, op->operand, \
                                       op->source_base_offset, \
                                       op->dest_base_appendix, op->file_size);

        handle->enqueue(newop);
        free(newop);
    }

    return;
}