diff --git a/typo3/sysext/core/Classes/Package/DependencyResolver.php b/typo3/sysext/core/Classes/Package/DependencyResolver.php
index b7e98f467b9c542b0b6dd270722e04085a27ed8f..f98b42a07284ebbe85027d7054840df229c457e0 100644
--- a/typo3/sysext/core/Classes/Package/DependencyResolver.php
+++ b/typo3/sysext/core/Classes/Package/DependencyResolver.php
@@ -271,9 +271,15 @@ class DependencyResolver {
 	protected function getPackageKeysInBasePath(array $packageStateConfiguration, $basePath, array $excludedPaths = array()) {
 		$packageKeys = array();
 		foreach ($packageStateConfiguration as $packageKey => $package) {
-			if ($basePath === '' || in_array($basePath, $package['packagePathStack'], TRUE)) {
-				$containedExcludedPaths = array_intersect($package['packagePathStack'], $excludedPaths);
-				if (empty($containedExcludedPaths)) {
+			if (($basePath === '' || strpos($package['packagePath'], $basePath) === 0)) {
+				$isExcluded = FALSE;
+				foreach ($excludedPaths as $excludedPath) {
+					if (strpos($package['packagePath'], $excludedPath) === 0) {
+						$isExcluded = TRUE;
+						break;
+					}
+				}
+				if (!$isExcluded) {
 					$packageKeys[] = $packageKey;
 				}
 			}
@@ -281,4 +287,4 @@ class DependencyResolver {
 		return $packageKeys;
 	}
 
-}
\ No newline at end of file
+}
diff --git a/typo3/sysext/core/Classes/Package/PackageManager.php b/typo3/sysext/core/Classes/Package/PackageManager.php
index 1555f3c17ff7eb9f82a4c95676102895efd7a5b9..fb713d1206e4caa362224276fb4de66b243a1c10 100644
--- a/typo3/sysext/core/Classes/Package/PackageManager.php
+++ b/typo3/sysext/core/Classes/Package/PackageManager.php
@@ -83,9 +83,9 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 	 */
 	public function __construct() {
 		$this->packagesBasePaths = array(
-			'sysext'    => PATH_typo3 . 'sysext',
-			'global'    => PATH_typo3 . 'ext',
 			'local'     => PATH_typo3conf . 'ext',
+			'global'    => PATH_typo3 . 'ext',
+			'sysext'    => PATH_typo3 . 'sysext',
 			'composer'  => PATH_site . 'Packages',
 		);
 		$this->packageStatesPathAndFilename = PATH_typo3conf . 'PackageStates.php';
@@ -384,10 +384,6 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 			}
 
 			$this->packageStatesConfiguration['packages'][$packageKey]['packagePath'] = str_replace($this->packagesBasePath, '', $packagePath);
-			// An extension might be overwritten by another one. (eg sysext overwritten with ext)
-			// We have to remember which paths we found the extension in as
-			// we need to know this in the DependencyResolver later.
-			$this->packageStatesConfiguration['packages'][$packageKey]['packagePathStack'][] = $this->packageStatesConfiguration['packages'][$packageKey]['packagePath'];
 
 			// Change this to read the target from Composer or any other source
 			$this->packageStatesConfiguration['packages'][$packageKey]['classesPath'] = Package::DIRECTORY_CLASSES;
@@ -707,9 +703,6 @@ class PackageManager extends \TYPO3\Flow\Package\PackageManager implements \TYPO
 		$newPackages = array();
 		foreach (array_keys($this->packageStatesConfiguration['packages']) as $packageKey) {
 			$newPackages[$packageKey] = $this->packages[$packageKey];
-			// Remove the packagePathStack here again. We don't need it anymore and
-			// we don't want it in the package states file
-			unset($this->packageStatesConfiguration['packages'][$packageKey]['packagePathStack']);
 		}
 		$this->packages = $newPackages;
 	}
diff --git a/typo3/sysext/core/Tests/Unit/Package/DependencyResolverTest.php b/typo3/sysext/core/Tests/Unit/Package/DependencyResolverTest.php
index b9de6a24097af2362fb4f978ce2e71a072ff65c5..c9afedbe61482413898c94d6a7e1b040cf75e542 100644
--- a/typo3/sysext/core/Tests/Unit/Package/DependencyResolverTest.php
+++ b/typo3/sysext/core/Tests/Unit/Package/DependencyResolverTest.php
@@ -84,15 +84,22 @@ class DependencyResolverTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 			'A' => array(
 				'state' => 'active',
 				'dependencies' => array('B'),
-				'packagePathStack' => array('foo')
 			),
 			'B' => array(
 				'state' => 'active',
-				'dependencies' => array('A'),
-				'packagePathStack' => array('foo')
+				'dependencies' => array('A')
 			),
 		);
-		$dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('dummy'));
+
+		$packageKeys = array_keys($unsortedPackageStatesConfiguration);
+
+		$basePathAssignment = array(
+			array($unsortedPackageStatesConfiguration, '', array(DependencyResolver::SYSEXT_FOLDER), $packageKeys),
+			array($unsortedPackageStatesConfiguration, DependencyResolver::SYSEXT_FOLDER, array(), array()),
+		);
+
+		$dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('getActivePackageKeysOfType'));
+		$dependencyResolver->expects($this->any())->method('getActivePackageKeysOfType')->will($this->returnValueMap($basePathAssignment));
 		$dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
 	}
 
