diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 9b931333b7f729542c2c87bd539ea45a410d6588..495532561ea05a076e0ac3ff4e3804c9b7f80102 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -883,11 +883,19 @@ class Trashbin {
 		$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), \RecursiveIteratorIterator::CHILD_FIRST);
 		$size = 0;
 
-		foreach ($iterator as $path) {
+        /**
+		 * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
+		 * This bug is fixed in PHP 5.5.9 or before
+		 * See #8376
+		 */
+		$iterator->rewind();
+		while ($iterator->valid()) {
+			$path = $iterator->current();
 			$relpath = substr($path, strlen($root) - 1);
 			if (!$view->is_dir($relpath)) {
 				$size += $view->filesize($relpath);
 			}
+			$iterator->next();
 		}
 		return $size;
 	}
diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php
index ed2ad87085877f1784edf6605fbb9e77d16c9c98..de940fc7cdb6735498742c38d2923a8bbac5b19f 100644
--- a/lib/private/files/storage/local.php
+++ b/lib/private/files/storage/local.php
@@ -44,6 +44,11 @@ if (\OC_Util::runningOnWindows()) {
 					new \RecursiveDirectoryIterator($this->datadir . $path),
 					\RecursiveIteratorIterator::CHILD_FIRST
 				);
+				/**
+				 * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
+				 * This bug is fixed in PHP 5.5.9 or before
+				 * See #8376
+				 */
 				$it->rewind();
 				while ($it->valid()) {
 					/**
diff --git a/lib/private/files/storage/mappedlocal.php b/lib/private/files/storage/mappedlocal.php
index 75582fd6c8365d37b5e530fb2bbb3322c5d13608..f995cb00c7af663a0bd1b336329b9746a4004ff3 100644
--- a/lib/private/files/storage/mappedlocal.php
+++ b/lib/private/files/storage/mappedlocal.php
@@ -39,17 +39,26 @@ class MappedLocal extends \OC\Files\Storage\Common{
 				new \RecursiveDirectoryIterator($this->buildPath($path)),
 				\RecursiveIteratorIterator::CHILD_FIRST
 			);
-			foreach ($it as $file) {
+			/**
+			 * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
+             * This bug is fixed in PHP 5.5.9 or before
+			 * See #8376
+			 */
+			$it->rewind();
+			while ($it->valid()) {
 				/**
 				 * @var \SplFileInfo $file
 				 */
+				$file = $it->current();
 				if (in_array($file->getBasename(), array('.', '..'))) {
+					$it->next();
 					continue;
 				} elseif ($file->isDir()) {
 					rmdir($file->getPathname());
 				} elseif ($file->isFile() || $file->isLink()) {
 					unlink($file->getPathname());
 				}
+				$it->next();
 			}
 			if ($result = @rmdir($this->buildPath($path))) {
 				$this->cleanMapper($path);