Example #1
0
int
update_index (struct index_state *istate, const char *index_path)
{
    char index_shadow[PATH_MAX];
    int index_fd;
    int ret = 0;

    snprintf (index_shadow, PATH_MAX, "%s.shadow", index_path);
    index_fd = g_open (index_shadow, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
    if (index_fd < 0) {
        g_warning ("Failed to open shadow index: %s.\n", strerror(errno));
        return -1;
    }

    if (write_index (istate, index_fd) < 0) {
        g_warning ("Failed to write shadow index: %s.\n", strerror(errno));
        return -1;
    }
    close (index_fd);

    ret = ccnet_rename (index_shadow, index_path);
    if (ret < 0) {
        g_warning ("Failed to update index errno=%d %s\n", errno, strerror(errno));
        return -1;
    }
    return 0;
}
Example #2
0
static int
block_backend_fs_commit_block (BlockBackend *bend,
                               BHandle *handle)
{
    char path[SEAF_PATH_MAX];

    g_return_val_if_fail (handle->rw_type == BLOCK_WRITE, -1);

    get_block_path (bend, handle->block_id, path, handle->store_id, handle->version);

    if (create_parent_path (path) < 0) {
        seaf_warning ("Failed to create path for block %s.\n", handle->block_id);
        return -1;
    }

    if (ccnet_rename (handle->tmp_file, path) < 0) {
        seaf_warning ("[block bend] failed to commit block %s: %s\n",
                      handle->block_id, strerror(errno));
        return -1;
    }

    return 0;
}