Framework: Tinker is not working "" php-xdg-runtime-dir-fallback-): Directory not empty ""

Created on 22 Oct 2017  路  23Comments  路  Source: laravel/framework

  • Laravel Version: 5.5.*
  • PHP Version:7.0.10
  • Database Driver & Version: mysql

Description:

every thing was working fine , even tinker ,
when i used php artisan make:transformer
the Error come to life !!!
"rmdir(C:UsersAppData\Local\Temp\php-xdg-runtime-dir-fallback-): Directory not empty"
when i use php artisan tinker

Most helpful comment

composer update should do it. It's fixed in PsySH v0.8.13.

All 23 comments

can you tell us how to reproduce this issue. It seems like you are using Laravel fractal right?

i Don't know how , Yes am using Fractal , am not sure if this problem because of it, but this error is new to me , didn't happen before .
i fixed the problem by deleting the folder "php-xdg-runtime-dir-fallback"
i think there 's a conflict in Laravel 55

yes! i am also facing same error every time when i use tinker.
but i delete that folder every time then it's works ...otherwise it's displays above mentioned error.

Yeah I can understand you gies its frustrating but we need to find how to create such issue so that we find what is causing problem. There can be various reason like package, config, cache

This is a problem with windows compatibility with a dependency. See: https://github.com/bobthecow/psysh/issues/430

They are working on a permanent fix, however they offer a temporary fix in that thread.

My workaround is below. (This edits a vendor file, so if you're not comfortable with that, see the recommended workaround in the linked thread above)

I added this to the bottom of Xdg.php, then replaced all references to rmdir($fallback) with $this->deleteDirectory($fallback);

    /*
     * php delete function that deals with directories recursively
     */
    private function deleteDirectory($dir) {
        if (!file_exists($dir)) {
            return true;
        }

        if (!is_dir($dir)) {
            return unlink($dir);
        }

        foreach (scandir($dir) as $item) {
            if ($item == '.' || $item == '..') {
                continue;
            }

            if (! $this->deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
                return false;
            }

        }

        return rmdir($dir);
    }

I got a solution. we need to overwrite a function in "\vendor\dnoegel\php-xdg-base-dir\tests\XdgTest.php". line 83 to 119

on Windows OS a folder created inside "php-xdg-runtime-dir-fallback-" named "psysh" so we need to remove delete inner folder first then delete outer folder..

    public function getRuntimeDir($strict=true)
    {
        if ($runtimeDir = getenv('XDG_RUNTIME_DIR')) {
            return $runtimeDir;
        }

        if ($strict) {
            throw new \RuntimeException('XDG_RUNTIME_DIR was not set');
        }

        $fallback = sys_get_temp_dir() . DIRECTORY_SEPARATOR . self::RUNTIME_DIR_FALLBACK . getenv('USER');

        $create = false;

        if (!is_dir($fallback)) {
            mkdir($fallback, 0700, true);
        }

        $st = lstat($fallback);

        # The fallback must be a directory
        if (!$st['mode'] & self::S_IFDIR) {
            rmdir($fallback."/psysh");
            rmdir($fallback);
            $create = true;
        } elseif ($st['uid'] != getmyuid() ||
            $st['mode'] & (self::S_IRWXG | self::S_IRWXO)
        ) {

            rmdir($fallback."/psysh");
            rmdir($fallback);
            $create = true;
        }

        if ($create) {
            mkdir($fallback, 0700, true);
        }

        return $fallback;
    }

Strange I never got such problem. Got vanilla PHP from windows.php.net .

composer update should do it. It's fixed in PsySH v0.8.13.

Great. Thanks!

worked Great , but what was the problem ?

There鈥檚 a bug in an underlying library (PHP XDG BaseDir) when running on Windows. v0.8.13 just reverts the one change from v0.8.12 that triggers the bug. A future release will fix it fully.

Cool , Thank You . ^^

Closing since it's not a laravel issue.

I run php artisan tinker and the same error after installing Python.

composer update fixed it.

hello, i have the same issue on linux server after a composer update :
rmdir(/tmp/php-xdg-runtime-dir-fallback-root): Directory not empty

If you've confirmed you have the latest psysh version, then submit an issue to that repo. This isn't a Laravel issue. After updating psysh, I no longer have this issue.

Temporary fix is downgrading psysh to v0.8.11

Just specify the psy/psysh package and version in your composer.json like this

 "laravel/tinker": "~1.0",
 "psy/psysh": "0.8.11",

And run a composer update

https://github.com/bobthecow/psysh/issues/430#issuecomment-344118543

Temp fix not needed. Problem was corrected.

i've fixed it with "Sudo php artisan tinker" :thinking:

ooh. don't do that :-/

Why? is it bad? thanks

The reason you're having trouble is that your current user can't write to your temp directory. Running as sudo bypasses this, but will leave even more files there that your current user can't write to. It's better to fix the temp directory permissions :)

Oh didn't know that! i'll try to fix it then! thanks you very much!

Was this page helpful?
0 / 5 - 0 ratings