示例#1
0
static int
mkdir_with_fs (glfs_t *fs)
{
        int ret;
        mode_t mode = get_default_dir_mode_perm ();

        if (state->parents) {
                ret = gluster_create_path (fs, state->gluster_url->path, mode);
        } else {
                ret = glfs_mkdir (fs, state->gluster_url->path, mode);
        }

        if (ret == -1) {
                error (0, errno, "cannot create directory `%s'", state->url);
                goto out;
        }

out:
        return ret;
}
示例#2
0
int
gluster_put (glfs_t *fs, struct state *state)
{
        int ret = -1;
        glfs_fd_t *fd = NULL;
        char *filename = state->gluster_url->path;
        char *dir_path = strdup (state->gluster_url->path);
        struct stat statbuf;

        if (dir_path == NULL) {
                error (EXIT_FAILURE, errno, "strdup");
                goto out;
        }

        ret = glfs_lstat (fs, filename, &statbuf);
        if (ret != -1 && !state->append && !state->overwrite) {
                errno = EEXIST;
                ret = -1;
                goto out;
        }

        if (state->parents) {
                ret = gluster_create_path (fs, dir_path,
                                get_default_dir_mode_perm ());
                if (ret == -1) {
                        goto out;
                }
        }

        fd = glfs_creat (fs, filename, O_RDWR, get_default_file_mode_perm ());
        if (fd == NULL) {
                ret = -1;
                goto out;
        }

        ret = gluster_lock (fd, F_WRLCK);
        if (ret == -1) {
                goto out;
        }

        if (state->append) {
                ret = glfs_lseek (fd, 0, SEEK_END);
                if (ret == -1) {
                        error (0, errno, "seek error: %s", filename);
                        goto out;
                }
        } else {
                ret = glfs_ftruncate (fd, 0);
                if (ret == -1) {
                        error (0, errno, "truncate error: %s", filename);
                        goto out;
                }
        }

        if (gluster_write (STDIN_FILENO, fd) == 0) {
                ret = -1;
        }

out:
        free (dir_path);

        if (fd) {
                glfs_close (fd);
        }

        return ret;
}