Skip to content

Commit

Permalink
(chocolateyGH-121) IFilesService capture files by directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ferventcoder committed May 15, 2015
1 parent 7f7b277 commit 40b4437
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/chocolatey/infrastructure.app/services/FilesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,23 @@ public PackageFiles capture_package_files(PackageResult packageResult, Chocolate
return null;
}

return capture_package_files(installDirectory, config);
}

public PackageFiles capture_package_files(string directory, ChocolateyConfiguration config)
{
if (directory.is_equal_to(ApplicationParameters.InstallLocation) || directory.is_equal_to(ApplicationParameters.PackagesLocation))
{
var logMessage = "Install location is not specific enough, cannot capture files:{0} Erroneous install location captured as '{1}'".format_with(Environment.NewLine, directory);
this.Log().Error(logMessage);
return null;
}

var packageFiles = new PackageFiles();

this.Log().Debug(() => "Capturing package files in '{0}'".format_with(installDirectory));
this.Log().Debug(() => "Capturing package files in '{0}'".format_with(directory));
//gather all files in the folder
var files = _fileSystem.get_files(installDirectory, pattern: "*.*", option: SearchOption.AllDirectories);
var files = _fileSystem.get_files(directory, pattern: "*.*", option: SearchOption.AllDirectories);
foreach (string file in files.or_empty_list_if_null())
{
packageFiles.Files.Add(get_package_file(file));
Expand All @@ -80,6 +92,7 @@ public PackageFiles capture_package_files(PackageResult packageResult, Chocolate
return packageFiles;
}


public PackageFile get_package_file(string file)
{
var hash = _hashProvider.hash_file(file);
Expand Down
8 changes: 8 additions & 0 deletions src/chocolatey/infrastructure.app/services/IFilesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public interface IFilesService
/// <returns>PackageFiles with entries based on the install location of the package.</returns>
PackageFiles capture_package_files(PackageResult packageResult, ChocolateyConfiguration config);

/// <summary>
/// Captures the snapshot of the package files
/// </summary>
/// <param name="directory">The directory.</param>
/// <param name="config">The configuration.</param>
/// <returns>PackageFiles with entries based on the install location of the package.</returns>
PackageFiles capture_package_files(string directory, ChocolateyConfiguration config);

/// <summary>
/// Gets a PackageFile from the filepath
/// </summary>
Expand Down

0 comments on commit 40b4437

Please sign in to comment.