bug fix #19139
@@ -1598,10 +1598,9 @@ | ||
1598 | 1598 | } |
1599 | 1599 | } |
1600 | 1600 | |
1601 | +DEBUG_PRINTF("write compiled file path = (%s)", const_cast<char*>(full_compile_filename.c_str())); | |
1602 | + | |
1601 | 1603 | #ifdef PHP_WIN32 |
1602 | - | |
1603 | -DEBUG_PRINTF("write compiled file (win32) = (%s)", const_cast<char*>(full_compile_filename.c_str())); | |
1604 | - | |
1605 | 1604 | php_stream *strm = php_stream_open_wrapper(const_cast<char*>(full_compile_filename.c_str()), "wb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); |
1606 | 1605 | if (!strm) { |
1607 | 1606 |
@@ -1609,9 +1608,15 @@ | ||
1609 | 1608 | if (full_compile_filename.find(DEFAULT_SLASH) != string::npos) { |
1610 | 1609 | size_t slash_rpos = full_compile_filename.rfind("/"); |
1611 | 1610 | size_t default_slash_rpos = full_compile_filename.rfind(DEFAULT_SLASH); |
1612 | - slash_rpos = slash_rpos > default_slash_rpos ? slash_rpos : default_slash_rpos; | |
1611 | + | |
1612 | +DEBUG_PRINTF("slash_rpos=(%d), default_slash_rpos=(%d)", slash_rpos, default_slash_rpos); | |
1613 | + | |
1614 | + if (slash_rpos == string::npos || slash_rpos < default_slash_rpos) { | |
1615 | + slash_rpos = default_slash_rpos; | |
1616 | + } | |
1613 | 1617 | string directory_path = full_compile_filename.substr(0, slash_rpos); |
1614 | 1618 | |
1619 | +DEBUG_PRINTF("slash_rpos=(%d)", slash_rpos); | |
1615 | 1620 | DEBUG_PRINTF("directory_path=(%s)", const_cast<char*>(directory_path.c_str())); |
1616 | 1621 | |
1617 | 1622 | // mkdir recursively |
@@ -1639,19 +1644,27 @@ | ||
1639 | 1644 | // write compiled file |
1640 | 1645 | FILE *fp = VCWD_FOPEN(full_compile_filename.c_str(), "wb"); |
1641 | 1646 | if (fp == NULL) { |
1642 | - // check sub directory exists or not. | |
1647 | + // create sub directory path | |
1643 | 1648 | if (full_compile_filename.find(DEFAULT_SLASH) != string::npos) { |
1644 | - vector<string> elements; | |
1645 | - split_element(const_cast<char*>(full_compile_filename.c_str()), elements, DEFAULT_SLASH); | |
1646 | - string sub_directory = elements[0]; | |
1647 | - for (vector<string>::iterator i = elements.begin() + 1; i != elements.end() - 1; ++i) { | |
1648 | - sub_directory += DEFAULT_SLASH; | |
1649 | - sub_directory += (*i); | |
1650 | - struct stat cs; | |
1651 | - if (VCWD_STAT(sub_directory.c_str(), &cs) == -1) { | |
1652 | - mkdir(sub_directory.c_str(), 0755); | |
1653 | - } | |
1649 | + size_t slash_rpos = full_compile_filename.rfind("\\"); | |
1650 | + size_t default_slash_rpos = full_compile_filename.rfind(DEFAULT_SLASH); | |
1651 | + | |
1652 | +DEBUG_PRINTF("slash_rpos=(%d), default_slash_rpos=(%d)", slash_rpos, default_slash_rpos); | |
1653 | + | |
1654 | + if (slash_rpos == string::npos || slash_rpos < default_slash_rpos) { | |
1655 | + slash_rpos = default_slash_rpos; | |
1654 | 1656 | } |
1657 | + string directory_path = full_compile_filename.substr(0, slash_rpos); | |
1658 | + | |
1659 | +DEBUG_PRINTF("slash_rpos=(%d)", slash_rpos); | |
1660 | +DEBUG_PRINTF("directory_path=(%s)", const_cast<char*>(directory_path.c_str())); | |
1661 | + | |
1662 | + // mkdir recursively | |
1663 | + php_stream_context *context = NULL; | |
1664 | + if (!php_stream_mkdir(const_cast<char*>(directory_path.c_str()), 0755, (PHP_STREAM_MKDIR_RECURSIVE | REPORT_ERRORS), context)) { | |
1665 | + zend_error(E_ERROR, "fail to php_stream_mkdir (%s)", const_cast<char*>(directory_path.c_str())); | |
1666 | + return; | |
1667 | + } | |
1655 | 1668 | } |
1656 | 1669 | |
1657 | 1670 | fp = VCWD_FOPEN(full_compile_filename.c_str(), "wb"); |