You are here

public function TempFileAdapter::deleteTempFile in Backup and Migrate 8.4

Delete a temporary file.

Parameters

string $filename The path to the file.:

Overrides TempFileAdapterInterface::deleteTempFile

1 call to TempFileAdapter::deleteTempFile()
TempFileAdapter::deleteAllTempFiles in lib/backup_migrate_core/src/File/TempFileAdapter.php
Delete all temp files which have been created.
1 method overrides TempFileAdapter::deleteTempFile()
DrupalTempFileAdapter::deleteTempFile in src/File/DrupalTempFileAdapter.php
Delete a temporary file.

File

lib/backup_migrate_core/src/File/TempFileAdapter.php, line 84

Class

TempFileAdapter
Provides a very basic temp file manager which assumes read/write access to a local temp directory.

Namespace

BackupMigrate\Core\File

Code

public function deleteTempFile($filename) {

  // Only delete files that were created by this manager.
  if (in_array($filename, $this->tempfiles)) {
    if (file_exists($filename)) {
      if (is_writable($filename)) {
        unlink($filename);
      }
      else {
        throw new BackupMigrateException('Could not delete the temp file: %file because it is not writable', [
          '%file' => $filename,
        ]);
      }
    }

    // Remove the item from the list.
    $this->tempfiles = array_diff($this->tempfiles, [
      $filename,
    ]);
    return;
  }
  throw new BackupMigrateException('Attempting to delete a temp file not managed by this codebase: %file', [
    '%file' => $filename,
  ]);
}