@@ -868,94 +875,4 @@ class DependencyResolverTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		$this->assertSame($expected, $path);
 	}
 
-	/**
-	 * Data provider for getPackageKeysInBasePathReturnsCorrectKeys
-	 * @return array
-	 */
-	public function getPackageKeysInBasePathReturnsCorrectKeysDataProvider() {
-		return array(
-			'Single paths only, include all' => array(
-				array(
-					'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-					'key2' => array('packagePathStack' => array('somewhereelse')),
-					'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-				),
-				'',
-				array(),
-				array('key1', 'key2', 'key3')
-			),
-			'Single paths only, include sysext' => array(
-				array(
-					'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-					'key2' => array('packagePathStack' => array('somewhereelse')),
-					'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-				),
-				DependencyResolver::SYSEXT_FOLDER,
-				array(),
-				array('key1', 'key3')
-			),
-			'Single paths only, exclude sysext' => array(
-				array(
-					'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-					'key2' => array('packagePathStack' => array('somewhereelse')),
-					'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-				),
-				'',
-				array(DependencyResolver::SYSEXT_FOLDER),
-				array('key2')
-			),
-			'Multiple paths, include sysext' => array(
-				array(
-					'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
-					'key2' => array('packagePathStack' => array('somewhereelse')),
-					'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-				),
-				DependencyResolver::SYSEXT_FOLDER,
-				array(),
-				array('key1', 'key3')
-			),
-			'Multiple paths, exclude sysext' => array(
-				array(
-					'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
-					'key2' => array('packagePathStack' => array('somewhereelse')),
-					'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-					'key4' => array('packagePathStack' => array('elsewhere')),
-				),
-				'',
-				array(DependencyResolver::SYSEXT_FOLDER),
-				array('key2', 'key4')
-			),
-			'Multiple paths, include somewhereelse' => array(
-				array(
-					'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
-					'key2' => array('packagePathStack' => array('somewhereelse')),
-					'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-				),
-				'somewhereelse',
-				array(),
-				array('key1', 'key2')
-			),
-			'Multiple paths, include somewhereelse, exclude sysext' => array(
-				array(
-					'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
-					'key2' => array('packagePathStack' => array('somewhereelse')),
-					'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
-					'key4' => array('packagePathStack' => array('elsewhere')),
-				),
-				'somewhereelse',
-				array(DependencyResolver::SYSEXT_FOLDER),
-				array('key2')
-			),
-		);
-	}
-
-	/**
-	 * @test
-	 * @dataProvider getPackageKeysInBasePathReturnsCorrectKeysDataProvider
-	 */
-	public function getPackageKeysInBasePathReturnsCorrectKeys(array $packageStates, $include, array $exclude, array $expectedKeys) {
-		$dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('dummy'));
-		$keys = $dependencyResolver->_call('getPackageKeysInBasePath', $packageStates, $include, $exclude);
-		$this->assertSame($expectedKeys, $keys);
-	}
 }