From 4863902f4f89d00a7fa916d11cf24fe1cb9b8160 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 a68ef11696..293bd5999d 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -175,6 +175,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 19a0205f86..8fe1773974 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