diff --git a/lib/installer.php b/lib/installer.php
index b650f3eed0df4227a88861cdd4b1c914e94b449f..00feb6d470940c95a8943c8751ee583a0ffdd690 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -302,8 +302,8 @@ class OC_Installer{
 						}
 					}
 				}
+				closedir( $dir );
 			}
-			closedir( $dir );
 		}
 	}