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_map_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() {
83 struct dirent
*result
;
84 int ret
= readdir_r(m_dir
, &entry
, &result
);
85 if (ret
!= 0 || !result
) {
88 return String(entry
.d_name
, CopyString
);
91 void PlainDirectory::rewind() {
95 bool PlainDirectory::isValid() const {
99 Variant
ArrayDirectory::read() {
104 auto ret
= m_it
.second();
105 assertx(ret
.isString());
107 return Variant(HHVM_FN(basename
)(ret
.toString()));
110 void ArrayDirectory::rewind() {
114 bool ArrayDirectory::isEof() const {
118 String
ArrayDirectory::path() {
120 return empty_string();
123 auto entry
= m_it
.second();
124 assertx(entry
.isString());
125 return HHVM_FN(dirname
)(entry
.toString());
128 CachedDirectory::CachedDirectory(const String
& path
) {
129 assertx(File::IsVirtualDirectory(path
));
130 m_files
= StaticContentCache::TheFileCache
->readDirectory(path
.c_str());
133 ///////////////////////////////////////////////////////////////////////////////