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

main
Jordi Boggiano 4 years ago
parent 8a1e9744a0
commit 6529fabb24
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

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

@ -25,4 +25,14 @@ class InstalledArrayRepository extends WritableArrayRepository implements Instal
{ {
return 'installed '.parent::getRepoName(); 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;
}
} }

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

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

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

Loading…
Cancel
Save