コード例 #1
0
ファイル: clone-mgr.c プロジェクト: pombredanne/seafile
static char *
make_worktree (SeafCloneManager *mgr,
               const char *worktree,
               gboolean dry_run,
               GError **error)
{
    char *wt = g_strdup (worktree);
    struct stat st;
    int rc;
    char *ret;

    remove_trail_slash (wt);

    rc = g_lstat (wt, &st);
    if (rc < 0 && errno == ENOENT) {
        ret = wt;
        goto mk_dir;
    } else if (rc < 0 || !S_ISDIR(st.st_mode)) {
        if (!dry_run) {
            g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
                         "Invalid local directory");
            g_free (wt);
            return NULL;
        }
        ret = try_worktree (wt);
        g_free (wt);
        goto mk_dir;
    }

    /* OK, wt is an existing dir. Let's see if it's the worktree for
     * another repo. */
    if (is_worktree_of_repo (mgr, wt)) {
        if (!dry_run) {
            g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
                         "Already in sync");
            g_free (wt);
            return NULL;
        }
        ret = try_worktree (wt);
        g_free (wt);
    } else {
        return wt;
    }

mk_dir:
    if (!dry_run && g_mkdir_with_parents (ret, 0777) < 0) {
        seaf_warning ("[clone mgr] Failed to create dir %s.\n", ret);
        g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
                     "Failed to create worktree");
        g_free (ret);
        return NULL;
    }
    return ret;
}
コード例 #2
0
ファイル: clone-mgr.c プロジェクト: pombredanne/seafile
static char *
make_worktree_for_download (SeafCloneManager *mgr,
                            const char *wt_tmp,
                            GError **error)
{
    char *worktree;

    if (g_access (wt_tmp, F_OK) == 0) {
        worktree = try_worktree (wt_tmp);
    } else {
        worktree = g_strdup(wt_tmp);
    }

    if (!check_worktree_path (mgr, worktree, error)) {
        g_free (worktree);
        return NULL;
    }

    if (g_mkdir (worktree, 0777) < 0) {
        seaf_warning ("[clone mgr] Failed to create dir %s.\n", worktree);
        g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
                     "Failed to create worktree");
        g_free (worktree);
        return NULL;
    }

    return worktree;
}
コード例 #3
0
ファイル: clone-mgr.c プロジェクト: break123/seafile
static char *
make_worktree (SeafCloneManager *mgr,
               const char *worktree,
               gboolean dry_run,
               GError **error)
{
    char *wt = g_strdup (worktree);
    SeafStat st;
    int rc;
    char *ret;

    remove_trail_slash (wt);

    rc = seaf_stat (wt, &st);
    if (rc < 0 && errno == ENOENT) {
        ret = wt;
        return ret;
    } else if (rc < 0 || !S_ISDIR(st.st_mode)) {
        if (!dry_run) {
            g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
                         "Invalid local directory");
            g_free (wt);
            return NULL;
        }
        ret = try_worktree (wt);
        g_free (wt);
        return ret;
    }

    /* OK, wt is an existing dir. Let's see if it's the worktree for
     * another repo. */
    if (is_worktree_of_repo (mgr, wt)) {
        if (!dry_run) {
            g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
                         "Already in sync");
            g_free (wt);
            return NULL;
        }
        ret = try_worktree (wt);
        g_free (wt);
    } else {
        return wt;
    }

    return ret;
}
コード例 #4
0
ファイル: clone-mgr.c プロジェクト: break123/seafile
static char *
make_worktree_for_download (SeafCloneManager *mgr,
                            const char *wt_tmp,
                            GError **error)
{
    char *worktree;

    if (g_access (wt_tmp, F_OK) == 0) {
        worktree = try_worktree (wt_tmp);
    } else {
        worktree = g_strdup(wt_tmp);
    }

    if (!check_worktree_path (mgr, worktree, error)) {
        g_free (worktree);
        return NULL;
    }

    return worktree;
}