Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting randomly "unable to unlink old '<file>' (Permission denied)" after a git pull within a Vagrant box

I'm working in a Vagrant box pre-packaged with Homestead 5.0 and sometimes after a git pull or git checkout, I get

unable to unlink old '<file>' (Permission denied)

After rebooting my box, I can pull or checkout normally. I've also tried to git pull locally and it worked perfectly.

Setup:

  • Mac OS Sierra
  • Virtual Box 5.1.14
  • Vagrant 1.9.1
  • Homestead 5.0

Anyone with this problem ?

like image 297
Dominic Avatar asked Mar 03 '17 14:03

Dominic


1 Answers

It looks like it's a bug with macOS (possibly El Capitan but confirmed on Sierra) and/or NFS.

See these Vagrant issues:

  • NFS permission problem on MacOS Sierra
  • Problem with NFS Shared Folder Permissions on Mac OS X (El Capitan)

Most people found that it seems to be related to a filesystem caching issue.

Solution High Sierra (2017-11-21)

Upgrade to High Sierra 10.13.2 Beta 2 as confirmed by JF Bibeau.

Upgraded to High Sierra 10.13.2 Beta 2, removed my cronjob that would periodically do an ls -laR as a workaround, [...]

I'm happy to report I haven't seen this in almost 2 weeks of using High Sierra. It's completely fixed!

Note that a new, but different, problem seem to have arised on High Sierra related to incorrect listing of files on the guest machine.


Possible workarounds

If upgrading to High Sierra is not possible, here's a couple workarounds.

Update Vagrant and Virtualbox

If possible, update both, though some people mentioned downgrading helped.

Recursive listing on the host (Easy workaround)

Running the following on the host refreshes the filesystem cache:

ls -alR [synced_directory] > /dev/null

or opening the Get info menu of the synced directory seem to work temporarily.

Some people made a cron job to do that every 5 minutes so they never encounter the problem even if it's not a definitive solution.

Someone pointed out that running a recusive listing of only the directory had the same effect and was faster.

find [synced_directory] -type d  > /dev/null

Disabling NFS lookupcache

A comment in the issue mentioned:

Disabling NFS lookupcache seems to work, but the performance is unbearable.

Change permissions of synced directory

On the host machine, give read and write access to Everyone. It also seems to work temporarily, probably for the same caching reason the opening the Get info menu works.

Not using NFS

config.vm.synced_folder "./host", "/vagrant-dir", :mount_options => ["dmode=777", "fmode=777"]

But this has a huge performance downside.

Using vagrant-sshfs

This is a vagrant plugin which allows mounting directories with SSHFS. Though from the drawbacks listed on the repo itself:

Performance is worse than an implementation like NFS

Downgrade to El Capitan

Some people mentioned that they were not having this specific "unlink" problem on El Capitan. So downgrading would be a last resort solution to avoid dealing with it.


Some registered Apple developers have reported the problem on bugreport.apple.com (#28927426 and #33043401) but the information is private.

Apple responded and closed the original bug report, saying:

The issue reported in this bug report is fixed but the High Sierra issue is specific to APFS and not the same issue. Please file a new nug (sic) for that issue. Thank you. We are now closing this bug report.

like image 58
Emile Bergeron Avatar answered Nov 01 '22 08:11

Emile Bergeron