From f95b4f00a6b3bfb64dae4a9d27bce4b8998562d1 Mon Sep 17 00:00:00 2001 From: Johan 't Hart Date: Wed, 12 Aug 2009 23:40:50 +0200 Subject: [PATCH] Windows: mark newly-created dot files by fopen() as hidden Files starting with a dot are considered "hidden", i.e. you have to ask explicitely to see them. On Windows, this is not done automatically, as Windows has its own mechanism. We already mark dot directories created by mkdir() and dot files created by open() as hidden, so let's do that with fopen(), too (but only if the file was just created, not when it already exists). Naturally, we make this behavior optional on core.hideDotFiles. Signed-off-by: Johannes Schindelin Acked-by: Johannes Sixt --- compat/mingw.c | 18 ++++++++++++++++++ compat/mingw.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/compat/mingw.c b/compat/mingw.c index 7bb2635b6d..556ed57fea 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -181,6 +181,24 @@ int mingw_open (const char *filename, int oflags, ...) return fd; } +#undef fopen +FILE *mingw_fopen (const char *filename, const char *mode) +{ + int hide = 0; + if (hide_dotfiles && basename((char*)filename)[0] == '.') + hide = access(filename, F_OK); + + FILE *file = fopen(filename, mode); + /* + * 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. + */ + if (file && hide && make_hidden(filename)) + warning("Could not mark '%s' as hidden.", filename); + return file; +} + static inline time_t filetime_to_time_t(const FILETIME *ft) { long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime; diff --git a/compat/mingw.h b/compat/mingw.h index 0091ba7f3c..0300a14c4a 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -143,6 +143,9 @@ int mingw_mkdir(const char *path, int mode); int mingw_open (const char *filename, int oflags, ...); #define open mingw_open +FILE *mingw_fopen (const char *filename, const char *mode); +#define fopen mingw_fopen + char *mingw_getcwd(char *pointer, int len); #define getcwd mingw_getcwd