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 <johannes.schindelin@gmx.de>
Acked-by: Johannes Sixt <j6t@kdbg.org>
This commit is contained in:
Johan 't Hart
2009-08-12 23:40:50 +02:00
committed by Johannes Schindelin
parent 5cdb2faf0e
commit f95b4f00a6
2 changed files with 21 additions and 0 deletions

View File

@@ -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;

View File

@@ -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