Skip to content

Commit

Permalink
(chocolateyGH-121) Remove empty directories / scenarios
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed May 13, 2015
1 parent c1d1992 commit 489a342
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Scenarios.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions src/chocolatey.tests.integration/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<IChocolateyPackageService>();
}

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()
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
"simple file" | Out-File "$toolsDir\simplefile.txt" -force

Write-Output "$env:PackageName $env:PackageVersion Installed"

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
20 changes: 10 additions & 10 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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()
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 489a342

Please sign in to comment.