/**
  * @param ResourceDOInterface $resourceDO
  * @param string|resource|Stream $content
  * @return ResourceDOInterface
  * @throws \RuntimeException if the upload was not successful.
  * @throws \InvalidArgumentException if the $path specified is invalid.
  * @throws \RuntimeException on any error during the move operation, or on
  */
 protected function save(ResourceDOInterface $resourceDO, $content)
 {
     $backupResourceVerDO = null;
     $filePath = $resourceDO->getFilePath();
     $this->createDirectory(dirname($filePath));
     // backups don't needs if this is a 'new creation' command
     if ($resourceDO->isRecreate()) {
         $backupResourceVerDO = $this->backup($resourceDO);
     }
     if ($content instanceof UploadedFileInterface) {
         $this->uploadFile($content, $resourceDO->getMimeType(), $filePath);
     } else {
         $this->writeFile($filePath, $content);
     }
     $responseDO = $resourceDO;
     if ($backupResourceVerDO instanceof ResourceDOInterface && $backupResourceVerDO->getVersion() !== ResourceDOInterface::DEFAULT_VERSION) {
         // If the newly created file is the same as the previous version, remove backup immediately
         $responseDO = $this->destroyEqual($resourceDO, $backupResourceVerDO);
     }
     if ($responseDO === $resourceDO) {
         // cleanup postprocessing cache folders
         // - if it is a new file creation (remove possible garbage after other operations)
         // - or if the basic file is replaced and not equal to the previous version
         $this->afterSave($resourceDO);
     }
     if ($this->config->get('staticus.magic_defaults.allow')) {
         $this->copyFileToDefaults($resourceDO);
     }
     return $resourceDO;
 }