示例#1
0
文件: dir.c 项目: CCorreia/git
/*
 * Do not use the alphabetically stored index to look up
 * the directory name; instead, use the case insensitive
 * name hash.
 */
static enum exist_status directory_exists_in_index_icase(const char *dirname, int len)
{
	struct cache_entry *ce = index_name_exists(&the_index, dirname, len + 1, ignore_case);
	unsigned char endchar;

	if (!ce)
		return index_nonexistent;
	endchar = ce->name[len];

	/*
	 * The cache_entry structure returned will contain this dirname
	 * and possibly additional path components.
	 */
	if (endchar == '/')
		return index_directory;

	/*
	 * If there are no additional path components, then this cache_entry
	 * represents a submodule.  Submodules, despite being directories,
	 * are stored in the cache without a closing slash.
	 */
	if (!endchar && S_ISGITLINK(ce->ce_mode))
		return index_gitdir;

	/* This should never be hit, but it exists just in case. */
	return index_nonexistent;
}
示例#2
0
static int
delete_dir_recursive (const char *repo_id,
                      int repo_version,
                      const char *dir_path,
                      SeafDir *dir,
                      const char *worktree,
                      struct index_state *istate)
{
    GList *ptr;
    SeafDirent *dent;
    char *sub_path;
    SeafDir *sub_dir;

    for (ptr = dir->entries; ptr; ptr = ptr->next) {
        dent = ptr->data;
        sub_path = g_strconcat (dir_path, "/", dent->name, NULL);

        if (S_ISDIR(dent->mode)) {
            if (strcmp(dent->id, EMPTY_SHA1) == 0) {
                delete_path (worktree, sub_path, dent->mode, 0);
            } else {
                sub_dir = seaf_fs_manager_get_seafdir (seaf->fs_mgr,
                                                       repo_id, repo_version,
                                                       dent->id);
                if (!sub_dir) {
                    seaf_warning ("Failed to find dir %s in repo %.8s.\n",
                                  sub_path, repo_id);
                    g_free (sub_path);
                    return -1;
                }

                if (delete_dir_recursive (repo_id, repo_version,
                                          sub_path, sub_dir,
                                          worktree, istate) < 0) {
                    g_free (sub_path);
                    return -1;
                }

                seaf_dir_free (sub_dir);
            }
        } else if (S_ISREG(dent->mode)) {
            struct cache_entry *ce;

            ce = index_name_exists (istate, sub_path, strlen(sub_path), 0);
            if (ce) {
                delete_path (worktree, sub_path, dent->mode, ce->ce_mtime.sec);
            }
        }

        g_free (sub_path);
    }

    char *full_path = g_build_filename (worktree, dir_path, NULL);
    if (seaf_remove_empty_dir (full_path) < 0) {
        seaf_warning ("Failed to remove dir %s: %s.\n", full_path, strerror(errno));
        return -1;
    }

    return 0;
}
示例#3
0
static struct dir_entry *
dir_add_name(struct dir_struct *dir, const char *pathname, 
             int len, struct index_state *index)
{
    if (index_name_exists(index, pathname, len, 0))
        return NULL;

    ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
    return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
}