summaryrefslogtreecommitdiff
path: root/src/win32
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-08-28 19:30:08 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2015-08-28 19:30:08 -0400
commitaa06ecaf5bd44ed8ca11948598ef721c1e318025 (patch)
treed9ebd202833f9d77e9458b6a7561f9d044e561e2 /src/win32
parent126932eb0b3986784915acb4fab8f4137d162651 (diff)
parentbdec336301c348404b0590025025420febae5b98 (diff)
downloadlibgit2-aa06ecaf5bd44ed8ca11948598ef721c1e318025.tar.gz
Merge pull request #3352 from ethomson/hidden
win32: ensure hidden files can be staged
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/w32_util.c34
-rw-r--r--src/win32/w32_util.h16
2 files changed, 42 insertions, 8 deletions
diff --git a/src/win32/w32_util.c b/src/win32/w32_util.c
index 2e52525d5..60311bb50 100644
--- a/src/win32/w32_util.c
+++ b/src/win32/w32_util.c
@@ -48,10 +48,10 @@ bool git_win32__findfirstfile_filter(git_win32_path dest, const char *src)
* @param path The path which should receive the +H bit.
* @return 0 on success; -1 on failure
*/
-int git_win32__sethidden(const char *path)
+int git_win32__set_hidden(const char *path, bool hidden)
{
git_win32_path buf;
- DWORD attrs;
+ DWORD attrs, newattrs;
if (git_win32_path_from_utf8(buf, path) < 0)
return -1;
@@ -62,11 +62,35 @@ int git_win32__sethidden(const char *path)
if (attrs == INVALID_FILE_ATTRIBUTES)
return -1;
- /* If the item isn't already +H, add the bit */
- if ((attrs & FILE_ATTRIBUTE_HIDDEN) == 0 &&
- !SetFileAttributesW(buf, attrs | FILE_ATTRIBUTE_HIDDEN))
+ if (hidden)
+ newattrs = attrs | FILE_ATTRIBUTE_HIDDEN;
+ else
+ newattrs = attrs & ~FILE_ATTRIBUTE_HIDDEN;
+
+ if (attrs != newattrs && !SetFileAttributesW(buf, newattrs)) {
+ giterr_set(GITERR_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);
+
+ /* Ensure the path exists */
+ if (attrs == INVALID_FILE_ATTRIBUTES)
return -1;
+ *out = (attrs & FILE_ATTRIBUTE_HIDDEN) ? true : false;
return 0;
}
diff --git a/src/win32/w32_util.h b/src/win32/w32_util.h
index 377d651a8..8db3afbec 100644
--- a/src/win32/w32_util.h
+++ b/src/win32/w32_util.h
@@ -40,12 +40,22 @@ GIT_INLINE(bool) git_win32__isalpha(wchar_t c)
bool git_win32__findfirstfile_filter(git_win32_path dest, const char *src);
/**
- * Ensures the given path (file or folder) has the +H (hidden) attribute set.
+ * Ensures the given path (file or folder) has the +H (hidden) attribute set
+ * or unset.
*
- * @param path The path which should receive the +H bit.
+ * @param path The path that should receive the +H bit.
+ * @param hidden true to set +H, false to unset it
* @return 0 on success; -1 on failure
*/
-int git_win32__sethidden(const char *path);
+extern int git_win32__set_hidden(const char *path, bool hidden);
+
+/**
+ * Determines if the given file or folder has the hidden attribute set.
+ * @param hidden pointer to store hidden value
+ * @param path The path that should be queried for hiddenness.
+ * @return 0 on success or an error code.
+ */
+extern int git_win32__hidden(bool *hidden, const char *path);
/**
* Removes any trailing backslashes from a path, except in the case of a drive