Skip to content

Commit

Permalink
(GH-588) Manage extensions installed w/old method
Browse files Browse the repository at this point in the history
Look for and be able to upgrade/uninstall extensions that were
installed prior to 0.9.10 code, which removes the word ".extension"
from the extension folder name and only copies in the extensions folder
instead of the whole package.
  • Loading branch information
ferventcoder committed May 5, 2016
1 parent 01db65b commit 5c52830
Showing 1 changed file with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -824,56 +824,24 @@ private void handle_extension_packages(ChocolateyConfiguration config, PackageRe

_fileSystem.create_directory_if_not_exists(ApplicationParameters.ExtensionsLocation);
var extensionsFolderName = packageResult.Name.to_lower().Replace(".extensions", string.Empty).Replace(".extension", string.Empty);
var pkgExtensions = _fileSystem.combine_paths(ApplicationParameters.ExtensionsLocation, extensionsFolderName);
var packageExtensionsInstallDirectory = _fileSystem.combine_paths(ApplicationParameters.ExtensionsLocation, extensionsFolderName);

if (_fileSystem.directory_exists(pkgExtensions))
{
// remove old dll files files
foreach (var oldDllFile in _fileSystem.get_files(pkgExtensions, "*.dll.old", SearchOption.AllDirectories).or_empty_list_if_null())
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.delete_file(oldDllFile),
"Attempted to remove '{0}' but had an error".format_with(oldDllFile),
throwError: false,
logWarningInsteadOfError: true);
}

// rename possibly locked dll files
foreach (var dllFile in _fileSystem.get_files(pkgExtensions, "*.dll", SearchOption.AllDirectories).or_empty_list_if_null())
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.move_file(dllFile, dllFile + ".old"),
"Attempted to rename '{0}' but had an error".format_with(dllFile));
}

FaultTolerance.try_catch_with_logging_exception(
() =>
{
foreach (var file in _fileSystem.get_files(pkgExtensions, "*.*", SearchOption.AllDirectories).or_empty_list_if_null().Where(f => !f.EndsWith(".dll.old")))
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.delete_file(file),
"Attempted to remove '{0}' but had an error".format_with(file),
throwError: false,
logWarningInsteadOfError: true);
}
},
"Attempted to remove '{0}' but had an error".format_with(pkgExtensions),
throwError: false,
logWarningInsteadOfError: true);
}
remove_extension_folder(packageExtensionsInstallDirectory);
// don't name your package *.extension.extension
remove_extension_folder(packageExtensionsInstallDirectory + ".extension");
remove_extension_folder(packageExtensionsInstallDirectory + ".extensions");

if (!config.CommandName.is_equal_to(CommandNameType.uninstall.to_string()))
{
if (packageResult.InstallLocation == null) return;

_fileSystem.create_directory_if_not_exists(pkgExtensions);
_fileSystem.create_directory_if_not_exists(packageExtensionsInstallDirectory);
var extensionsFolder = _fileSystem.combine_paths(packageResult.InstallLocation, "extensions");
var extensionFolderToCopy = _fileSystem.directory_exists(extensionsFolder) ? extensionsFolder : packageResult.InstallLocation;

FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.copy_directory(extensionFolderToCopy, pkgExtensions, overwriteExisting: true),
"Attempted to copy{0} '{1}'{0} to '{2}'{0} but had an error".format_with(Environment.NewLine, extensionFolderToCopy, pkgExtensions));
() => _fileSystem.copy_directory(extensionFolderToCopy, packageExtensionsInstallDirectory, overwriteExisting: true),
"Attempted to copy{0} '{1}'{0} to '{2}'{0} but had an error".format_with(Environment.NewLine, extensionFolderToCopy, packageExtensionsInstallDirectory));

string logMessage = " Installed/updated {0} extensions.".format_with(extensionsFolderName);
this.Log().Warn(logMessage);
Expand All @@ -887,6 +855,46 @@ private void handle_extension_packages(ChocolateyConfiguration config, PackageRe
}
}

private void remove_extension_folder(string packageExtensionsDirectory)
{
if (!_fileSystem.directory_exists(packageExtensionsDirectory)) return;

// remove old dll files files
foreach (var oldDllFile in _fileSystem.get_files(packageExtensionsDirectory, "*.dll.old", SearchOption.AllDirectories).or_empty_list_if_null())
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.delete_file(oldDllFile),
"Attempted to remove '{0}' but had an error".format_with(oldDllFile),
throwError: false,
logWarningInsteadOfError: true);
}

// rename possibly locked dll files
foreach (var dllFile in _fileSystem.get_files(packageExtensionsDirectory, "*.dll", SearchOption.AllDirectories).or_empty_list_if_null())
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.move_file(dllFile, dllFile + ".old"),
"Attempted to rename '{0}' but had an error".format_with(dllFile));
}

FaultTolerance.try_catch_with_logging_exception(
() =>
{
foreach (var file in _fileSystem.get_files(packageExtensionsDirectory, "*.*", SearchOption.AllDirectories).or_empty_list_if_null().Where(f => !f.EndsWith(".dll.old")))
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.delete_file(file),
"Attempted to remove '{0}' but had an error".format_with(file),
throwError: false,
logWarningInsteadOfError: true);
}
},
"Attempted to remove '{0}' but had an error".format_with(packageExtensionsDirectory),
throwError: false,
logWarningInsteadOfError: true);

}

private void handle_template_packages(ChocolateyConfiguration config, PackageResult packageResult)
{
if (packageResult == null) return;
Expand Down

0 comments on commit 5c52830

Please sign in to comment.