Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant & Symfony 3.3: Failed to remove directory

Trying to set up a Symfony 3.3 environment with Flex. Currently, when trying to require some packages like the following:

composer req annotations security orm template asset validator

Everything goes well, except on cache:clear I'm getting the following errors:

!!    [Symfony\Component\Filesystem\Exception\IOException]                         
!!    Failed to remove directory "/home/vagrant/Code/multi-user-gallery-blog/var/  
!!    cache/loca~/pools": rmdir(/home/vagrant/Code/multi-user-gallery-blog/var/ca  
!!    che/loca~/pools): Directory not empty. 

I already tried to remove the folders manually, but those are generated automatically in the installation process, and then Symfony cannot remove them.

I'm running this on Vagrant Homestead.

Any idea on how can I solve this problem?

like image 548
Cláudio Ribeiro Avatar asked Nov 12 '17 17:11

Cláudio Ribeiro


2 Answers

See my comment to the accepted answer, here is the code:

public function getCacheDir()
{
    if (in_array($this->environment, ['dev', 'test'])) {
        return '/tmp/cache/' .  $this->environment;
    }

    return parent::getCacheDir();
}

public function getLogDir()
{
    if (in_array($this->environment, ['dev', 'test'])) {
        return '/var/log/symfony/logs';
    }

    return parent::getLogDir();
}
like image 63
Nicolas Avatar answered Sep 20 '22 19:09

Nicolas


This is an issue with the way Vagrant/VirtualBox maps shared folders between the host and guest machines. In Symfony projects, the cache directory is typically placed within the project directory that gets synced from the host machine.

We can change the cache directory to use a location within the guest machine's filesystem to avoid these problems by adding an override method to the app/AppKernel.php class:

class AppKernel extends Kernel 
{
    ...
    public function getCacheDir() 
    {
        if ($this->environment === 'local') {
            return '/tmp/symfony/cache';
        }

        return parent::getCacheDir();
    }
}

The example above demonstrates how we can set a custom cache directory for local development environments while retaining the default behavior for production. /tmp/symfony/cache is just an example. We can choose a location anywhere on the guest machine's filesystem that the application has permission to write to. Replace 'local' with the name of the environment the project uses for development.

like image 38
Cy Rossignol Avatar answered Sep 24 '22 19:09

Cy Rossignol