protected function deleteFile($filePath)
 {
     // If file is already gone somewhere, it is OK for us
     if ($this->filesystem->has($filePath) && !$this->filesystem->delete($filePath)) {
         throw new CommandErrorException('The file cannot be removed: ' . $filePath);
     }
 }
 public function delete($spiBinaryFileId)
 {
     try {
         $this->filesystem->delete($spiBinaryFileId);
     } catch (FlysystemNotFoundException $e) {
         throw new BinaryFileNotFoundException($spiBinaryFileId, $e);
     }
 }
Exemple #3
0
 /**
  * Delete an item from the storage if it exists.
  *
  * @param string $key
  *
  * @return void
  */
 public function delete($key)
 {
     try {
         $this->flysystem->delete($key);
     } catch (FileNotFoundException $e) {
         //
     }
 }
 /**
  * {@inheritdoc}
  */
 public function delete($path)
 {
     try {
         return $this->filesystem->delete($path);
     } catch (FileNotFoundException $exception) {
         return false;
     }
 }
 protected function copyFile($fromFullPath, $toFullPath, $replace = false)
 {
     $this->createDirectory(dirname($toFullPath));
     if ($replace) {
         $this->filesystem->delete($toFullPath);
     }
     if (!$this->filesystem->copy($fromFullPath, $toFullPath)) {
         throw new CommandErrorException('File cannot be copied to the path ' . $toFullPath);
     }
 }
 public function handle(DeleteAvatarCommand $command)
 {
     $user = $this->users->findOrFail($command->userId);
     // Make sure the current user is allowed to edit the user profile.
     // This will let admins and the user themselves pass through, and
     // throw an exception otherwise.
     $user->assertCan($command->actor, 'edit');
     $avatarPath = $user->avatar_path;
     $user->changeAvatarPath(null);
     event(new AvatarWillBeDeleted($user, $command));
     $this->uploadDir->delete($avatarPath);
     $user->save();
     $this->dispatchEventsFor($user);
     return $user;
 }
 /**
  * Cleanup old sessions
  * @link http://php.net/manual/en/sessionhandlerinterface.gc.php
  * @param int $maxlifetime <p>
  * Sessions that have not updated for
  * the last maxlifetime seconds will be removed.
  * </p>
  * @return bool <p>
  * The return value (usually TRUE on success, FALSE on failure).
  * Note this value is returned internally to PHP for processing.
  * </p>
  * @since 5.4.0
  */
 public function gc($maxlifetime)
 {
     $files = Finder::create()->in($this->path)->files()->ignoreDotFiles(true)->date('<= now - ' . $maxlifetime . ' seconds');
     foreach ($files as $file) {
         $this->driver->delete($file->getRealPath());
     }
 }
 function it_can_remove_old_backups(FilesystemInterface $filesystem)
 {
     $files = [['path' => '.gitignore'], ['path' => 'foo.sql'], ['path' => 'foo1.sql'], ['path' => 'foo2.sql'], ['path' => 'foo3.sql'], ['path' => 'foo4.sql'], ['path' => 'foo5.sql'], ['path' => 'foo6.sql']];
     $filesystem->listFiles()->willReturn($files);
     $filesystem->getTimestamp('foo.sql')->willReturn(10000);
     $filesystem->getTimestamp('foo1.sql')->willReturn(500);
     $filesystem->getTimestamp('foo2.sql')->willReturn(10000);
     $filesystem->getTimestamp('foo3.sql')->willReturn(10000);
     $filesystem->getTimestamp('foo4.sql')->willReturn(100);
     $filesystem->getTimestamp('.gitignore')->willReturn(50);
     $filesystem->getTimestamp('foo5.sql')->willReturn(10000);
     $filesystem->getTimestamp('foo6.sql')->willReturn(10000);
     $filesystem->delete('foo1.sql')->shouldBeCalled();
     $filesystem->delete('foo4.sql')->shouldBeCalled();
     $this->removeOldBackups(5)->shouldReturn(['foo4.sql', 'foo1.sql']);
 }
 /**
  * {@inheritdoc}
  */
 public function push(BackupInterface $backup)
 {
     $backupDirectory = $backup->getName();
     if (!$this->flysystem->has($backupDirectory) && !$this->flysystem->createDir($backupDirectory)) {
         throw new DestinationException(sprintf('Unable to create backup directory "%s" in flysystem destination.', $backupDirectory));
     }
     $removedBackupFiles = $this->getFiles($backupDirectory);
     /**
      * @var FileInterface $backupFile
      */
     foreach ($backup->getFiles() as $backupFile) {
         if (isset($removedBackupFiles[$backupFile->getRelativePath()])) {
             unset($removedBackupFiles[$backupFile->getRelativePath()]);
         }
         $path = $backupDirectory . '/' . $backupFile->getRelativePath();
         try {
             if ($this->flysystem->has($path)) {
                 if ($backupFile->getModifiedAt() > new \DateTime('@' . $this->flysystem->getTimestamp($path))) {
                     $resource = fopen($backupFile->getPath(), 'r');
                     $this->flysystem->updateStream($path, $resource);
                     fclose($resource);
                 }
             } else {
                 $resource = fopen($backupFile->getPath(), 'r');
                 $this->flysystem->putStream($path, $resource);
                 fclose($resource);
             }
         } catch (\Exception $e) {
             throw new DestinationException(sprintf('Unable to backup file "%s" to flysystem destination.', $backupFile->getPath()), 0, $e);
         }
     }
     /**
      * @var FileInterface $removedBackupFile
      */
     foreach ($removedBackupFiles as $removedBackupFile) {
         $path = $backupDirectory . '/' . $removedBackupFile->getRelativePath();
         try {
             $this->flysystem->delete($path);
         } catch (\Exception $e) {
             throw new DestinationException(sprintf('Unable to cleanup backup destination "%s" after backup process, file "%s" could not be removed.', $backupDirectory, $path), 0, $e);
         }
     }
     $this->removeEmptyDirectories($backupDirectory);
     if (is_array($this->backups)) {
         $this->backups[$backup->getName()] = $backup;
     }
 }
 /**
  * Delete the file at a given path.
  *
  * @param  string|array  $paths
  * @return bool
  */
 public function delete($paths)
 {
     $paths = is_array($paths) ? $paths : func_get_args();
     foreach ($paths as $path) {
         $this->driver->delete($path);
     }
     return true;
 }
