From 489a3422d2003892ba3b79e7e44c636824d469dd Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 13 May 2015 11:24:26 -0500 Subject: [PATCH] (GH-121) Remove empty directories / scenarios While adding scenarios it was discovered that the empty directories were not being removed, so the service will ensure those are removed upon removing a package with no changed files in it. --- Scenarios.md | 5 ++-- src/chocolatey.tests.integration/Scenario.cs | 27 ++++++++++++++---- .../installpackage/installpackage.1.0.0.nupkg | Bin 4316 -> 4426 bytes .../tools/chocolateyinstall.ps1 | 6 +++- .../filesystem/DotNetFileSystemSpecs.cs | 2 +- .../scenarios/UninstallScenarios.cs | 8 ++++++ .../scenarios/UpgradeScenarios.cs | 20 ++++++------- .../services/NugetService.cs | 5 ++++ 8 files changed, 54 insertions(+), 19 deletions(-) diff --git a/Scenarios.md b/Scenarios.md index 2488a4de8b..95edb7a46d 100644 --- a/Scenarios.md +++ b/Scenarios.md @@ -126,7 +126,7 @@ * should install where install location reports * should not create a shim for ignored executable in the bin directory * should not create a shim for mismatched case ignored executable in the bin directory - * should not create an extensions folder for the pacakge + * should not create an extensions folder for the package * should not have inconclusive package result * should not have warning package result @@ -315,7 +315,7 @@ * should not have inconclusive package result * should not have warning package result -### ChocolateyUninstallCommand [ 12 Scenario(s), 82 Observation(s) ] +### ChocolateyUninstallCommand [ 12 Scenario(s), 83 Observation(s) ] #### when force uninstalling a package @@ -359,6 +359,7 @@ * should contain a warning message that it uninstalled successfully * should delete a shim for console in the bin directory * should delete a shim for graphical in the bin directory + * should delete any files created during the install * should delete the rollback * should have a successful package result * should not have inconclusive package result diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index 9147f0fe07..08fa4ae024 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -23,10 +23,14 @@ namespace chocolatey.tests.integration using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.nuget; + using chocolatey.infrastructure.app.services; using chocolatey.infrastructure.filesystem; public class Scenario { + + private static IChocolateyPackageService _service; + private static readonly DotNetFileSystem _fileSystem = new DotNetFileSystem(); public static string get_top_level() @@ -79,13 +83,26 @@ public static void add_packages_to_source_location(ChocolateyConfiguration confi public static void install_package(ChocolateyConfiguration config, string packageId, string version) { - var pattern = "{0}.{1}{2}".format_with(packageId, string.IsNullOrWhiteSpace(version) ? "*" : version, Constants.PackageExtension); - var files = _fileSystem.get_files(config.Sources, pattern); - foreach (var file in files) + if (_service == null) { - var packageManager = NugetCommon.GetPackageManager(config,new ChocolateyNugetLogger(), null, null, false); - packageManager.InstallPackage(new OptimizedZipPackage(file), false,false); + _service= NUnitSetup.Container.GetInstance(); } + + var originalPackageName = config.PackageNames; + var originalPackageVersion = config.Version; + + config.PackageNames = packageId; + config.Version = version; + _service.install_run(config); + config.PackageNames = originalPackageName; + config.Version = originalPackageVersion; + //var pattern = "{0}.{1}{2}".format_with(packageId, string.IsNullOrWhiteSpace(version) ? "*" : version, Constants.PackageExtension); + //var files = _fileSystem.get_files(config.Sources, pattern); + //foreach (var file in files) + //{ + // var packageManager = NugetCommon.GetPackageManager(config, new ChocolateyNugetLogger(), null, null, false); + // packageManager.InstallPackage(new OptimizedZipPackage(file), false,false); + //} } private static ChocolateyConfiguration baseline_configuration() diff --git a/src/chocolatey.tests.integration/context/installpackage/installpackage.1.0.0.nupkg b/src/chocolatey.tests.integration/context/installpackage/installpackage.1.0.0.nupkg index 749cb1a648b058f51f6288cfa9f58e662381b32c..277f38fee29acfeba1ac437f513e3502b3123d02 100644 GIT binary patch delta 802 zcmcbkcuGkqz?+$civa{;ZP&PcR=#YyQAmkV*wD<#)G*o7!pOif#U#}rO-Vt2;z50U}E3^IbpLaQ!*nnkTH2R zvp<;r%N)iFa+~OZTSCi#?mRU)fyJ)gx7U{Ikb^+$Z-;jVI+|N<$T(~;;?P{g=qNo~ zb>@o)|2EEKVZL|fka8ufc}K$cikkP;@1JWYKQD<7XfW-_Df}=i;#${wg}q!ElAE%$ z-oB7J`XndLS313CQ*K;>`?P08nwMO@r0j8f;jy@Z{SEuH+cOq_`Cjl($#~-DxvVG7 zwVJS9R`K;~lt{hvqwz7*+a0Syi-X1QXf}U{mofbEQP}JD=1Wr1hTN!roBWui5A3B9 zRxdDpkktoF3$O)1Y4OQbY?fg5HnwmMkhf>HOj|iwl-*pOK)7$tW)EUwG@ZPUa}G%V z=2)%+Oke{*aXML**AQ%KB(DRQp2O=1rXTQnparfepN#^@-nP9ax2%A{?F7WKK#Tw` ztdl45X@j-z=aXi`uLf3ql3$uhoPF{_e#y!I`Gw_S{y)UTzyQL52uA=}g_8{h^a2S4 i3p6=GtVJaBH#!MwB|sBFSQy3BeUmo`sIk@af&>9$ru*Cg delta 687 zcmX@5bVpGrz?+$civa|R>Vn*!HvBfi&O&>Qv*|TgS2G5g5uniJnl=F=TQeYadweBUUdk ztX%+TxVUYPpUsTUK#Kgb=!hsAjlNSo;$P@7E=9}z6OpFGT zb-3n$jM{vf>i`o6$ShDePM*wb2)5ujuLGFo;&TMketaHi9$L(2qX^R0w%6pA70`=L zKr9Qy2yl&sVR9m?++;a^9bi`VT7!ddGdS# ny+8ut1x*_eHz88p8=VBT5}*S>SQyz*hJeX(f@*AnydXgU^T)9< diff --git a/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 index d64eb8f47b..2491151c21 100644 --- a/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 +++ b/src/chocolatey.tests.integration/context/installpackage/tools/chocolateyinstall.ps1 @@ -1 +1,5 @@ -Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +"simple file" | Out-File "$toolsDir\simplefile.txt" -force + +Write-Output "$env:PackageName $env:PackageVersion Installed" + diff --git a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs index 7d032c0b37..653fb137c3 100644 --- a/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure/filesystem/DotNetFileSystemSpecs.cs @@ -233,7 +233,7 @@ public override void Because() { if (FileSystem.directory_exists(TestDirectory)) { - Directory.Delete(TestDirectory); + Directory.Delete(TestDirectory, recursive: true); } FileSystem.create_directory(TestDirectory); diff --git a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs index 15b3851dce..d207d7153c 100644 --- a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs @@ -175,6 +175,14 @@ public void should_delete_a_shim_for_graphical_in_the_bin_directory() File.Exists(shimfile).ShouldBeFalse(); } + [Fact] + public void should_delete_any_files_created_during_the_install() + { + var generatedFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames,"simplefile.txt"); + + File.Exists(generatedFile).ShouldBeFalse(); + } + [Fact] public void should_contain_a_warning_message_that_it_uninstalled_successfully() { diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 12ae77dace..48f2e50ad8 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -1562,7 +1562,7 @@ public override void Context() string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey"); if (Directory.Exists(dotChocolatey)) { - Directory.Delete(dotChocolatey); + Directory.Delete(dotChocolatey, recursive: true); } } @@ -1584,8 +1584,8 @@ public void should_remove_the_legacy_folder_version_of_the_package() { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isdependency.1.0.0"); Directory.Exists(packageDir).ShouldBeFalse(); - } - + } + [Fact] public void should_replace_the_legacy_folder_version_of_the_package_with_a_lib_package_folder_that_has_no_version() { @@ -1599,15 +1599,15 @@ public void should_not_upgrade_the_parent_package() var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency.1.0.0", "hasdependency.1.0.0.nupkg"); var package = new OptimizedZipPackage(packageFile); package.Version.Version.to_string().ShouldEqual("1.0.0.0"); - } - + } + [Fact] public void should_not_add_a_versionless_parent_package_folder_to_the_lib_dir() { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency"); Directory.Exists(packageDir).ShouldBeFalse(); - } - + } + [Fact] public void should_leave_the_parent_package_as_legacy_folder() { @@ -1635,7 +1635,7 @@ public void should_not_add_a_versionless_exact_version_package_folder_to_the_lib { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency"); Directory.Exists(packageDir).ShouldBeFalse(); - } + } [Fact] public void should_contain_a_message_the_dependency_upgraded_successfully() @@ -1778,7 +1778,7 @@ public override void Context() string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey"); if (Directory.Exists(dotChocolatey)) { - Directory.Delete(dotChocolatey); + Directory.Delete(dotChocolatey, recursive: true); } } @@ -1853,7 +1853,7 @@ public void should_remove_the_legacy_folder_version_of_the_exact_version_package { var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency.1.0.0"); Directory.Exists(packageDir).ShouldBeFalse(); - } + } [Fact] public void should_contain_a_message_that_everything_upgraded_successfully() diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 835ef7ea43..34d04e26f2 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -921,6 +921,11 @@ public void remove_installation_files(IPackage removedPackage, ChocolateyPackage } } } + + if (_fileSystem.directory_exists(installDir) && !_fileSystem.get_files(installDir, "*.*", SearchOption.AllDirectories).or_empty_list_if_null().Any()) + { + _fileSystem.delete_directory_if_exists(installDir, recursive: true); + } } private void set_package_names_if_all_is_specified(ChocolateyConfiguration config, Action customAction)