コード例 #1
0
ファイル: findfile.c プロジェクト: lznuaa/libgit2
int win32_find_system_file_using_path(git_buf *path, const char *filename)
{
	wchar_t * env = NULL;
	struct win32_path root;

	env = _wgetenv(L"PATH");
	if (!env)
		return -1;

	// search in all paths defined in PATH
	while ((env = win32_nextpath(env, root.path, MAX_PATH - 1)) != NULL && *root.path)
	{
		wchar_t * pfin = root.path + wcslen(root.path) - 1; // last char of the current path entry

		// ensure trailing slash
		if (*pfin != L'/' && *pfin != L'\\')
			wcscpy(++pfin, L"\\"); // we have enough space left, MAX_PATH - 1 is used in nextpath above

		root.len = (DWORD)wcslen(root.path) + 1;

		if (win32_find_file(path, &root, "git.cmd") == 0 || win32_find_file(path, &root, "git.exe") == 0) {
			// we found the cmd or bin directory of a git installaton
			if (root.len > 5) {
				wcscpy(root.path + wcslen(root.path) - 4, L"etc\\");
				if (win32_find_file(path, &root, filename) == 0)
					return 0;
			}
		}
	}
	
	return GIT_ENOTFOUND;
}
コード例 #2
0
ファイル: fileops.c プロジェクト: ileitch/meanie
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
}
コード例 #3
0
ファイル: fileops.c プロジェクト: ralpheav/PM_GIT
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
}
コード例 #4
0
ファイル: findfile.c プロジェクト: duralog/node-sencillo
int win32_find_system_file_using_registry(git_buf *path, const char *filename)
{
	struct win32_path root;

	if (win32_find_msysgit_in_registry(&root, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL)) {
		if (win32_find_msysgit_in_registry(&root, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL)) {
			giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory");
			return -1;
		}
	}

	if (win32_find_file(path, &root, filename) < 0) {
		giterr_set(GITERR_OS, "The system file '%s' doesn't exist", filename);
		git_buf_clear(path);
		return GIT_ENOTFOUND;
	}

	return 0;
}
コード例 #5
0
ファイル: findfile.c プロジェクト: lznuaa/libgit2
int win32_find_system_file_using_registry(git_buf *path, const char *filename)
{
	struct win32_path root;

	HKEY hKey;
	DWORD dwType = REG_SZ;
	DWORD dwSize = MAX_PATH;

	root.len = 0;
	if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
	{
		if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType,(LPBYTE)&root.path, &dwSize) == ERROR_SUCCESS)
		{
			// InstallLocation points to the root of the msysgit directory
			if (dwSize + 4 > MAX_PATH) // 4 = wcslen(L"etc\\")
			{
				giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory - path too long");
				return -1;
			}
			wcscat(root.path, L"etc\\");
			root.len = (DWORD)wcslen(root.path) + 1;
		}
	}
	RegCloseKey(hKey);

	if (!root.len) {
		giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory");
		return -1;
	}

	if (win32_find_file(path, &root, filename) < 0) {
		giterr_set(GITERR_OS, "The system file '%s' doesn't exist", filename);
		git_buf_clear(path);
		return GIT_ENOTFOUND;
	}

	return 0;
}
コード例 #6
0
ファイル: fileops.c プロジェクト: ileitch/meanie
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
}