mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
dir.h: direct::d_type
* dir.c (glob_helper): use d_type to reduce lstat system calls. * win32/dir.h (struct direct): add d_type instead of d_isdir and d_isrep. SYMLINKD is unreliable, since the target can be replaced after a link was created. * win32/win32.c (readdir_internal): set d_type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b48ef1382f
commit
00f7db376c
4 changed files with 25 additions and 6 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Sat Mar 14 12:23:53 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* dir.c (glob_helper): use d_type to reduce lstat system calls.
|
||||||
|
|
||||||
|
* win32/dir.h (struct direct): add d_type instead of d_isdir and
|
||||||
|
d_isrep. SYMLINKD is unreliable, since the target can be
|
||||||
|
replaced after a link was created.
|
||||||
|
|
||||||
|
* win32/win32.c (readdir_internal): set d_type.
|
||||||
|
|
||||||
Sat Mar 14 02:14:50 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Mar 14 02:14:50 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (primary): empty parentheses at cmdarg can be null.
|
* parse.y (primary): empty parentheses at cmdarg can be null.
|
||||||
|
|
4
dir.c
4
dir.c
|
@ -1731,13 +1731,13 @@ glob_helper(
|
||||||
name = buf + pathlen + (dirsep != 0);
|
name = buf + pathlen + (dirsep != 0);
|
||||||
if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1)) {
|
if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1)) {
|
||||||
/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
|
/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
|
||||||
#ifndef _WIN32
|
#ifndef DT_DIR
|
||||||
if (do_lstat(buf, &st, flags, enc) == 0)
|
if (do_lstat(buf, &st, flags, enc) == 0)
|
||||||
new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
|
new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
|
||||||
else
|
else
|
||||||
new_isdir = NO;
|
new_isdir = NO;
|
||||||
#else
|
#else
|
||||||
new_isdir = dp->d_isdir ? (!dp->d_isrep ? YES : UNKNOWN) : NO;
|
new_isdir = dp->d_type == DT_DIR ? YES : dp->d_type == DT_LNK ? UNKNOWN : NO;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,11 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define DT_UNKNOWN 0
|
||||||
|
#define DT_DIR (S_IFDIR>>12)
|
||||||
|
#define DT_REG (S_IFREG>>12)
|
||||||
|
#define DT_LNK 10
|
||||||
|
|
||||||
struct direct
|
struct direct
|
||||||
{
|
{
|
||||||
long d_namlen;
|
long d_namlen;
|
||||||
|
@ -15,8 +20,7 @@ struct direct
|
||||||
char *d_name;
|
char *d_name;
|
||||||
char *d_altname; /* short name */
|
char *d_altname; /* short name */
|
||||||
short d_altlen;
|
short d_altlen;
|
||||||
char d_isdir; /* directory */
|
uint8_t d_type;
|
||||||
char d_isrep; /* reparse point */
|
|
||||||
};
|
};
|
||||||
typedef struct {
|
typedef struct {
|
||||||
WCHAR *start;
|
WCHAR *start;
|
||||||
|
|
|
@ -2139,8 +2139,13 @@ readdir_internal(DIR *dirp, BOOL (*conv)(const WCHAR *, const WCHAR *, struct di
|
||||||
//
|
//
|
||||||
// Attributes
|
// Attributes
|
||||||
//
|
//
|
||||||
dirp->dirstr.d_isdir = GetBit(dirp->bits, BitOfIsDir(dirp->loc));
|
/* ignore FILE_ATTRIBUTE_DIRECTORY as unreliable for reparse points */
|
||||||
dirp->dirstr.d_isrep = GetBit(dirp->bits, BitOfIsRep(dirp->loc));
|
if (GetBit(dirp->bits, BitOfIsRep(dirp->loc)))
|
||||||
|
dirp->dirstr.d_type = DT_LNK;
|
||||||
|
else if (GetBit(dirp->bits, BitOfIsDir(dirp->loc)))
|
||||||
|
dirp->dirstr.d_type = DT_DIR;
|
||||||
|
else
|
||||||
|
dirp->dirstr.d_type = DT_REG;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Now set up for the next call to readdir
|
// Now set up for the next call to readdir
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue