监视文件以了解Vagrant的更改,文件修改时间未更新 [英] Watching files for changes on Vagrant, file modification times not updating

查看:158
本文介绍了监视文件以了解Vagrant的更改,文件修改时间未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试Vagrant.我们在主机上通过NFS与来宾共享了一个Web应用程序目录.在开发网站时,我们很快就开始遇到问题.

We're trying out Vagrant. We have a web application directory on the host shared with the guest via NFS. While developing the website we quickly started to hit issues.

我们正在运行gulp-watch,以查找对样式表和javascript文件的更改并运行任务,但是长达一分钟的时间才发现更改.

We are running gulp-watch to spot changes to stylesheet and javascript files and run tasks, but changes were not being picked up for up to one minute.

Laravel并没有注意到刀片模板正在更改,因此也没有重新编译刀片模板并显示旧的视图模板.

Also, Laravel was not noticing that blade templates were being changed, and so was not recompiling them and the old view templates were being shown.

我最终将问题归结为一个非常简短的PHP脚本,以演示该错误.

I eventually boiled down the problem to a very short PHP script to demonstrate the error.

<?php
header('Content-Type: text/plain');
$file = 'test.html';

echo "modified: " . date('r', filemtime($file)) . "\n";
echo "contents: " . file_get_contents($file) . "\n";

这将获取另一个文件test.html的修改时间,并输出其内容.这产生了奇怪的行为.通过主机更改test.html(增加其全部内容,一个整数)然后刷新页面时,它可以按预期工作(新文件修改日期和新文件内容),或者文件内容将更新但文件修改日期不会.点击刷新后,修改日期就会赶上.这是后一种情况的一个例子.

This gets the modification time of another file test.html and also outputs its contents. This gave strange behaviour. When changing test.html (incrementing its full contents, a single integer) via the host and then refreshing the page, either it would work as expected (new file modification date, and the new file contents) or the contents of the file would update but the file modification date would not. On hitting refresh the modification date would then catch up. Here's an example of the latter case.

后来我发现,如果在修改"和内容"两行之间进行切换,以便在查看修改日期之前检索到内容,那么每次都会得到预期的输出.

I later found that if the "modified" and "contents" lines were switched around so that the contents were retrieved before looking at the modification date, I would get the expected output every time.

问题是什么原因造成的,我们如何解决它,它是否与观察文件更改相关联?

The question was what was causing this and how we could get around it, and was it linked to the issues with watching files for changes?

推荐答案

它们确实是链接的.似乎与有关文件的NFS缓存详细信息有关.

They are indeed linked. It appears to be to do with NFS caching details about files.

运行gulp-watch时,我们可以从主机上编辑来宾正在监视的文件,并且不会引起注意.但是,一旦访客(例如使用cat file.less)访问了文件,gulp-watch进程就会看到更新的修改日期并运行其任务.

With gulp-watch running, we could edit a file from the host which was being watched by the guest, and it would not be noticed. But then as soon as the file was accessed by the guest (for instance with cat file.less) the gulp-watch process would see the updated modification date and run its tasks.

最终的解决方案是给Vagrant一​​个提示,以lookupcache=none选项挂载NFS共享.

The solution in the end was to give Vagrant a hint to mount the NFS share with the lookupcache=none option.

为此,我们Vagrantfile中的一行从

config.vm.synced_folder "./", "/vagrant", type: "nfs"

config.vm.synced_folder "./", "/vagrant", type: "nfs", mount_options: ["lookupcache=none"]

现在可以立即获取更改.

Changes are now picked up immediately.

这篇关于监视文件以了解Vagrant的更改,文件修改时间未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