#include "w32_util.h"
bool git_win32__findfirstfile_filter(git_win32_path dest, const char *src)
{
static const wchar_t suffix[] = L"\\*";
int len = git_win32_path_from_utf8(dest, src);
if (len < 0)
return false;
if (len > 0 &&
(dest[len - 1] == L'/' || dest[len - 1] == L'\\')) {
dest[len - 1] = L'\0';
len--;
}
if ((size_t)len >= GIT_WIN_PATH_UTF16 - CONST_STRLEN(suffix))
return false;
wcscat(dest, suffix);
return true;
}
int git_win32__set_hidden(const char *path, bool hidden)
{
git_win32_path buf;
DWORD attrs, newattrs;
if (git_win32_path_from_utf8(buf, path) < 0)
return -1;
attrs = GetFileAttributesW(buf);
if (attrs == INVALID_FILE_ATTRIBUTES)
return -1;
if (hidden)
newattrs = attrs | FILE_ATTRIBUTE_HIDDEN;
else
newattrs = attrs & ~FILE_ATTRIBUTE_HIDDEN;
if (attrs != newattrs && !SetFileAttributesW(buf, newattrs)) {
git_error_set(GIT_ERROR_OS, "failed to %s hidden bit for '%s'",
hidden ? "set" : "unset", path);
return -1;
}
return 0;
}
int git_win32__hidden(bool *out, const char *path)
{
git_win32_path buf;
DWORD attrs;
if (git_win32_path_from_utf8(buf, path) < 0)
return -1;
attrs = GetFileAttributesW(buf);
if (attrs == INVALID_FILE_ATTRIBUTES)
return -1;
*out = (attrs & FILE_ATTRIBUTE_HIDDEN) ? true : false;
return 0;
}
int git_win32__file_attribute_to_stat(
struct stat *st,
const WIN32_FILE_ATTRIBUTE_DATA *attrdata,
const wchar_t *path)
{
git_win32__stat_init(st,
attrdata->dwFileAttributes,
attrdata->nFileSizeHigh,
attrdata->nFileSizeLow,
attrdata->ftCreationTime,
attrdata->ftLastAccessTime,
attrdata->ftLastWriteTime);
if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && path) {
git_win32_path target;
if (git_win32_path_readlink_w(target, path) >= 0) {
st->st_mode = (st->st_mode & ~S_IFMT) | S_IFLNK;
if ((st->st_size = git_utf8_from_16(NULL, 0, target)) < 0) {
git_error_set(GIT_ERROR_OS, "could not convert reparse point name for '%ls'", path);
return -1;
}
}
}
return 0;
}