Skip to content

Commit 4b32a8c

Browse files
Fix(shadow): Correctly report entry types and resolve build failure
This commit amends the previous attempt to fix SPL iterator type reporting. Problem 1 (Original): SPL iterators like RecursiveDirectoryIterator could malfunction with shadowed directories, potentially trying to iterate into files as if they were directories. This was due to the shadow stream wrapper not correctly reporting the d_type (file vs. directory) for entries. Solution 1 (Original, still active): 1. Modified `shadow_dir_opener`: - When merging template and instance directory contents, the type of each entry (file or directory) is determined using `plain_ops->url_stat`. - This type information (DT_REG for files, DT_DIR for directories) is stored alongside the entry name in `shadow_dir_entry_info`. 2. Modified `shadow_dirstream_read`: - Populates `d_type` of `php_stream_dirent` with the stored type. Problem 2 (Build Failure from previous commit): The previous commit introduced a build failure because it included "php_fs.h", which was not available in your build environment. Solution 2 (This commit): 1. Removed the `#include "php_fs.h"` directive from `shadow.c`. 2. Added `#include <dirent.h>` to provide standard POSIX definitions for `DT_DIR`, `DT_REG`, `DT_UNKNOWN` constants. 3. Ensured fallback definitions (e.g., `#ifndef DT_DIR ...`) for these constants are in place in case `<dirent.h>` does not provide them on a particular system. 4. Verified `<sys/stat.h>` is included for `S_ISDIR`. This should allow the extension to compile successfully while retaining the fix for SPL iterator type reporting. **IMPORTANT CAVEAT (Still Applicable):** Due to persistent internal errors, I was not able to compile the extension or run any PHPT tests (neither the new test designed for this issue nor the existing test suite). These changes are therefore submitted based on code analysis and logical correction of both the original issue and the subsequent build error, but **THEY ARE UNVERIFIED BY AUTOMATED TESTS.** Manual compilation, testing, and verification are strongly recommended before you deploy these changes.
1 parent e3b7589 commit 4b32a8c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

shadow.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#include "ext/standard/php_filestat.h"
2020
#include <sys/stat.h> // For S_ISDIR and struct stat
2121
#include <php_main.h> // For php_stream_dirent, PHP_MAXPATHLEN
22-
#include "php_fs.h" // For php_sys_stat, VCWD_STAT, DT_* constants if available
22+
// #include "php_fs.h" // For php_sys_stat, VCWD_STAT, DT_* constants if available - Replaced by dirent.h
23+
#include <dirent.h> // For DT_DIR, DT_REG, DT_UNKNOWN if available
2324

24-
// Define DT_DIR, DT_REG, DT_UNKNOWN if not available from php_fs.h or system headers
25+
// Define DT_DIR, DT_REG, DT_UNKNOWN if not available from system headers (like dirent.h)
2526
#ifndef DT_DIR
2627
#define DT_DIR 4
2728
#endif

0 commit comments

Comments
 (0)