Blame src/path.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_path_h__
Packit Service 20376f
#define INCLUDE_path_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "posix.h"
Packit Service 20376f
#include "buffer.h"
Packit Service 20376f
#include "vector.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Path manipulation utils
Packit Service 20376f
 *
Packit Service 20376f
 * These are path utilities that munge paths without actually
Packit Service 20376f
 * looking at the real filesystem.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * The dirname() function shall take a pointer to a character string
Packit Service 20376f
 * that contains a pathname, and return a pointer to a string that is a
Packit Service 20376f
 * pathname of the parent directory of that file. Trailing '/' characters
Packit Service 20376f
 * in the path are not counted as part of the path.
Packit Service 20376f
 *
Packit Service 20376f
 * If path does not contain a '/', then dirname() shall return a pointer to
Packit Service 20376f
 * the string ".". If path is a null pointer or points to an empty string,
Packit Service 20376f
 * dirname() shall return a pointer to the string "." .
Packit Service 20376f
 *
Packit Service 20376f
 * The `git_path_dirname` implementation is thread safe. The returned
Packit Service 20376f
 * string must be manually free'd.
Packit Service 20376f
 *
Packit Service 20376f
 * The `git_path_dirname_r` implementation writes the dirname to a `git_buf`
Packit Service 20376f
 * if the buffer pointer is not NULL.
Packit Service 20376f
 * It returns an error code < 0 if there is an allocation error, otherwise
Packit Service 20376f
 * the length of the dirname (which will be > 0).
Packit Service 20376f
 */
Packit Service 20376f
extern char *git_path_dirname(const char *path);
Packit Service 20376f
extern int git_path_dirname_r(git_buf *buffer, const char *path);
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * This function returns the basename of the file, which is the last
Packit Service 20376f
 * part of its full name given by fname, with the drive letter and
Packit Service 20376f
 * leading directories stripped off. For example, the basename of
Packit Service 20376f
 * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
Packit Service 20376f
 *
Packit Service 20376f
 * Trailing slashes and backslashes are significant: the basename of
Packit Service 20376f
 * c:/foo/bar/ is an empty string after the rightmost slash.
Packit Service 20376f
 *
Packit Service 20376f
 * The `git_path_basename` implementation is thread safe. The returned
Packit Service 20376f
 * string must be manually free'd.
Packit Service 20376f
 *
Packit Service 20376f
 * The `git_path_basename_r` implementation writes the basename to a `git_buf`.
Packit Service 20376f
 * It returns an error code < 0 if there is an allocation error, otherwise
Packit Service 20376f
 * the length of the basename (which will be >= 0).
Packit Service 20376f
 */
Packit Service 20376f
extern char *git_path_basename(const char *path);
Packit Service 20376f
extern int git_path_basename_r(git_buf *buffer, const char *path);
Packit Service 20376f
Packit Service 20376f
/* Return the offset of the start of the basename.  Unlike the other
Packit Service 20376f
 * basename functions, this returns 0 if the path is empty.
Packit Service 20376f
 */
Packit Service 20376f
extern size_t git_path_basename_offset(git_buf *buffer);
Packit Service 20376f
Packit Service 20376f
extern const char *git_path_topdir(const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Find offset to root of path if path has one.
Packit Service 20376f
 *
Packit Service 20376f
 * This will return a number >= 0 which is the offset to the start of the
Packit Service 20376f
 * path, if the path is rooted (i.e. "/rooted/path" returns 0 and
Packit Service 20376f
 * "c:/windows/rooted/path" returns 2).  If the path is not rooted, this
Packit Service 20376f
 * returns -1.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_root(const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Ensure path has a trailing '/'.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_to_dir(git_buf *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Ensure string has a trailing '/' if there is space for it.
Packit Service 20376f
 */
Packit Service 20376f
extern void git_path_string_to_dir(char* path, size_t size);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Taken from git.git; returns nonzero if the given path is "." or "..".
Packit Service 20376f
 */
Packit Service 20376f
GIT_INLINE(int) git_path_is_dot_or_dotdot(const char *name)
Packit Service 20376f
{
Packit Service 20376f
	return (name[0] == '.' &&
Packit Service 20376f
			  (name[1] == '\0' ||
Packit Service 20376f
				(name[1] == '.' && name[2] == '\0')));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
#ifdef GIT_WIN32
Packit Service 20376f
GIT_INLINE(int) git_path_is_dot_or_dotdotW(const wchar_t *name)
Packit Service 20376f
{
Packit Service 20376f
	return (name[0] == L'.' &&
Packit Service 20376f
			  (name[1] == L'\0' ||
Packit Service 20376f
				(name[1] == L'.' && name[2] == L'\0')));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Convert backslashes in path to forward slashes.
Packit Service 20376f
 */
Packit Service 20376f
GIT_INLINE(void) git_path_mkposix(char *path)
Packit Service 20376f
{
Packit Service 20376f
	while (*path) {
Packit Service 20376f
		if (*path == '\\')
Packit Service 20376f
			*path = '/';
Packit Service 20376f
Packit Service 20376f
		path++;
Packit Service 20376f
	}
Packit Service 20376f
}
Packit Service 20376f
#else
Packit Service 20376f
#	define git_path_mkposix(p) /* blank */
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if string is a relative path (i.e. starts with "./" or "../")
Packit Service 20376f
 */
Packit Service 20376f
GIT_INLINE(int) git_path_is_relative(const char *p)
Packit Service 20376f
{
Packit Service 20376f
	return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/')));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if string is at end of path segment (i.e. looking at '/' or '\0')
Packit Service 20376f
 */
Packit Service 20376f
GIT_INLINE(int) git_path_at_end_of_segment(const char *p)
Packit Service 20376f
{
Packit Service 20376f
	return !*p || *p == '/';
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
extern int git__percent_decode(git_buf *decoded_out, const char *input);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Extract path from file:// URL.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_fromurl(git_buf *local_path_out, const char *file_url);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Path filesystem utils
Packit Service 20376f
 *
Packit Service 20376f
 * These are path utilities that actually access the filesystem.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if a file exists and can be accessed.
Packit Service 20376f
 * @return true or false
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_exists(const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if the given path points to a directory.
Packit Service 20376f
 * @return true or false
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_isdir(const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if the given path points to a regular file.
Packit Service 20376f
 * @return true or false
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_isfile(const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if the given path points to a symbolic link.
Packit Service 20376f
 * @return true or false
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_islink(const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if the given path is a directory, and is empty.
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_is_empty_dir(const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Stat a file and/or link and set error if needed.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_lstat(const char *path, struct stat *st);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if the parent directory contains the item.
Packit Service 20376f
 *
Packit Service 20376f
 * @param dir Directory to check.
Packit Service 20376f
 * @param item Item that might be in the directory.
Packit Service 20376f
 * @return 0 if item exists in directory, <0 otherwise.
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_contains(git_buf *dir, const char *item);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if the given path contains the given subdirectory.
Packit Service 20376f
 *
Packit Service 20376f
 * @param parent Directory path that might contain subdir
Packit Service 20376f
 * @param subdir Subdirectory name to look for in parent
Packit Service 20376f
 * @return true if subdirectory exists, false otherwise.
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_contains_dir(git_buf *parent, const char *subdir);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Determine the common directory length between two paths, including
Packit Service 20376f
 * the final path separator.  For example, given paths 'a/b/c/1.txt
Packit Service 20376f
 * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this
Packit Service 20376f
 * will return the length of the string 'a/b/c/', which is 6.
Packit Service 20376f
 *
Packit Service 20376f
 * @param one The first path
Packit Service 20376f
 * @param two The second path
Packit Service 20376f
 * @return The length of the common directory
Packit Service 20376f
 */
Packit Service 20376f
extern size_t git_path_common_dirlen(const char *one, const char *two);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Make the path relative to the given parent path.
Packit Service 20376f
 *
Packit Service 20376f
 * @param path The path to make relative
Packit Service 20376f
 * @param parent The parent path to make path relative to
Packit Service 20376f
 * @return 0 if path was made relative, GIT_ENOTFOUND
Packit Service 20376f
 *         if there was not common root between the paths,
Packit Service 20376f
 *         or <0.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_make_relative(git_buf *path, const char *parent);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check if the given path contains the given file.
Packit Service 20376f
 *
Packit Service 20376f
 * @param dir Directory path that might contain file
Packit Service 20376f
 * @param file File name to look for in parent
Packit Service 20376f
 * @return true if file exists, false otherwise.
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_contains_file(git_buf *dir, const char *file);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Prepend base to unrooted path or just copy path over.
Packit Service 20376f
 *
Packit Service 20376f
 * This will optionally return the index into the path where the "root"
Packit Service 20376f
 * is, either the end of the base directory prefix or the path root.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_join_unrooted(
Packit Service 20376f
	git_buf *path_out, const char *path, const char *base, ssize_t *root_at);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Removes multiple occurrences of '/' in a row, squashing them into a
Packit Service 20376f
 * single '/'.
Packit Service 20376f
 */
Packit Service 20376f
extern void git_path_squash_slashes(git_buf *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Clean up path, prepending base if it is not already rooted.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_prettify(git_buf *path_out, const char *path, const char *base);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Clean up path, prepending base if it is not already rooted and
Packit Service 20376f
 * appending a slash.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get a directory from a path.
Packit Service 20376f
 *
Packit Service 20376f
 * If path is a directory, this acts like `git_path_prettify_dir`
Packit Service 20376f
 * (cleaning up path and appending a '/').  If path is a normal file,
Packit Service 20376f
 * this prettifies it, then removed the filename a la dirname and
Packit Service 20376f
 * appends the trailing '/'.  If the path does not exist, it is
Packit Service 20376f
 * treated like a regular filename.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_find_dir(git_buf *dir, const char *path, const char *base);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Resolve relative references within a path.
Packit Service 20376f
 *
Packit Service 20376f
 * This eliminates "./" and "../" relative references inside a path,
Packit Service 20376f
 * as well as condensing multiple slashes into single ones.  It will
Packit Service 20376f
 * not touch the path before the "ceiling" length.
Packit Service 20376f
 *
Packit Service 20376f
 * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
Packit Service 20376f
 * prefix and not touch that part of the path.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_resolve_relative(git_buf *path, size_t ceiling);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Apply a relative path to base path.
Packit Service 20376f
 *
Packit Service 20376f
 * Note that the base path could be a filename or a URL and this
Packit Service 20376f
 * should still work.  The relative path is walked segment by segment
Packit Service 20376f
 * with three rules: series of slashes will be condensed to a single
Packit Service 20376f
 * slash, "." will be eaten with no change, and ".." will remove a
Packit Service 20376f
 * segment from the base path.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_apply_relative(git_buf *target, const char *relpath);
Packit Service 20376f
Packit Service 20376f
enum {
Packit Service 20376f
	GIT_PATH_DIR_IGNORE_CASE = (1u << 0),
Packit Service 20376f
	GIT_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1),
Packit Service 20376f
	GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2),
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Walk each directory entry, except '.' and '..', calling fn(state).
Packit Service 20376f
 *
Packit Service 20376f
 * @param pathbuf Buffer the function reads the initial directory
Packit Service 20376f
 * 		path from, and updates with each successive entry's name.
Packit Service 20376f
 * @param flags Combination of GIT_PATH_DIR flags.
Packit Service 20376f
 * @param callback Callback for each entry. Passed the `payload` and each
Packit Service 20376f
 *		successive path inside the directory as a full path.  This may
Packit Service 20376f
 *		safely append text to the pathbuf if needed.  Return non-zero to
Packit Service 20376f
 *		cancel iteration (and return value will be propagated back).
Packit Service 20376f
 * @param payload Passed to callback as first argument.
Packit Service 20376f
 * @return 0 on success or error code from OS error or from callback
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_direach(
Packit Service 20376f
	git_buf *pathbuf,
Packit Service 20376f
	uint32_t flags,
Packit Service 20376f
	int (*callback)(void *payload, git_buf *path),
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Sort function to order two paths
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_cmp(
Packit Service 20376f
	const char *name1, size_t len1, int isdir1,
Packit Service 20376f
	const char *name2, size_t len2, int isdir2,
Packit Service 20376f
	int (*compare)(const char *, const char *, size_t));
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Invoke callback up path directory by directory until the ceiling is
Packit Service 20376f
 * reached (inclusive of a final call at the root_path).
Packit Service 20376f
 *
Packit Service 20376f
 * Returning anything other than 0 from the callback function
Packit Service 20376f
 * will stop the iteration and propagate the error to the caller.
Packit Service 20376f
 *
Packit Service 20376f
 * @param pathbuf Buffer the function reads the directory from and
Packit Service 20376f
 *		and updates with each successive name.
Packit Service 20376f
 * @param ceiling Prefix of path at which to stop walking up.  If NULL,
Packit Service 20376f
 *		this will walk all the way up to the root.  If not a prefix of
Packit Service 20376f
 *		pathbuf, the callback will be invoked a single time on the
Packit Service 20376f
 *		original input path.
Packit Service 20376f
 * @param callback Function to invoke on each path.  Passed the `payload`
Packit Service 20376f
 *		and the buffer containing the current path.  The path should not
Packit Service 20376f
 *		be modified in any way. Return non-zero to stop iteration.
Packit Service 20376f
 * @param payload Passed to fn as the first ath.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_walk_up(
Packit Service 20376f
	git_buf *pathbuf,
Packit Service 20376f
	const char *ceiling,
Packit Service 20376f
	int (*callback)(void *payload, const char *path),
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
enum { GIT_PATH_NOTEQUAL = 0, GIT_PATH_EQUAL = 1, GIT_PATH_PREFIX = 2 };
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Determines if a path is equal to or potentially a child of another.
Packit Service 20376f
 * @param parent The possible parent
Packit Service 20376f
 * @param child The possible child
Packit Service 20376f
 */
Packit Service 20376f
GIT_INLINE(int) git_path_equal_or_prefixed(
Packit Service 20376f
	const char *parent,
Packit Service 20376f
	const char *child,
Packit Service 20376f
	ssize_t *prefixlen)
Packit Service 20376f
{
Packit Service 20376f
	const char *p = parent, *c = child;
Packit Service 20376f
	int lastslash = 0;
Packit Service 20376f
Packit Service 20376f
	while (*p && *c) {
Packit Service 20376f
		lastslash = (*p == '/');
Packit Service 20376f
Packit Service 20376f
		if (*p++ != *c++)
Packit Service 20376f
			return GIT_PATH_NOTEQUAL;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	if (*p != '\0')
Packit Service 20376f
		return GIT_PATH_NOTEQUAL;
Packit Service 20376f
Packit Service 20376f
	if (*c == '\0') {
Packit Service 20376f
		if (prefixlen)
Packit Service 20376f
			*prefixlen = p - parent;
Packit Service 20376f
Packit Service 20376f
		return GIT_PATH_EQUAL;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	if (*c == '/' || lastslash) {
Packit Service 20376f
		if (prefixlen)
Packit Service 20376f
			*prefixlen = (p - parent) - lastslash;
Packit Service 20376f
Packit Service 20376f
		return GIT_PATH_PREFIX;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	return GIT_PATH_NOTEQUAL;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
/* translate errno to libgit2 error code and set error message */
Packit Service 20376f
extern int git_path_set_error(
Packit Service 20376f
	int errno_value, const char *path, const char *action);
Packit Service 20376f
Packit Service 20376f
/* check if non-ascii characters are present in filename */
Packit Service 20376f
extern bool git_path_has_non_ascii(const char *path, size_t pathlen);
Packit Service 20376f
Packit Service 20376f
#define GIT_PATH_REPO_ENCODING "UTF-8"
Packit Service 20376f
Packit Service 20376f
#ifdef __APPLE__
Packit Service 20376f
#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC"
Packit Service 20376f
#else
Packit Service 20376f
#define GIT_PATH_NATIVE_ENCODING "UTF-8"
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
Packit Service 20376f
#include <iconv.h>
Packit Service 20376f
Packit Service 20376f
typedef struct {
Packit Service 20376f
	iconv_t map;
Packit Service 20376f
	git_buf buf;
Packit Service 20376f
} git_path_iconv_t;
Packit Service 20376f
Packit Service 20376f
#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_BUF_INIT }
Packit Service 20376f
Packit Service 20376f
/* Init iconv data for converting decomposed UTF-8 to precomposed */
Packit Service 20376f
extern int git_path_iconv_init_precompose(git_path_iconv_t *ic);
Packit Service 20376f
Packit Service 20376f
/* Clear allocated iconv data */
Packit Service 20376f
extern void git_path_iconv_clear(git_path_iconv_t *ic);
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Rewrite `in` buffer using iconv map if necessary, replacing `in`
Packit Service 20376f
 * pointer internal iconv buffer if rewrite happened.  The `in` pointer
Packit Service 20376f
 * will be left unchanged if no rewrite was needed.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen);
Packit Service 20376f
Packit Service 20376f
#endif /* GIT_USE_ICONV */
Packit Service 20376f
Packit Service 20376f
extern bool git_path_does_fs_decompose_unicode(const char *root);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
typedef struct git_path_diriter git_path_diriter;
Packit Service 20376f
Packit Service 20376f
#if defined(GIT_WIN32) && !defined(__MINGW32__)
Packit Service 20376f
Packit Service 20376f
struct git_path_diriter
Packit Service 20376f
{
Packit Service 20376f
	git_win32_path path;
Packit Service 20376f
	size_t parent_len;
Packit Service 20376f
Packit Service 20376f
	git_buf path_utf8;
Packit Service 20376f
	size_t parent_utf8_len;
Packit Service 20376f
Packit Service 20376f
	HANDLE handle;
Packit Service 20376f
Packit Service 20376f
	unsigned int flags;
Packit Service 20376f
Packit Service 20376f
	WIN32_FIND_DATAW current;
Packit Service 20376f
	unsigned int needs_next;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_BUF_INIT, 0, INVALID_HANDLE_VALUE }
Packit Service 20376f
Packit Service 20376f
#else
Packit Service 20376f
Packit Service 20376f
struct git_path_diriter
Packit Service 20376f
{
Packit Service 20376f
	git_buf path;
Packit Service 20376f
	size_t parent_len;
Packit Service 20376f
Packit Service 20376f
	unsigned int flags;
Packit Service 20376f
Packit Service 20376f
	DIR *dir;
Packit Service 20376f
Packit Service 20376f
#ifdef GIT_USE_ICONV
Packit Service 20376f
	git_path_iconv_t ic;
Packit Service 20376f
#endif
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#define GIT_PATH_DIRITER_INIT { GIT_BUF_INIT }
Packit Service 20376f
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Initialize a directory iterator.
Packit Service 20376f
 *
Packit Service 20376f
 * @param diriter Pointer to a diriter structure that will be setup.
Packit Service 20376f
 * @param path The path that will be iterated over
Packit Service 20376f
 * @param flags Directory reader flags
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_diriter_init(
Packit Service 20376f
	git_path_diriter *diriter,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	unsigned int flags);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Advance the directory iterator.  Will return GIT_ITEROVER when
Packit Service 20376f
 * the iteration has completed successfully.
Packit Service 20376f
 *
Packit Service 20376f
 * @param diriter The directory iterator
Packit Service 20376f
 * @return 0, GIT_ITEROVER, or an error code
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_diriter_next(git_path_diriter *diriter);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Returns the file name of the current item in the iterator.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to store the path in
Packit Service 20376f
 * @param out_len Pointer to store the length of the path in
Packit Service 20376f
 * @param diriter The directory iterator
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_diriter_filename(
Packit Service 20376f
	const char **out,
Packit Service 20376f
	size_t *out_len,
Packit Service 20376f
	git_path_diriter *diriter);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Returns the full path of the current item in the iterator; that
Packit Service 20376f
 * is the current filename plus the path of the directory that the
Packit Service 20376f
 * iterator was constructed with.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to store the path in
Packit Service 20376f
 * @param out_len Pointer to store the length of the path in
Packit Service 20376f
 * @param diriter The directory iterator
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_diriter_fullpath(
Packit Service 20376f
	const char **out,
Packit Service 20376f
	size_t *out_len,
Packit Service 20376f
	git_path_diriter *diriter);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Performs an `lstat` on the current item in the iterator.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer to store the stat data in
Packit Service 20376f
 * @param diriter The directory iterator
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Closes the directory iterator.
Packit Service 20376f
 *
Packit Service 20376f
 * @param diriter The directory iterator
Packit Service 20376f
 */
Packit Service 20376f
extern void git_path_diriter_free(git_path_diriter *diriter);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Load all directory entries (except '.' and '..') into a vector.
Packit Service 20376f
 *
Packit Service 20376f
 * For cases where `git_path_direach()` is not appropriate, this
Packit Service 20376f
 * allows you to load the filenames in a directory into a vector
Packit Service 20376f
 * of strings. That vector can then be sorted, iterated, or whatever.
Packit Service 20376f
 * Remember to free alloc of the allocated strings when you are done.
Packit Service 20376f
 *
Packit Service 20376f
 * @param contents Vector to fill with directory entry names.
Packit Service 20376f
 * @param path The directory to read from.
Packit Service 20376f
 * @param prefix_len When inserting entries, the trailing part of path
Packit Service 20376f
 * 		will be prefixed after this length.  I.e. given path "/a/b" and
Packit Service 20376f
 * 		prefix_len 3, the entries will look like "b/e1", "b/e2", etc.
Packit Service 20376f
 * @param flags Combination of GIT_PATH_DIR flags.
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_dirload(
Packit Service 20376f
	git_vector *contents,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	size_t prefix_len,
Packit Service 20376f
	uint32_t flags);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/* Used for paths to repositories on the filesystem */
Packit Service 20376f
extern bool git_path_is_local_file_url(const char *file_url);
Packit Service 20376f
extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path);
Packit Service 20376f
Packit Service 20376f
/* Flags to determine path validity in `git_path_isvalid` */
Packit Service 20376f
#define GIT_PATH_REJECT_TRAVERSAL          (1 << 0)
Packit Service 20376f
#define GIT_PATH_REJECT_DOT_GIT            (1 << 1)
Packit Service 20376f
#define GIT_PATH_REJECT_SLASH              (1 << 2)
Packit Service 20376f
#define GIT_PATH_REJECT_BACKSLASH          (1 << 3)
Packit Service 20376f
#define GIT_PATH_REJECT_TRAILING_DOT       (1 << 4)
Packit Service 20376f
#define GIT_PATH_REJECT_TRAILING_SPACE     (1 << 5)
Packit Service 20376f
#define GIT_PATH_REJECT_TRAILING_COLON     (1 << 6)
Packit Service 20376f
#define GIT_PATH_REJECT_DOS_PATHS          (1 << 7)
Packit Service 20376f
#define GIT_PATH_REJECT_NT_CHARS           (1 << 8)
Packit Service 20376f
#define GIT_PATH_REJECT_DOT_GIT_LITERAL    (1 << 9)
Packit Service 20376f
#define GIT_PATH_REJECT_DOT_GIT_HFS        (1 << 10)
Packit Service 20376f
#define GIT_PATH_REJECT_DOT_GIT_NTFS       (1 << 11)
Packit Service 20376f
Packit Service 20376f
/* Default path safety for writing files to disk: since we use the
Packit Service 20376f
 * Win32 "File Namespace" APIs ("\\?\") we need to protect from
Packit Service 20376f
 * paths that the normal Win32 APIs would not write.
Packit Service 20376f
 */
Packit Service 20376f
#ifdef GIT_WIN32
Packit Service 20376f
# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
Packit Service 20376f
	GIT_PATH_REJECT_TRAVERSAL | \
Packit Service 20376f
	GIT_PATH_REJECT_BACKSLASH | \
Packit Service 20376f
	GIT_PATH_REJECT_TRAILING_DOT | \
Packit Service 20376f
	GIT_PATH_REJECT_TRAILING_SPACE | \
Packit Service 20376f
	GIT_PATH_REJECT_TRAILING_COLON | \
Packit Service 20376f
	GIT_PATH_REJECT_DOS_PATHS | \
Packit Service 20376f
	GIT_PATH_REJECT_NT_CHARS
Packit Service 20376f
#else
Packit Service 20376f
# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
Packit Service 20376f
	GIT_PATH_REJECT_TRAVERSAL
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
 /* Paths that should never be written into the working directory. */
Packit Service 20376f
#define GIT_PATH_REJECT_WORKDIR_DEFAULTS \
Packit Service 20376f
	GIT_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT
Packit Service 20376f
Packit Service 20376f
/* Paths that should never be written to the index. */
Packit Service 20376f
#define GIT_PATH_REJECT_INDEX_DEFAULTS \
Packit Service 20376f
	GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Determine whether a path is a valid git path or not - this must not contain
Packit Service 20376f
 * a '.' or '..' component, or a component that is ".git" (in any case).
Packit Service 20376f
 *
Packit Service 20376f
 * `repo` is optional.  If specified, it will be used to determine the short
Packit Service 20376f
 * path name to reject (if `GIT_PATH_REJECT_DOS_SHORTNAME` is specified),
Packit Service 20376f
 * in addition to the default of "git~1".
Packit Service 20376f
 */
Packit Service 20376f
extern bool git_path_isvalid(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	uint16_t mode,
Packit Service 20376f
	unsigned int flags);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Convert any backslashes into slashes
Packit Service 20376f
 */
Packit Service 20376f
int git_path_normalize_slashes(git_buf *out, const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitmodules file
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_dotgit_modules(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitmodules file in NTFS
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_ntfs_dotgit_modules(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitmodules file in HFS+
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_hfs_dotgit_modules(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitignore file
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_dotgit_ignore(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitignore file in NTFS
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitignore file in HFS+
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_hfs_dotgit_ignore(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitignore file
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_dotgit_attributes(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitattributes file in NTFS
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Check whether a path component corresponds to a .gitattributes file in HFS+
Packit Service 20376f
 *
Packit Service 20376f
 * @param name the path component to check
Packit Service 20376f
 * @param len the length of `name`
Packit Service 20376f
 */
Packit Service 20376f
extern int git_path_is_hfs_dotgit_attributes(const char *name, size_t len);
Packit Service 20376f
Packit Service 20376f
#endif