php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch add_lstat_support for SPL related Bug #51766Patch version 2010-08-31 08:53 UTC Return to Bug #51766 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: pajoye@php.netIndex: sapi/apache2handler/sapi_apache2.c =================================================================== --- sapi/apache2handler/sapi_apache2.c (revision 302910) +++ sapi/apache2handler/sapi_apache2.c (working copy) @@ -20,6 +20,7 @@ /* $Id$ */ + #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h" Index: TSRM/tsrm_virtual_cwd.c =================================================================== --- TSRM/tsrm_virtual_cwd.c (revision 302910) +++ TSRM/tsrm_virtual_cwd.c (working copy) @@ -40,6 +40,10 @@ # endif #endif +#ifndef S_IFLNK +# define S_IFLNK 0120000 +#endif + #ifdef NETWARE #include <fsio.h> #endif @@ -202,7 +206,7 @@ return (time_t)UnixTime; } -CWD_API int php_sys_stat(const char *path, struct stat *buf) /* {{{ */ +CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat) /* {{{ */ { WIN32_FILE_ATTRIBUTE_DATA data; __int64 t; @@ -247,9 +251,46 @@ free(tmp); } } + buf->st_uid = buf->st_gid = buf->st_ino = 0; - buf->st_mode = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)) : S_IFREG; - buf->st_mode |= (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)) : (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)|S_IWRITE|(S_IWRITE>>3)|(S_IWRITE>>6)); + + if (lstat && data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { + /* File is a reparse point. Get the target */ + HANDLE hLink = NULL; + REPARSE_DATA_BUFFER * pbuffer; + unsigned int retlength = 0; + TSRM_ALLOCA_FLAG(use_heap_large); + + hLink = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL); + if(hLink == INVALID_HANDLE_VALUE) { + return -1; + } + + pbuffer = (REPARSE_DATA_BUFFER *)tsrm_do_alloca(MAXIMUM_REPARSE_DATA_BUFFER_SIZE, use_heap_large); + if(!DeviceIoControl(hLink, FSCTL_GET_REPARSE_POINT, NULL, 0, pbuffer, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &retlength, NULL)) { + tsrm_free_alloca(pbuffer, use_heap_large); + CloseHandle(hLink); + return -1; + } + + CloseHandle(hLink); + + if(pbuffer->ReparseTag == IO_REPARSE_TAG_SYMLINK) { + buf->st_mode = S_IFLNK; + buf->st_mode |= (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)) : (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)|S_IWRITE|(S_IWRITE>>3)|(S_IWRITE>>6)); + } + +#if 0 /* Not used yet */ + else if(pbuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { + buf->st_mode |=; + } +#endif + tsrm_free_alloca(pbuffer, use_heap_large); + } else { + buf->st_mode = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)) : S_IFREG; + buf->st_mode |= (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)) : (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)|S_IWRITE|(S_IWRITE>>3)|(S_IWRITE>>6)); + } + if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { int len = strlen(path); @@ -272,8 +313,7 @@ buf->st_ctime = FileTimeToUnixTime(data.ftCreationTime); buf->st_mtime = FileTimeToUnixTime(data.ftLastWriteTime); return 0; -} -/* }}} */ +} /* }}} */ #endif static int php_is_dir_ok(const cwd_state *state) /* {{{ */ @@ -715,8 +755,8 @@ memcpy(tmp, path, len+1); if(save && - !(IS_UNC_PATH(path, len) && len >= 3 && path[2] != '?') && - (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { + !(IS_UNC_PATH(path, len) && len >= 3 && path[2] != '?') && + (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { /* File is a reparse point. Get the target */ HANDLE hLink = NULL; REPARSE_DATA_BUFFER * pbuffer; @@ -1209,7 +1249,7 @@ if (length == 0) { return 1; /* Can't cd to empty string */ - } + } while(--length >= 0 && !IS_SLASH(path[length])) { } @@ -1558,7 +1598,6 @@ } /* }}} */ -#if !defined(TSRM_WIN32) CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC) /* {{{ */ { cwd_state new_state; @@ -1570,13 +1609,12 @@ return -1; } - retval = lstat(new_state.cwd, buf); + retval = php_sys_lstat(new_state.cwd, buf); CWD_STATE_FREE(&new_state); return retval; } /* }}} */ -#endif CWD_API int virtual_unlink(const char *path TSRMLS_DC) /* {{{ */ { Index: TSRM/tsrm_virtual_cwd.h =================================================================== --- TSRM/tsrm_virtual_cwd.h (revision 302910) +++ TSRM/tsrm_virtual_cwd.h (working copy) @@ -129,9 +129,12 @@ #endif #ifdef TSRM_WIN32 -CWD_API int php_sys_stat(const char *path, struct stat *buf); +CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat); +# define php_sys_stat(path, buf) php_sys_stat_ex(path, buf, 0) +# define php_sys_lstat(path, buf) php_sys_stat_ex(path, buf, 1) #else # define php_sys_stat stat +# define php_sys_lstat lstat #endif typedef struct _cwd_state { @@ -155,9 +158,9 @@ CWD_API int virtual_creat(const char *path, mode_t mode TSRMLS_DC); CWD_API int virtual_rename(char *oldname, char *newname TSRMLS_DC); CWD_API int virtual_stat(const char *path, struct stat *buf TSRMLS_DC); -#if !defined(TSRM_WIN32) + CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC); -#endif + CWD_API int virtual_unlink(const char *path TSRMLS_DC); CWD_API int virtual_mkdir(const char *pathname, mode_t mode TSRMLS_DC); CWD_API int virtual_rmdir(const char *pathname TSRMLS_DC); @@ -261,9 +264,9 @@ #define VCWD_REALPATH(path, real_path) virtual_realpath(path, real_path TSRMLS_CC) #define VCWD_RENAME(oldname, newname) virtual_rename(oldname, newname TSRMLS_CC) #define VCWD_STAT(path, buff) virtual_stat(path, buff TSRMLS_CC) -#if !defined(TSRM_WIN32) -# define VCWD_LSTAT(path, buff) virtual_lstat(path, buff TSRMLS_CC) -#endif + +#define VCWD_LSTAT(path, buff) virtual_lstat(path, buff TSRMLS_CC) + #define VCWD_UNLINK(path) virtual_unlink(path TSRMLS_CC) #define VCWD_MKDIR(pathname, mode) virtual_mkdir(pathname, mode TSRMLS_CC) #define VCWD_RMDIR(pathname) virtual_rmdir(pathname TSRMLS_CC) Index: Zend/zend_ini_scanner_defs.h =================================================================== --- Zend/zend_ini_scanner_defs.h (revision 302910) +++ Zend/zend_ini_scanner_defs.h (working copy) @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Sun Aug 1 12:07:43 2010 */ +/* Generated by re2c 0.13.5 on Mon Aug 09 09:27:45 2010 */ #line 3 "Zend/zend_ini_scanner_defs.h" enum YYCONDTYPE { Index: Zend/zend_language_scanner_defs.h =================================================================== --- Zend/zend_language_scanner_defs.h (revision 302910) +++ Zend/zend_language_scanner_defs.h (working copy) @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Tue Jun 29 08:18:52 2010 */ +/* Generated by re2c 0.13.5 on Wed Jun 30 22:24:50 2010 */ #line 3 "Zend/zend_language_scanner_defs.h" enum YYCONDTYPE { Index: Zend/zend_ini_scanner.c =================================================================== --- Zend/zend_ini_scanner.c (revision 302910) +++ Zend/zend_ini_scanner.c (working copy) @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Sun Aug 1 12:07:43 2010 */ +/* Generated by re2c 0.13.5 on Mon Aug 09 09:27:45 2010 */ #line 1 "Zend/zend_ini_scanner.l" /* +----------------------------------------------------------------------+ Index: Zend/zend_language_scanner.c =================================================================== --- Zend/zend_language_scanner.c (revision 302910) +++ Zend/zend_language_scanner.c (working copy) @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Tue Jun 29 23:22:29 2010 */ +/* Generated by re2c 0.13.5 on Wed Jun 30 22:24:50 2010 */ #line 1 "Zend/zend_language_scanner.l" /* +----------------------------------------------------------------------+ Index: main/win95nt.h =================================================================== --- main/win95nt.h (revision 302910) +++ main/win95nt.h (working copy) @@ -33,7 +33,7 @@ typedef int uid_t; typedef int gid_t; typedef char * caddr_t; -#define lstat(x, y) stat(x, y) +#define lstat(x, y) php_sys_lstat(x, y) #define _IFIFO 0010000 /* fifo */ #define _IFBLK 0060000 /* block special */ #define _IFLNK 0120000 /* symbolic link */ Index: main/streams/plain_wrapper.c =================================================================== --- main/streams/plain_wrapper.c (revision 302910) +++ main/streams/plain_wrapper.c (working copy) @@ -1017,10 +1017,18 @@ return -1; } -#ifdef HAVE_SYMLINK +#ifdef PHP_WIN32 + if (EG(windows_version_info).dwMajorVersion >= 5) { + if (flags & PHP_STREAM_URL_STAT_LINK) { + return VCWD_LSTAT(url, &ssb->sb); + } + } +#else +# ifdef HAVE_SYMLINK if (flags & PHP_STREAM_URL_STAT_LINK) { return VCWD_LSTAT(url, &ssb->sb); } else +# endif #endif return VCWD_STAT(url, &ssb->sb); } |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Sat May 04 13:01:30 2024 UTC |