Exemple #11
0
 /**
  * @param DeleteAvatar $command
  * @return \Flarum\Core\User
  * @throws PermissionDeniedException
  */
 public function handle(DeleteAvatar $command)
 {
     $actor = $command->actor;
     $user = $this->users->findOrFail($command->userId);
     if ($actor->id !== $user->id) {
         $this->assertCan($actor, 'edit', $user);
     }
     $avatarPath = $user->avatar_path;
     $user->changeAvatarPath(null);
     $this->events->fire(new AvatarWillBeDeleted($user, $actor));
     $user->save();
     if ($this->uploadDir->has($avatarPath)) {
         $this->uploadDir->delete($avatarPath);
     }
     $this->dispatchEventsFor($user, $actor);
     return $user;
 }
Exemple #12
0
 public function it_can_will_error_and_roll_back_when_delete_fails(File $file)
 {
     $uuid = Uuid::uuid4();
     $file->getUuid()->willReturn($uuid);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->fileSystem->delete($uuid->toString())->willReturn(false);
     $this->objectRepository->delete(File::TYPE, $uuid)->shouldNotBeCalled();
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow(\RuntimeException::class)->duringDelete($file);
 }
Exemple #13
0
 private function createAndBackup($path, $content)
 {
     if ($this->enableBackup) {
         if ($this->backup->has($path)) {
             $this->backup->delete($path);
         }
         $this->backup->write($path, $content);
     }
     $this->master->write($path, $content);
 }
Exemple #14
0
 /**
  * Delete the file at a given path.
  *
  * @param  string|array  $paths
  * @return bool
  */
 public function delete($paths)
 {
     $paths = is_array($paths) ? $paths : func_get_args();
     foreach ($paths as $path) {
         try {
             $this->driver->delete($path);
         } catch (FileNotFoundException $e) {
             //
         }
     }
     return true;
 }
