Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (GH-934) Support Paths > 260 Characters
  (GH-943) Skip Locked Pending Files
  (GH-943) Lock Pending File Until Operation Completes
  (GH-943) IFileSystem - Open File Exclusively
  (GH-839) More switch names for dependency apply
  • Loading branch information
ferventcoder committed Sep 17, 2016
2 parents ab07573 + a19831f commit 19cdf4b
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 64 deletions.
4 changes: 4 additions & 0 deletions src/chocolatey.console/chocolatey.console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="AlphaFS, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4d31a58f7d7ad5c9, processorArchitecture=MSIL">
<HintPath>..\packages\AlphaFS.2.0.1\lib\net40\AlphaFS.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
</Reference>
Expand All @@ -101,6 +104,7 @@
<HintPath>..\..\lib\PowerShell\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey.console/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="AlphaFS" version="2.0.1" targetFramework="net40" />
<package id="log4net" version="2.0.3" targetFramework="net40" />
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net40" />
<package id="Nuget.Core" version="2.8.2" targetFramework="net40" />
Expand Down
4 changes: 4 additions & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<ApplicationIcon>..\..\docs\logo\chocolatey.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="AlphaFS">
<HintPath>..\packages\AlphaFS.2.0.1\lib\net40\AlphaFS.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -73,6 +76,7 @@
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net40\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("apply-install-arguments-to-dependencies",
.Add("argsglobal|args-global|installargsglobal|install-args-global|applyargstodependencies|apply-args-to-dependencies|apply-install-arguments-to-dependencies",
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
.Add("apply-package-parameters-to-dependencies",
.Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies",
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = option != null)
.Add("allowdowngrade|allow-downgrade",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("apply-install-arguments-to-dependencies",
.Add("argsglobal|args-global|installargsglobal|install-args-global|applyargstodependencies|apply-args-to-dependencies|apply-install-arguments-to-dependencies",
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
.Add("apply-package-parameters-to-dependencies",
.Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies",
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = option != null)
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("apply-install-arguments-to-dependencies",
.Add("argsglobal|args-global|installargsglobal|install-args-global|applyargstodependencies|apply-args-to-dependencies|apply-install-arguments-to-dependencies",
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
.Add("apply-package-parameters-to-dependencies",
.Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies",
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = option != null)
.Add("allowdowngrade|allow-downgrade",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class ChocolateyPackageService : IChocolateyPackageService
private readonly IAutomaticUninstallerService _autoUninstallerService;
private readonly IXmlService _xmlService;
private readonly IConfigTransformService _configTransformService;
private readonly IDictionary<string, FileStream> _pendingLocks = new Dictionary<string, FileStream>();

private readonly IList<string> _proBusinessMessages = new List<string> {
@"
Are you ready for the ultimate experience? Check out Pro / Business!
Expand Down Expand Up @@ -1158,6 +1160,7 @@ public void set_pending(PackageResult packageResult, ChocolateyConfiguration con

var pendingFile = _fileSystem.combine_paths(packageDirectory, ApplicationParameters.PackagePendingFileName);
_fileSystem.write_file(pendingFile, "{0}".format_with(packageResult.Name));
_pendingLocks.Add(packageResult.Name.to_lower(), _fileSystem.open_file_exclusive(pendingFile));
}

public void remove_pending(PackageResult packageResult, ChocolateyConfiguration config)
Expand All @@ -1177,6 +1180,15 @@ public void remove_pending(PackageResult packageResult, ChocolateyConfiguration
}

var pendingFile = _fileSystem.combine_paths(packageDirectory, ApplicationParameters.PackagePendingFileName);
var lockName = packageResult.Name.to_lower();
if (_pendingLocks.ContainsKey(lockName))
{
var fileLock = _pendingLocks[lockName];
_pendingLocks.Remove(lockName);
fileLock.Close();
fileLock.Dispose();
}

if (_fileSystem.file_exists(pendingFile)) _fileSystem.delete_file(pendingFile);
}

Expand Down
3 changes: 2 additions & 1 deletion src/chocolatey/infrastructure.app/services/FilesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace chocolatey.infrastructure.app.services
{
using System;
using System.IO;
using System.Linq;
using configuration;
using cryptography;
using domain;
Expand Down Expand Up @@ -117,7 +118,7 @@ public PackageFiles capture_package_files(string directory, ChocolateyConfigurat
this.Log().Debug(() => "Capturing package files in '{0}'".format_with(directory));
//gather all files in the folder
var files = _fileSystem.get_files(directory, pattern: "*.*", option: SearchOption.AllDirectories);
foreach (string file in files.or_empty_list_if_null())
foreach (string file in files.or_empty_list_if_null().Where(f => !f.EndsWith(ApplicationParameters.PackagePendingFileName)))
{
packageFiles.Files.Add(get_package_file(file));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void handle_message(PreRunMessage message)
foreach (var pendingFile in pendingFiles.or_empty_list_if_null())
{
var packageFolder = _fileSystem.get_directory_name(pendingFile);
var packageFolderName = _fileSystem.get_directory_info_for(packageFolder).Name;
string packageFolderName = _fileSystem.get_directory_info_for(packageFolder).Name;

var pendingSkipFiles = _fileSystem.get_files(packageFolder, PENDING_SKIP_FILE, SearchOption.AllDirectories).ToList();
if (pendingSkipFiles.Count != 0)
Expand All @@ -72,6 +72,19 @@ private void handle_message(PreRunMessage message)
continue;
}

try
{
//attempt to open the pending file. If it is locked, continue
var file = _fileSystem.open_file_exclusive(pendingFile);
file.Close();
file.Dispose();
}
catch (Exception)
{
this.Log().Debug("Pending file found for {0}, but the file is locked by another process.".format_with(packageFolderName));
continue;
}

// wait for the file to be at least x seconds old
// this allows commands running from the package for configuring sources, etc
var fileInfo = _fileSystem.get_file_info_for(pendingFile);
Expand Down
Loading

0 comments on commit 19cdf4b

Please sign in to comment.