1
0
Fork 0

Add isFresh to InstalledRepositoryInterface and make sure local repo is always an InstalledRepositoryInterface

pull/8777/head^2
Jordi Boggiano 2020-04-23 10:52:33 +02:00
parent 8a1e9744a0
commit 6529fabb24
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
5 changed files with 26 additions and 4 deletions

View File

@ -28,7 +28,7 @@ use Composer\Util\Filesystem;
*/
class FilesystemRepository extends WritableArrayRepository
{
private $file;
protected $file;
private $dumpVersions;
private $rootPackage;

View File

@ -25,4 +25,14 @@ class InstalledArrayRepository extends WritableArrayRepository implements Instal
{
return 'installed '.parent::getRepoName();
}
/**
* {@inheritDoc}
*/
public function isFresh()
{
// this is not a completely correct implementation but there is no way to
// distinguish an empty repo and a newly created one given this is all in-memory
return $this->count() === 0;
}
}

View File

@ -23,4 +23,12 @@ class InstalledFilesystemRepository extends FilesystemRepository implements Inst
{
return 'installed '.parent::getRepoName();
}
/**
* {@inheritDoc}
*/
public function isFresh()
{
return !$this->file->exists();
}
}

View File

@ -21,4 +21,8 @@ namespace Composer\Repository;
*/
interface InstalledRepositoryInterface extends WritableRepositoryInterface
{
/**
* @return bool true if packages were never installed in this repository
*/
public function isFresh();
}

View File

@ -163,9 +163,9 @@ class RepositoryManager
/**
* Sets local repository for the project.
*
* @param WritableRepositoryInterface $repository repository instance
* @param InstalledRepositoryInterface $repository repository instance
*/
public function setLocalRepository(WritableRepositoryInterface $repository)
public function setLocalRepository(InstalledRepositoryInterface $repository)
{
$this->localRepository = $repository;
}
@ -173,7 +173,7 @@ class RepositoryManager
/**
* Returns local repository for the project.
*
* @return WritableRepositoryInterface
* @return InstalledRepositoryInterface
*/
public function getLocalRepository()
{