Skip to content

Instantly share code, notes, and snippets.

@igorzi
Created November 25, 2011 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorzi/1392592 to your computer and use it in GitHub Desktop.
Save igorzi/1392592 to your computer and use it in GitHub Desktop.
From 5f367063aefc8c7c372b6bf4d0fd3a4d65db5e9a Mon Sep 17 00:00:00 2001
From: Igor Zinkovsky <igorzi@microsoft.com>
Date: Thu, 24 Nov 2011 16:59:58 -0800
Subject: [PATCH] windows: set S_IFDIR for uv_fs_stat
---
src/win/fs.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/src/win/fs.c b/src/win/fs.c
index 8650f77..ec9bfbd 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -491,6 +491,7 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {
void fs__stat(uv_fs_t* req, const wchar_t* path) {
int result;
+ unsigned short mode;
fs__open(req, path, _O_RDONLY, 0);
if (req->result == -1) {
@@ -501,6 +502,20 @@ void fs__stat(uv_fs_t* req, const wchar_t* path) {
if (result == -1) {
req->ptr = NULL;
} else {
+
+ /*
+ * VC CRT doesn't properly set S_IFDIR in _fstati64,
+ * so we set it here if path is a directory.
+ */
+ if (GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY) {
+ mode = req->stat.st_mode;
+ mode &= ~_S_IFMT;
+ mode |= _S_IFDIR;
+
+ req->stat.st_mode = mode;
+ assert((req->stat.st_mode & _S_IFMT) == _S_IFDIR);
+ }
+
req->ptr = &req->stat;
}
--
1.7.4.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment