From 5cdb2faf0eb8ba0572b798d7c29071a742a3cb66 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 9 Aug 2009 19:12:17 +0200 Subject: [PATCH] Windows: mark newly-created files whose name starts with a dot as hidden Signed-off-by: Johannes Schindelin Acked-by: Johannes Sixt --- Documentation/config.txt | 2 +- compat/mingw.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index bbb7ee262e..f9fd44e783 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -135,7 +135,7 @@ core.fileMode:: core.hideDotFiles:: (Windows-only) If true (which is the default), mark newly-created - directories whose name starts with a dot as hidden. + directories and files whose name starts with a dot as hidden. core.ignoreCygwinFSTricks:: This option is only used by Cygwin implementation of Git. If false, diff --git a/compat/mingw.c b/compat/mingw.c index 126b784119..7bb2635b6d 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2,9 +2,11 @@ #include "win32.h" #include #include +#include #include "../strbuf.h" -#include +extern int hide_dotfiles; +unsigned int _CRT_fmode = _O_BINARY; static int err_win_to_posix(DWORD winerr) { @@ -131,7 +133,6 @@ static int make_hidden(const char *path) #undef mkdir int mingw_mkdir(const char *path, int mode) { - extern int hide_dotfiles; int ret = mkdir(path); if (!ret && hide_dotfiles) { /* @@ -167,6 +168,16 @@ int mingw_open (const char *filename, int oflags, ...) if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) errno = EISDIR; } + if ((oflags & O_CREAT) && fd >= 0 && hide_dotfiles) { + /* + * In Windows a file or dir starting with a dot is not + * automatically hidden. So lets mark it as hidden when + * such a file is created. + */ + const char *start = basename((char*)filename); + if (*start == '.' && make_hidden(filename)) + warning("Could not mark '%s' as hidden.", filename); + } return fd; }