DirectoryIterator ignoring directories in vagrant synced folders

偶尔善良 提交于 2020-12-14 11:08:35

问题


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/codeonly 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

回答1:


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.



来源:https://stackoverflow.com/questions/63207799/directoryiterator-ignoring-directories-in-vagrant-synced-folders

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!