예제 #1
0
 /** {@inheritdoc} */
 public function cleanup($id)
 {
     $dir = $this->getPath($id);
     if (is_dir($dir)) {
         foreach (new \DirectoryIterator($dir) as $file) {
             // There should be no subdirectories, no need for recursion.
             // Every object should be a regular file or "dotfile". Errors
             // can be ignored because a nonempty directory cannot be
             // removed, causing an exception in the final step.
             if (!$file->isDot()) {
                 try {
                     \Library\FileObject::unlink($file->getPathname());
                 } catch (\Exception $e) {
                 }
             }
         }
         \Library\FileObject::rmdir($dir);
     }
 }
예제 #2
0
 public function testRmdirErrorNotEmpty()
 {
     $dir = vfsStream::newDirectory('test')->at($this->_root);
     $dirname = $dir->url();
     $filename = vfsStream::newFile('test.txt')->at($dir)->url();
     try {
         FileObject::rmdir($dirname);
         $this->fail('Expected exception was not thrown');
     } catch (\RuntimeException $e) {
         $this->assertEquals("Error removing directory '{$dirname}'", $e->getMessage());
         $this->assertFileExists($filename);
     }
 }