]>
git.proxmox.com Git - libgit2.git/blob - src/win32/w32_util.c
10e17fcd042ddd333411f43cc1c691efba12d6fd
2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
11 * Creates a FindFirstFile(Ex) filter string from a UTF-8 path.
12 * The filter string enumerates all items in the directory.
14 * @param dest The buffer to receive the filter string.
15 * @param src The UTF-8 path of the directory to enumerate.
16 * @return True if the filter string was created successfully; false otherwise
18 bool git_win32__findfirstfile_filter(git_win32_path dest
, const char *src
)
20 static const wchar_t suffix
[] = L
"\\*";
21 int len
= git_win32_path_from_utf8(dest
, src
);
23 /* Ensure the path was converted */
27 /* Ensure that the path does not end with a trailing slash,
28 * because we're about to add one. Don't rely our trim_end
29 * helper, because we want to remove the backslash even for
30 * drive letter paths, in this case. */
32 (dest
[len
- 1] == L
'/' || dest
[len
- 1] == L
'\\')) {
33 dest
[len
- 1] = L
'\0';
37 /* Ensure we have enough room to add the suffix */
38 if ((size_t)len
>= GIT_WIN_PATH_UTF16
- CONST_STRLEN(suffix
))
46 * Ensures the given path (file or folder) has the +H (hidden) attribute set.
48 * @param path The path which should receive the +H bit.
49 * @return 0 on success; -1 on failure
51 int git_win32__set_hidden(const char *path
, bool hidden
)
54 DWORD attrs
, newattrs
;
56 if (git_win32_path_from_utf8(buf
, path
) < 0)
59 attrs
= GetFileAttributesW(buf
);
61 /* Ensure the path exists */
62 if (attrs
== INVALID_FILE_ATTRIBUTES
)
66 newattrs
= attrs
| FILE_ATTRIBUTE_HIDDEN
;
68 newattrs
= attrs
& ~FILE_ATTRIBUTE_HIDDEN
;
70 if (attrs
!= newattrs
&& !SetFileAttributesW(buf
, newattrs
)) {
71 git_error_set(GIT_ERROR_OS
, "failed to %s hidden bit for '%s'",
72 hidden
? "set" : "unset", path
);
79 int git_win32__hidden(bool *out
, const char *path
)
84 if (git_win32_path_from_utf8(buf
, path
) < 0)
87 attrs
= GetFileAttributesW(buf
);
89 /* Ensure the path exists */
90 if (attrs
== INVALID_FILE_ATTRIBUTES
)
93 *out
= (attrs
& FILE_ATTRIBUTE_HIDDEN
) ? true : false;