Remove uncompressed files

Files are temporarily uncompressed for usage in restore. We do not need these copies
permanently.

@param string $fileName      Relative or absolute path to file
@return boolean              Success or failure of cleanup
559308
protected function cleanup($fileName)
	{
		$status = true;
		$fileNameUncompressed = $this->getUncompressedFileName($fileName);
		if ($fileName !== $fileNameUncompressed)
			$status = File::delete($fileName);

		return $status;
	}
661851
public function contains($filename)
    {
        $this->initialize();

        try {
            $file = $this->matcher->getFile($filename);
        } catch (FileNotFoundException $e) {
            return false;
        }

        foreach ($this->files as $item) {
            if ($item->getFullPath() === $file->getFullPath()) {
                return true;
            }
        }

        return false;
    }
702948
protected function cleanFilename($filename)
    {
        /** @var FileIDHelper $helper */
        $helper = Injector::inst()->get(HashFileIDHelper::class);
        return $helper->cleanFilename($filename);
    }
449729
protected function isExcluded($filename)
    {
        foreach ($this->config->getExcludedFiles() as $excludedFile) {
            if ($filename === $excludedFile) {
                return true;
            }
        }
        foreach ($this->config->getExcludedDirs() as $excludedDir) {
            if (strpos($filename, $excludedDir) === 0) {
                return true;
            }
        }
        return false;
    }
513091
public function deleteDummyFile($fileName)
    {
        $absolutePathToFile = $this->getUploadFolderPath() . $fileName;
        $fileExists = file_exists($absolutePathToFile);

        if (!isset($this->dummyFiles[$fileName])) {
            throw new \InvalidArgumentException(
                'The file "' . $absolutePathToFile . '" which you are trying to delete ' .
                (!$fileExists ? 'does not exist and has never been ' : 'was not ') .
                'created by this instance of the testing framework.',
                1334439315
            );
        }

        if ($fileExists && !unlink($absolutePathToFile)) {
            throw new Exception('The file "' . $absolutePathToFile . '" could not be deleted.', 1334439327);
        }

        unset($this->dummyFiles[$fileName]);
    }
561892
public function removeFolder( $folderName )
	{
		$this->connection->checkConnection();
		$reader	= new Net_FTP_Reader( $this->connection );
		$list	= $reader->getList( $folderName );
		foreach( $list as $entry )
		{
			if( $entry['name'] != "." && $entry['name'] != ".." )
			{
				if( $entry['isdir'] )
					$this->removeFolder( $folderName."/".$entry['name'], TRUE );
				else
					$this->removeFile( $folderName."/".$entry['name'] );
			}
		}
		return @ftp_rmdir( $this->connection->getResource(), $folderName );
	}
158609
public function delete($filename)
		{
			if (true === $this->_enabled && !empty($filename)) {
				$index	= $this->_zip->locateName($filename, \ZipArchive::FL_NODIR);

				if ($index) {
					return $this->deleteIndex((int)$index);
				}
			}

			return false;
		}
191559
public static function deleteDir(string $dirname) : bool
     {
         if (!is_dir($dirname)) {
             return false;
         }

         // Delete dir
         if (is_dir($dirname)) {
             $ob = scandir($dirname);
             foreach ($ob as $o) {
                 if ($o != '.' && $o != '..') {
                     if (filetype($dirname.'/'.$o) == 'dir') {
                         Filesystem::deleteDir($dirname.'/'.$o);
                     } else {
                         unlink($dirname.'/'.$o);
                     }
                 }
             }
         }

         reset($ob);
         rmdir($dirname);

         return true;
     }
357237
public function fileExists($filename)
    {
        if ($this->mediaDirectory->isFile($filename)) {
            return true;
        } else {
            return $this->coreFileStorageDatabase->saveFileToFilesystem(
                $this->mediaDirectory->getAbsolutePath($filename)
            );
        }
    }
1251092
public function export($filename = null)
	{
		if (!$this->getEnabled()) {
			return false;
		}

		if ($filename === null) {
			$filename = $this->getFilename();
		}

		$path = $this->getPath();

		if (!$this->getBackupFilesystemInstance()->checkPathExists($path)) {
			throw new BackupExportException('Unable to export to path "' . $path . '" as it doesn\'t exist.');
		}

		$filepath = $path . '/' . $filename . '.' . $this->getBackupEngineInstance()->getFileExtension();

        $this->setWorkingFilepath($filepath);
		$result = $this->getBackupEngineInstance()->export($filepath);

		if ($result) {
			if ($this->getCompress()) {
				$filepath = $this->compressFile($filepath);
			}

			$this->setWorkingFilepath($filepath);
		} else {
			$this->removeTemporaryFiles($filepath, true);
			$this->setWorkingFilepath(null);
		}

		return $result;
	}
1095430
function releaseMutex($filename) {
		$ret = flock($this->fplock[md5($filename)], LOCK_UN);
		fclose($this->fplock[md5($filename)]);
		unset($this->fplock[md5($filename)]);
		if (! $ret) {
			$this->debug("Not able to release lock for $filename");
		}
		return $ret;
	}
803187
public static function removeExtension($fileName) {
		$ext = strrchr($fileName, '.');
		if($ext !== false) {
			$fileName = substr($fileName, 0, -strlen($ext));
		}
		return $fileName;
	}
53941
public function delete($fileName)
    {
        $path = $this->getPathBase($fileName);

        if (!file_exists($path)) {
            return;
        }

        return unlink($path);
    }
847163
private function tryRemoveWithLock(string $fileName): bool
    {
        if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
            // On Windows, unlinking a locked/opened file will not work, so we just attempt the delete straight away.
            // In the worst case, the unlink will just fail due to concurrent access and the caller needs to deal with that.
            return unlink($fileName);
        }
        $file = fopen($fileName, 'rb');
        if ($file === false) {
            return false;
        }

        $result = false;
        if (flock($file, LOCK_EX) !== false) {
            $result = unlink($fileName);
            flock($file, LOCK_UN);
        }
        fclose($file);

        return $result;
    }
1050048
public function remove($fileName)
    {
        $fileName = $this->getTargetDir() . DIRECTORY_SEPARATOR . $fileName;

        if (!file_exists($fileName)) {
            return;
        }

        unlink($fileName);
    }
272791
public function deleteFile($filename)
    {
        if (!file_exists($this->absolutizePath($filename))) {
            \PHPUnit\Framework\Assert::fail('file not found');
        }
        unlink($this->absolutizePath($filename));
    }
633797
protected function sourceFileExists($filename)
    {
        $fullFilename = $this->formDir . $filename;
        if (file_exists($fullFilename)) {
            return true;
        }

        return false;
    }