示例#1
0
 /**
  * Delete a file or directory.
  *
  * @param File $file the file
  *
  * @param bool $recursive
  *
  * @return bool
  */
 public function delete($file, $recursive = false, $force = false)
 {
     // TODO: invalidate cache after delete?
     if ($file->isDirectory()) {
         if ($recursive) {
             /** @var File $file */
             foreach ($file->ls() as $file) {
                 if (!$file->delete(true, $force)) {
                     return false;
                 }
             }
         } else {
             if ($file->count() > 0) {
                 return false;
             }
         }
         return $this->ftpDelete($file);
     } else {
         if (!$file->isWritable()) {
             if ($force) {
                 $file->setMode(0666);
             } else {
                 return false;
             }
         }
         return $this->ftpDelete($file);
     }
 }