/**
  * Fire just before saving a folder.
  *
  * @param EntryInterface|FolderInterface $entry
  * @return bool
  */
 public function saving(EntryInterface $entry)
 {
     $disk = $entry->getDisk();
     /**
      * If the folder already exists then
      * skip it because even if it does not
      * exist on the server it'll be written
      * automatically soon.
      */
     if ($this->folders->findByName($entry->getName(), $disk, $entry->getParent())) {
         return false;
     }
     return parent::saving($entry);
 }
 /**
  * Sync the files folder.
  *
  * @param File          $resource
  * @param DiskInterface $disk
  * @return null|FolderInterface
  */
 protected function syncFolder(File $resource, DiskInterface $disk)
 {
     $path = dirname($resource->getPath());
     if ($path === '.') {
         return null;
     }
     /* @var FolderInterface|null $parent */
     $parent = null;
     $folder = null;
     foreach (explode('/', $path) as $name) {
         if (!($folder = $this->folders->findByName($name, $disk, $parent))) {
             $folder = $this->folders->create(['name' => $name, 'disk_id' => $disk->getId(), 'parent_id' => $parent ? $parent->getId() : null]);
         }
         $parent = $folder;
     }
     return $folder;
 }