Exemplo n.º 1
0
int git_futils_find_system_file(git_buf *path, const char *filename)
{
#ifdef GIT_WIN32
	struct win32_path root;

	if (win32_expand_path(&root, L"%PROGRAMFILES%\\Git\\etc\\") < 0 ||
		root.path[0] == L'%') /* i.e. no expansion happened */
	{
		giterr_set(GITERR_OS, "Cannot locate the system's Program Files directory");
		return -1;
	}

	if (win32_find_file(path, &root, filename) < 0) {
		git_buf_clear(path);
		return GIT_ENOTFOUND;
	}

	return 0;

#else
	if (git_buf_joinpath(path, "/etc", filename) < 0)
		return -1;

	if (git_path_exists(path->ptr) == true)
		return 0;

	git_buf_clear(path);
	return GIT_ENOTFOUND;
#endif
}
Exemplo n.º 2
0
int git_futils_find_global_file(git_buf *path, const char *filename)
{
#ifdef GIT_WIN32
	struct win32_path root;
	static const wchar_t *tmpls[4] = {
		L"%HOME%\\",
		L"%HOMEDRIVE%%HOMEPATH%\\",
		L"%USERPROFILE%\\",
		NULL,
	};
	const wchar_t **tmpl;

	for (tmpl = tmpls; *tmpl != NULL; tmpl++) {
		/* try to expand environment variable, skipping if not set */
		if (win32_expand_path(&root, *tmpl) != 0 || root.path[0] == L'%')
			continue;

		/* try to look up file under path */
		if (!win32_find_file(path, &root, filename))
			return 0;

		/* No error if file not found under %HOME%, b/c we don't trust it,
		 * but do error if another var is set and yet file is not found.
		 */
		if (tmpl != tmpls)
			break;
	}

	giterr_set(GITERR_OS, "The global file '%s' doesn't exist", filename);
	git_buf_clear(path);

	return GIT_ENOTFOUND;
#else
	const char *home = getenv("HOME");

	if (home == NULL) {
		giterr_set(GITERR_OS, "Global file lookup failed. "
			"Cannot locate the user's home directory");
		return GIT_ENOTFOUND;
	}

	if (git_buf_joinpath(path, home, filename) < 0)
		return -1;

	if (git_path_exists(path->ptr) == false) {
		giterr_set(GITERR_OS, "The global file '%s' doesn't exist", filename);
		git_buf_clear(path);
		return GIT_ENOTFOUND;
	}

	return 0;
#endif
}
Exemplo n.º 3
0
int git_futils_find_global_file(git_buf *path, const char *filename)
{
#ifdef GIT_WIN32
	struct win32_path root;

	if (win32_expand_path(&root, L"%USERPROFILE%\\") < 0 ||
		root.path[0] == L'%') /* i.e. no expansion happened */
	{
		giterr_set(GITERR_OS, "Cannot locate the user's profile directory");
		return -1;
	}

	if (win32_find_file(path, &root, filename) < 0) {
		git_buf_clear(path);
		return GIT_ENOTFOUND;
	}

	return 0;
#else
	const char *home = getenv("HOME");

	if (home == NULL) {
		giterr_set(GITERR_OS, "Global file lookup failed. "
			"Cannot locate the user's home directory");
		return -1;
	}

	if (git_buf_joinpath(path, home, filename) < 0)
		return -1;

	if (git_path_exists(path->ptr) == false) {
		git_buf_clear(path);
		return GIT_ENOTFOUND;
	}

	return 0;
#endif
}