예제 #1
0
파일: odb_pack.c 프로젝트: fatlotus/nodegit
int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
{
	struct pack_backend *backend;
	char path[GIT_PATH_MAX];

	backend = git__calloc(1, sizeof(struct pack_backend));
	if (backend == NULL)
		return GIT_ENOMEM;

	if (git_vector_init(&backend->packs, 8, packfile_sort__cb) < GIT_SUCCESS) {
		free(backend);
		return GIT_ENOMEM;
	}

	git_path_join(path, objects_dir, "pack");
	if (git_futils_isdir(path) == GIT_SUCCESS) {
		backend->pack_folder = git__strdup(path);
		backend->pack_folder_mtime = 0;

		if (backend->pack_folder == NULL) {
			free(backend);
			return GIT_ENOMEM;
		}
	}

	backend->parent.read = &pack_backend__read;
	backend->parent.read_prefix = &pack_backend__read_prefix;
	backend->parent.read_header = NULL;
	backend->parent.exists = &pack_backend__exists;
	backend->parent.free = &pack_backend__free;

	*backend_out = (git_odb_backend *)backend;
	return GIT_SUCCESS;
}
예제 #2
0
파일: posix.c 프로젝트: nulltoken/libgit2
int p_getcwd(char *buffer_out, size_t size)
{
    char *cwd_buffer;

    assert(buffer_out && size > 0);

#ifdef GIT_WIN32
    cwd_buffer = _getcwd(buffer_out, size);
#else
    cwd_buffer = getcwd(buffer_out, size);
#endif

    if (cwd_buffer == NULL)
        return git__throw(GIT_EOSERR, "Failed to retrieve current working directory");

    git_path_mkposix(buffer_out);

    git_path_join(buffer_out, buffer_out, "");	//Ensure the path ends with a trailing slash
    return GIT_SUCCESS;
}
예제 #3
0
int git_config_find_global(char *global_config_path)
{
	const char *home;

	home = getenv("HOME");

#ifdef GIT_WIN32
	if (home == NULL)
		home = getenv("USERPROFILE");
#endif

	if (home == NULL)
		return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory");

	git_path_join(global_config_path, home, GIT_CONFIG_FILENAME);

	if (git_futils_exists(global_config_path) < GIT_SUCCESS)
		return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist");

	return GIT_SUCCESS;
}
예제 #4
0
파일: fileops.c 프로젝트: fatlotus/nodegit
int git_futils_mkpath2file(const char *file_path)
{
	const int mode = 0755; /* or 0777 ? */
	int error = GIT_SUCCESS;
	char target_folder_path[GIT_PATH_MAX];

	error = git_path_dirname_r(target_folder_path, sizeof(target_folder_path), file_path);
	if (error < GIT_SUCCESS)
		return git__throw(GIT_EINVALIDPATH, "Failed to recursively build `%s` tree structure. Unable to parse parent folder name", file_path);

	/* Does the containing folder exist? */
	if (git_futils_isdir(target_folder_path)) {
		git_path_join(target_folder_path, target_folder_path, ""); /* Ensure there's a trailing slash */

		/* Let's create the tree structure */
		error = git_futils_mkdir_r(target_folder_path, mode);
		if (error < GIT_SUCCESS)
			return error;	/* The callee already takes care of setting the correct error message. */
	}

	return GIT_SUCCESS;
}
예제 #5
0
파일: index.c 프로젝트: boyski/libgit2
static int index_init_entry(git_index_entry *entry, git_index *index, const char *rel_path, int stage)
{
	char full_path[GIT_PATH_MAX];
	struct stat st;
	int error;

	if (index->repository == NULL)
		return git__throw(GIT_EBAREINDEX, "Failed to initialize entry. Repository is bare");

	git_path_join(full_path, index->repository->path_workdir, rel_path);

	if (p_lstat(full_path, &st) < 0)
		return git__throw(GIT_ENOTFOUND, "Failed to initialize entry. '%s' cannot be opened", full_path);

	if (stage < 0 || stage > 3)
		return git__throw(GIT_ERROR, "Failed to initialize entry. Invalid stage %i", stage);

	memset(entry, 0x0, sizeof(git_index_entry));

	entry->ctime.seconds = (git_time_t)st.st_ctime;
	entry->mtime.seconds = (git_time_t)st.st_mtime;
	/* entry.mtime.nanoseconds = st.st_mtimensec; */
	/* entry.ctime.nanoseconds = st.st_ctimensec; */
	entry->dev= st.st_rdev;
	entry->ino = st.st_ino;
	entry->mode = index_create_mode(st.st_mode);
	entry->uid = st.st_uid;
	entry->gid = st.st_gid;
	entry->file_size = st.st_size;

	/* write the blob to disk and get the oid */
	if ((error = git_blob_create_fromfile(&entry->oid, index->repository, rel_path)) < GIT_SUCCESS)
		return git__rethrow(error, "Failed to initialize index entry");

	entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT);
	entry->path = rel_path; /* do not duplicate; index_insert already does this */
	return GIT_SUCCESS;
}