Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WIP: [Feature #1135] Util\Filesystem additional methods, unit tests, …

…and update to Composer/Downloader/VcsDownloader.
  • Loading branch information...
commit ffe3c10991623340170c79fb89ee33bf5cd8fc64 1 parent db1aa16
@bzitzow authored
View
6 src/Composer/Downloader/VcsDownloader.php
@@ -55,7 +55,11 @@ public function download(PackageInterface $package, $path)
}
$this->io->write(" - Installing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)");
- $this->filesystem->removeDirectory($path);
+
+ if (!$this->filesystem->directoryIsEmpty($path, array('composer.json'))) {
+ $this->filesystem->removeDirectory($path);
+ }
+
$this->doDownload($package, $path);
$this->io->write('');
}
View
6 src/Composer/Installer/ProjectInstaller.php
@@ -62,14 +62,10 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
$fs = new FileSystem();
if ($fs->directoryExists($installPath)) {
- if (!$fs->directoryIsEmpty($installPath)) {
+ if (!$fs->directoryIsEmpty($installPath, array('composer.json'))) {
throw new \InvalidArgumentException("Project directory \"$installPath\" must be empty.");
}
} else {
-// if (!file_exists(dirname($installPath))) {
-// throw new \InvalidArgumentException("Project root \"" . dirname($installPath) . "\" does not exist.");
-// }
-
mkdir($installPath, 0777, true);
}
View
14 src/Composer/Util/Filesystem.php
@@ -70,20 +70,26 @@ public function directoryExists($dir)
return true;
}
- public function directoryIsEmpty($dir, $excluding= null)
+ /**
+ * @param $dir
+ * @param null $excluding
+ * @return bool
+ * @throws \RuntimeException
+ */
+ public function directoryIsEmpty($dir, $excluding = array())
{
if (!$this->directoryExists($dir)) {
throw new \RuntimeException("Directory \"$dir\" does not exist");
}
$excludeList = array('.', '..');
- if (null !== $excluding) {
-
+ if (!empty($excluding)) {
+ $excludeList = array_merge($excludeList, $excluding);
}
$dirContent = array_diff(scandir($dir), $excludeList);
- if(count($dirContent) >= 1) {
+ if (count($dirContent) >= 1) {
return false;
}
View
45 tests/Composer/Test/Fixtures/projectTestDirectory/composer.json
@@ -0,0 +1,45 @@
+{
+ "name": "composer/composer",
+ "description": "Package Manager",
+ "keywords": ["package", "dependency", "autoload"],
+ "homepage": "http://getcomposer.org/",
+ "type": "library",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Nils Adermann",
+ "email": "naderman@naderman.de",
+ "homepage": "http://www.naderman.de"
+ },
+ {
+ "name": "Jordi Boggiano",
+ "email": "j.boggiano@seld.be",
+ "homepage": "http://seld.be"
+ }
+ ],
+ "support": {
+ "irc": "irc://irc.freenode.org/composer",
+ "issues": "https://github.com/composer/composer/issues"
+ },
+ "require": {
+ "php": ">=5.3.2",
+ "justinrainbow/json-schema": "1.1.*",
+ "seld/jsonlint": "1.*",
+ "symfony/console": "2.1.*",
+ "symfony/finder": "2.1.*",
+ "symfony/process": "2.1.*"
+ },
+ "suggest": {
+ "ext-zip": "Enabling the zip extension allows you to unzip archives, and allows gzip compression of all internet traffic",
+ "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages"
+ },
+ "autoload": {
+ "psr-0": { "Composer": "src/" }
+ },
+ "bin": ["bin/composer"],
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ }
+}
View
37 tests/Composer/Test/Util/FilesystemTest.php
@@ -86,11 +86,44 @@ public function providePathCouples()
array('/tmp/test', '/tmp', "./"),
array('C:/Temp/test/sub', 'C:\Temp', "../"),
array('/tmp/test/sub', '/tmp', "../"),
- array('/tmp/test/sub', '/tmp', "../../", true),
- array('c:/tmp/test/sub', 'c:/tmp', "../../", true),
+ array('/tmp/test/sub', '/tmp', "../../", TRUE),
+ array('c:/tmp/test/sub', 'c:/tmp', "../../", TRUE),
array('/tmp', '/tmp/test', "test"),
array('C:/Temp', 'C:\Temp\test', "test"),
array('C:/Temp', 'c:\Temp\test', "test"),
);
}
+
+ public function testDirectoryExists()
+ {
+ $fs = new Filesystem();
+ $directory1 = '/does/not/exist';
+ $directory2 = __DIR__;
+
+ $this->assertFalse($fs->directoryExists($directory1));
+ $this->assertTrue($fs->directoryExists($directory2));
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ */
+ public function testDirectoryIsEmptyRuntimeException()
+ {
+ $fs = new Filesystem();
+ $dir = '/does/not/exist';
+
+ $fs->directoryIsEmpty($dir);
+ }
+
+ public function testDirectoryIsEmpty()
+ {
+ $fs = new Filesystem();
+ $dir = __DIR__;
+ $project = __DIR__.'/../Fixtures/projectTestDirectory';
+
+ $this->assertFalse($fs->directoryIsEmpty($dir));
+ $this->assertTrue($fs->directoryIsEmpty($project, array('composer.json')));
+ $this->assertFalse($fs->directoryIsEmpty($project));
+
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.