Exemple #15
0
 public function delete(File $file)
 {
     $this->pdo->beginTransaction();
     try {
         if (!$this->fileSystem->delete($file->getUuid()->toString())) {
             throw new \RuntimeException('Failed to delete file');
         }
         $this->objectRepository->delete(File::TYPE, $file->getUuid());
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
 /**
  * Delete the file at a given path.
  *
  * @param  string|array  $paths
  * @return bool
  */
 public function delete($paths)
 {
     $paths = is_array($paths) ? $paths : func_get_args();
     $success = true;
     foreach ($paths as $path) {
         try {
             if (!$this->driver->delete($path)) {
                 $success = false;
             }
         } catch (FileNotFoundException $e) {
             $success = false;
         }
     }
     return $success;
 }
 protected function uploadFile(UploadedFileInterface $content, $mime, $filePath)
 {
     $uri = $content->getStream()->getMetadata('uri');
     if (!$uri) {
         throw new SaveResourceErrorException('Unknown error: can\'t get uploaded file uri');
     }
     $uploadedMime = $this->filesystem->getMimetype($uri);
     if ($mime !== $uploadedMime) {
         /**
          * Try to remove unnecessary file because UploadFile object can be emulated
          * @see \Staticus\Middlewares\ActionPostAbstract::download
          */
         $this->filesystem->delete($uri);
         throw new WrongRequestException('Bad request: incorrect mime-type of the uploaded file');
     }
     $content->moveTo($filePath);
 }
Exemple #18
0
 /**
  * Erase a directory.
  *
  * @param string $dirname
  * @throws WriteException
  */
 private function ensuredEraseDir($dirname)
 {
     try {
         $listing = $this->fs->listContents($dirname, false);
         foreach ($listing as $item) {
             if ($item['type'] === 'dir') {
                 $this->fs->deleteDir($item['path']);
             } else {
                 $this->fs->delete($item['path']);
             }
         }
         return;
     } catch (Error $ex) {
     } catch (Exception $ex) {
     }
     throw new WriteException("Directory {$dirname} could not be erased.", $ex);
 }
Exemple #19
0
 /**
  * Erase a directory.
  *
  * @param string $dirname
  * @throws IoWriteException
  */
 public function eraseDir($dirname = '')
 {
     try {
         $listing = $this->fs->listContents($dirname, false);
         foreach ($listing as $item) {
             if ($item['type'] === 'dir') {
                 $this->fs->deleteDir($item['path']);
             } else {
                 $this->fs->delete($item['path']);
             }
         }
     } catch (Error $ex) {
         throw new IoWriteException("Directory {$dirname} could not be erased.", $ex);
     } catch (Exception $ex) {
         throw new IoWriteException("Directory {$dirname} could not be erased.", $ex);
     }
 }
Exemple #20
0
 /**
  * Downloads the packages zipball from github and extracts it.
  *
  * @param  array $package The selected version of the package.
  * @return void
  */
 private function downloadAndExtractPackageZipBall($package)
 {
     // NOTE: We actually use this list to determin if there are any stale
     // packages that need to be deleted, so we generate the list here
     // before we decide if we need to actually download the package or not.
     if (!isset($this->downloaded[$package['name']])) {
         $this->downloaded[$package['name']] = [];
     }
     if (!Linq::from($this->downloaded[$package['name']])->contains($package['version_normalized'])) {
         $this->downloaded[$package['name']][] = $package['version_normalized'];
     }
     $packagePath = $this->vendorDir . '/' . $package['name'] . '/' . $package['version_normalized'];
     if ($this->filesystem->has($packagePath)) {
         $this->notify("ALREADY HAVE PACKAGE\n");
         return;
     }
     $url = $package['dist']['url'];
     $zipBall = $this->http->request('GET', $url)->getBody();
     $zipBallPath = $packagePath . '/dist.zip';
     $this->filesystem->put($zipBallPath, $zipBall);
     $this->zip->extract($zipBallPath, $packagePath);
     $this->filesystem->delete($zipBallPath);
     $this->notify("DONE\n");
 }
Exemple #21
0
 /**
  * @param resource $stream
  */
 public function write($stream)
 {
     $this->_filesystem->delete($this->getPath());
     $this->_filesystem->writeStream($this->getPath(), $stream);
 }
 /**
  * Remove file
  *
  * @param  string  $path  file path
  * @return bool
  **/
 protected function _unlink($path)
 {
     return $this->fs->delete($path);
 }
 /**
  * @param string $containerName
  * @param string $fileName
  * @param string|null $relativePath
  *
  * @return bool
  */
 public function deleteFile($containerName, $fileName, $relativePath)
 {
     $fullFileName = $this->getFullFileName($containerName, $fileName, $relativePath);
     return $this->filesystem->delete($fullFileName);
 }
Exemple #24
0
 /**
  * Deletes a path from a filesystem
  *
  * @param \League\Flysystem\FilesystemInterface $filesystem a filesystem writer
  * @param string $path the path that should be deleted
  * @return bool
  */
 public function deletePath(FilesystemInterface $filesystem, $path)
 {
     $success = false;
     try {
         $success = $filesystem->delete($path);
     } catch (FileNotFoundException $e) {
         // TODO: log this?
     }
     return $success;
 }
 /**
  * Removes a file from the filesystem. This does not check if the file is
  * still used or if it is a bad idea to delete it for some other reason
  * this has to be taken care of in the upper layers (e.g. the Storage)!
  *
  * @param string $fileIdentifier
  * @return bool TRUE if deleting the file succeeded
  */
 public function deleteFile($fileIdentifier)
 {
     return $this->filesystem->delete($fileIdentifier);
 }
Exemple #26
0
 /**
  * Delete a file.
  *
  * @param string $path
  *
  * @throws FileNotFoundException
  *
  * @return bool True on success, false on failure.
  */
 public function delete($path)
 {
     return $this->fileSystem->delete($path);
 }
Exemple #27
0
 /**
  * @inheritdoc
  */
 public function delete($path)
 {
     $path = $this->strategy->encode($path);
     return $this->filesystem->delete($path);
 }
Exemple #28
0
 /**
  * @param \Illuminate\Support\Collection $files
  */
 private function deleteFiles($files)
 {
     foreach ($files as $file) {
         $this->filesystem->delete($file['path']);
     }
 }
 /**
  * Move a file to a new location.
  *
  * @param  string  $from
  * @param  string  $to
  * @return bool
  */
 public function move($from, $to)
 {
     $this->driver->copy($from, $to);
     $this->driver->delete($from);
 }
 /**
  * @param $filePath
  */
 protected function deleteFile($filePath)
 {
     if (!$this->filesystem->delete($filePath)) {
         throw new CommandErrorException('The file cannot be removed: ' . $filePath);
     }
 }