DirectoryIterator 忽略流浪同步文件夹中的目录 [英] DirectoryIterator ignoring directories in vagrant synced folders
问题描述
我正在使用 laravel/homestead vagrant box.当我尝试将 DirectoryIterator
用于同步文件夹时,它只返回点"条目 (..
,.
).
我的 vagrant 同步文件夹被称为 code
(在 vmbox 中),在这个目录中我有我的 vagrant 文件和项目代码,所以当我使用 DirectoryIterator
作为 /home/vagrant
它列出了所有没有问题的目录,包括 code
目录.但是当我将它用于 /home/vagrant/code
时,只显示点条目,其他目录被忽略.scandir()
正常工作,列出所有目录没有问题.
这是代码和输出:
foreach (new DirectoryIterator('/home/vagrant') as $fileInfo) {echo $fileInfo->getFilename() .<br>\n";}输出:....ssh.sudo_as_admin_successful.作曲家.当地的代码.config.bash_别名.wget-hsts.npm
foreach (new DirectoryIterator('/home/vagrant/code') as $fileInfo) {echo $fileInfo->getFilename() .<br>\n";}输出:...
foreach (scandir('/home/vagrant/code') as $fileInfo) {回声 $fileInfo.<br>\n";}输出:....流浪汉宅基地.yaml许可证.txt流浪档案后.sh别名垃圾桶作曲家.jsoncomposer.lock家园项目自述文件脚本源文件
我对 vagrant 也有同样的问题.我调试了一下,发现问题在于同步文件夹的文件类型,而不是DirectoryIterator
问题
Vagrantfile - 文件夹同步配置问题
config.vm.synced_folder "/var/www/virtual/machine/folder", "/var/www/host/machine/folder"
在上述配置中,我没有为 sync 文件夹指定任何文件类型.因此,Vagrant 会自动为我的环境选择最佳的同步文件夹选项
解决方案
我已将同步文件夹文件类型更改为nfs",从而解决了问题
Vagrantfile - 解决方案
config.vm.synced_folder "/var/www/virtual/machine/folder", "/var/www/host/machine/folder", type: "nfs"
注意
<块引用>在使用 NFS 支持的同步文件夹之前,主机必须安装 nfsd,NFS 服务器守护程序.它预装在 Mac OS X 上,通常是在 Linux 上进行简单的软件包安装.
I'm using laravel/homestead vagrant box.
When I try to use DirectoryIterator
for synced folder it returns only the "dot" entries (..
,.
).
My vagrant synced folder is called code
(in vmbox), inside this directory I have my vagrant files and project codes, so when I use DirectoryIterator
for /home/vagrant
it list all directories without problem including code
directory. But when I use it for /home/vagrant/code
only dot entries shows up, other directories is ignored. scandir()
works normally and list all directories without a problem.
Edit: here is the code and outputs:
foreach (new DirectoryIterator('/home/vagrant') as $fileInfo) {
echo $fileInfo->getFilename() . "<br>\n";
}
outputs:
.
..
.ssh
.sudo_as_admin_successful
.composer
.local
code
.config
.bash_aliases
.wget-hsts
.npm
foreach (new DirectoryIterator('/home/vagrant/code') as $fileInfo) {
echo $fileInfo->getFilename() . "<br>\n";
}
outputs:
.
..
foreach (scandir('/home/vagrant/code') as $fileInfo) {
echo $fileInfo. "<br>\n";
}
outputs:
.
..
.vagrant
Homestead.yaml
LICENSE.txt
Vagrantfile
after.sh
aliases
bin
composer.json
composer.lock
homestead
project
readme.md
scripts
src
I had the same issue with vagrant. I debugged a little and found out the issue is the in the file type of the synced folder and not with the DirectoryIterator
Problem
Vagrantfile - folder sync config issue
config.vm.synced_folder "/var/www/virtual/machine/folder", "/var/www/host/machine/folder"
In the above configuration I did not specify any file type for the sync folder. because of that, Vagrant automatically choose the best synced folder option for my environment
Solution
I have changed the sync folder file type to "nfs" which solved the issue
Vagrantfile - solution
config.vm.synced_folder "/var/www/virtual/machine/folder", "/var/www/host/machine/folder", type: "nfs"
Note
Before using synced folders backed by NFS, the host machine must have nfsd installed, the NFS server daemon. This comes pre-installed on Mac OS X, and is typically a simple package install on Linux.
这篇关于DirectoryIterator 忽略流浪同步文件夹中的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!