I had an issue on my Windows workstation with Drupal 7.15 and Drush 5.2 or 5.7 when clearing the cache for all 17 sites at the same time. But I think this also occurred on my Linux production server, but cannot check that right now.

When trying to clear the cache using drush @sites cache-clear all, the folder C:\Users\USERNAME/.drush/cache/default/ keeps being created and removed, since I see it flashing by in explorer.

Sometimes the result was (say in 50% of the cases):

'all' cache was cleared in C:/drupal#SITENAME

but sometimes it was:

file_put_contents(C:\Users\USERNAME/.drush/cache/default/5.7-commandfiles-5-360407b77294ab6be6b70c5e54073079.cache): failed to open stream: No such file or directory cache.inc:433 [warning]

Drush seemed to have problems with the writing of a file, so I wrote the following directory check for function DrushJSONCache::writeFile(), situated in cache.inc, and it worked.

/**
 * JSON cache storage backend.
 */
class DrushJSONCache extends DrushFileCache {
  const EXTENSION = '.json';

  function readFile($filename) {
    $item = file_get_contents($filename);
    return $item ? (object)drush_json_decode($item) : FALSE;
  }

  function writeFile($filename, $cache) {
    $dirname = dirname($filename); // <- added line
    if (!is_dir($dirname)) mkdir($dirname, 0777, true); // <- added line
  
    return file_put_contents($filename, drush_json_encode($cache));
  }
}

Comments

moshe weitzman’s picture

Assigned: Unassigned » dmitry_bezer
moshe weitzman’s picture

Issue tags: +Windows
lmeurs’s picture

I can confirm this happened on my Linux production server as well, the additional two lines fixed this for me. (Drupal 7.15, Drush 5.2)

.var.www.vhosts.SERVERNAME.httpdocs#default                >>                [warning]
file_put_contents(/home/admin/.drush/cache/default/5.2-commandfiles-5-e595d987acd5ba595d190642e65183e6.cache): failed to open stream: No such file or directory cache.inc:433

But it also seems that when a site's cache cannot be cleared, Drush does not remove the site from the queue until it has successfully cleared the site's cache. Some sites give no warnings, others 1 or even 2, but eventually they all have success.

moshe weitzman’s picture

Assigned: dmitry_bezer » msonnabaum

Change to Mark as this sounds broader than Windows

fonant’s picture

Confirm that I have the same problem (Linux box, Drush 5.6) for "drush @sites cc all". The two lines added as above to create the @.drush/cache/default@ directory work to fix the error here.

It appears that Drush removes the @.drush/cache/default@ directory when it has finished (perhaps only for a multi-site command?) although there is an empty @.drush/cache/usage@ directory remaining.

The 0777 permissions might possibly be better being a bit more restrictive, depending on who many different users (current shell user only, I presume) need access to the cache. Although since it appears to be deleted anyway, perhaps this isn't a worry.

msonnabaum’s picture

Status: Active » Postponed (maintainer needs more info)

This sounds like the bug that Owen just fixed. Please try again with the latest from master.

lmeurs’s picture

I just updated to Drush v5.8 and ran drush @sites cache-clear all 8 times in a row on the same Windows 7 workstation with 22 sites installed on it. The problem does not occur anymore, but 2 times I got the following warning:

rmdir(C:\Users\USERNAME/.drush/cache/default): Directory not empty
filesystem.inc:143

greg.1.anderson’s picture

Version: 7.x-5.7 » 8.x-6.x-dev
Status: Postponed (maintainer needs more info) » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If desired, you may copy this bug to our Github project and then post a link here to the new issue. Please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.

greg.1.anderson’s picture

Issue summary: View changes

Tried to make clearer that it only happens when clearing cache for all 17 sites, AT THE SAME TIME