On Windows, mark directory hidden when starting with dot.

In Windows a file or directory starting with a dot is not
automatically hidden. So lets mark it as hidden when
such a directory is created.

This fixes msysGit issue 288.

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-08 22:44:01 +02:00
committed by Johannes Schindelin
parent e8a0ecc3ac
commit 33dc23c8d1
2 changed files with 29 additions and 6 deletions

View File

@@ -119,6 +119,32 @@ static int err_win_to_posix(DWORD winerr)
return error;
}
static int make_hidden(const char *path)
{
DWORD attribs = GetFileAttributes(path);
if (SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN | attribs))
return 0;
errno = err_win_to_posix(GetLastError());
return -1;
}
#undef mkdir
int mingw_mkdir(const char *path, int mode)
{
int ret = mkdir(path);
if (!ret) {
/*
* In Windows a file or dir starting with a dot is not
* automatically hidden. So lets mark it as hidden when
* such a directory is created.
*/
const char *start = basename((char*)path);
if (*start == '.')
return make_hidden(path);
}
return ret;
}
#undef open
int mingw_open (const char *filename, int oflags, ...)
{

View File

@@ -98,12 +98,6 @@ static inline int fcntl(int fd, int cmd, long arg)
* simple adaptors
*/
static inline int mingw_mkdir(const char *path, int mode)
{
return mkdir(path);
}
#define mkdir mingw_mkdir
static inline int mingw_unlink(const char *pathname)
{
/* read-only files cannot be removed */
@@ -143,6 +137,9 @@ int readlink(const char *path, char *buf, size_t bufsiz);
* replacements of existing functions
*/
int mingw_mkdir(const char *path, int mode);
#define mkdir mingw_mkdir
int mingw_open (const char *filename, int oflags, ...);
#define open mingw_open