2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/directory.h"
19 #include "hphp/runtime/base/array-init.h"
21 #include "hphp/runtime/ext/std/ext_std_file.h"
22 #include "hphp/runtime/base/file.h"
23 #include "hphp/runtime/server/static-content-cache.h"
25 #include <sys/types.h>
30 IMPLEMENT_RESOURCE_ALLOCATION(PlainDirectory
)
32 ///////////////////////////////////////////////////////////////////////////////
35 s_wrapper_type("wrapper_type"),
36 s_stream_type("stream_type"),
38 s_unread_bytes("unread_bytes"),
39 s_seekable("seekable"),
40 s_timed_out("timed_out"),
43 s_plainfile("plainfile"),
47 Array
Directory::getMetaData() {
48 return make_dict_array(
49 s_wrapper_type
, s_plainfile
, // PHP5 compatibility
60 ///////////////////////////////////////////////////////////////////////////////
62 PlainDirectory::PlainDirectory(int fd
) {
63 m_dir
= ::fdopendir(fd
);
66 PlainDirectory::PlainDirectory(const String
& path
) {
67 m_dir
= ::opendir(path
.data());
70 PlainDirectory::~PlainDirectory() {
74 void PlainDirectory::close() {
81 Variant
PlainDirectory::read() {
82 if (!m_dir
) return false;
85 struct dirent
*result
;
86 int ret
= readdir_r(m_dir
, &entry
, &result
);
87 if (ret
!= 0 || !result
) {
90 return String(entry
.d_name
, CopyString
);
93 void PlainDirectory::rewind() {
99 bool PlainDirectory::isValid() const {
103 Variant
ArrayDirectory::read() {
108 auto ret
= m_it
.second();
109 assertx(ret
.isString());
111 return Variant(HHVM_FN(basename
)(ret
.toString()));
114 void ArrayDirectory::rewind() {
118 bool ArrayDirectory::isEof() const {
122 String
ArrayDirectory::path() {
124 return empty_string();
127 auto entry
= m_it
.second();
128 assertx(entry
.isString());
129 return HHVM_FN(dirname
)(entry
.toString());
132 CachedDirectory::CachedDirectory(const String
& path
) {
133 assertx(File::IsVirtualDirectory(path
));
134 m_files
= StaticContentCache::TheFileCache
->listDirectory(path
.toCppString());
137 ///////////////////////////////////////////////////////////////////////////////