Skip to content

Commit 19cdf4b

Browse files
committed
Merge branch 'stable'
* 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
2 parents ab07573 + a19831f commit 19cdf4b

12 files changed

+250
-64
lines changed

src/chocolatey.console/chocolatey.console.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<ApplicationManifest>app.manifest</ApplicationManifest>
7979
</PropertyGroup>
8080
<ItemGroup>
81+
<Reference Include="AlphaFS, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4d31a58f7d7ad5c9, processorArchitecture=MSIL">
82+
<HintPath>..\packages\AlphaFS.2.0.1\lib\net40\AlphaFS.dll</HintPath>
83+
</Reference>
8184
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
8285
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
8386
</Reference>
@@ -101,6 +104,7 @@
101104
<HintPath>..\..\lib\PowerShell\System.Management.Automation.dll</HintPath>
102105
</Reference>
103106
<Reference Include="System.Security" />
107+
<Reference Include="System.Transactions" />
104108
<Reference Include="System.Xml" />
105109
<Reference Include="System.Xml.Linq" />
106110
</ItemGroup>

src/chocolatey.console/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<packages>
4+
<package id="AlphaFS" version="2.0.1" targetFramework="net40" />
45
<package id="log4net" version="2.0.3" targetFramework="net40" />
56
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net40" />
67
<package id="Nuget.Core" version="2.8.2" targetFramework="net40" />

src/chocolatey/chocolatey.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<ApplicationIcon>..\..\docs\logo\chocolatey.ico</ApplicationIcon>
3939
</PropertyGroup>
4040
<ItemGroup>
41+
<Reference Include="AlphaFS">
42+
<HintPath>..\packages\AlphaFS.2.0.1\lib\net40\AlphaFS.dll</HintPath>
43+
</Reference>
4144
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
4245
<HintPath>..\packages\log4net.2.0.3\lib\net40-client\log4net.dll</HintPath>
4346
</Reference>
@@ -73,6 +76,7 @@
7376
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net40\System.Reactive.Linq.dll</HintPath>
7477
</Reference>
7578
<Reference Include="System.Security" />
79+
<Reference Include="System.Transactions" />
7680
<Reference Include="System.Xml.Linq" />
7781
<Reference Include="Microsoft.CSharp" />
7882
<Reference Include="System.Xml" />

src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
6262
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
6363
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
6464
option => configuration.PackageParameters = option.remove_surrounding_quotes())
65-
.Add("apply-install-arguments-to-dependencies",
65+
.Add("argsglobal|args-global|installargsglobal|install-args-global|applyargstodependencies|apply-args-to-dependencies|apply-install-arguments-to-dependencies",
6666
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
6767
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
68-
.Add("apply-package-parameters-to-dependencies",
68+
.Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies",
6969
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
7070
option => configuration.ApplyPackageParametersToDependencies = option != null)
7171
.Add("allowdowngrade|allow-downgrade",

src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
5858
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
5959
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
6060
option => configuration.PackageParameters = option.remove_surrounding_quotes())
61-
.Add("apply-install-arguments-to-dependencies",
61+
.Add("argsglobal|args-global|installargsglobal|install-args-global|applyargstodependencies|apply-args-to-dependencies|apply-install-arguments-to-dependencies",
6262
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
6363
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
64-
.Add("apply-package-parameters-to-dependencies",
64+
.Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies",
6565
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
6666
option => configuration.ApplyPackageParametersToDependencies = option != null)
6767
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",

src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
6363
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
6464
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
6565
option => configuration.PackageParameters = option.remove_surrounding_quotes())
66-
.Add("apply-install-arguments-to-dependencies",
66+
.Add("argsglobal|args-global|installargsglobal|install-args-global|applyargstodependencies|apply-args-to-dependencies|apply-install-arguments-to-dependencies",
6767
"Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false.",
6868
option => configuration.ApplyInstallArgumentsToDependencies = option != null)
69-
.Add("apply-package-parameters-to-dependencies",
69+
.Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies",
7070
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
7171
option => configuration.ApplyPackageParametersToDependencies = option != null)
7272
.Add("allowdowngrade|allow-downgrade",

src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs

+12
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class ChocolateyPackageService : IChocolateyPackageService
5050
private readonly IAutomaticUninstallerService _autoUninstallerService;
5151
private readonly IXmlService _xmlService;
5252
private readonly IConfigTransformService _configTransformService;
53+
private readonly IDictionary<string, FileStream> _pendingLocks = new Dictionary<string, FileStream>();
54+
5355
private readonly IList<string> _proBusinessMessages = new List<string> {
5456
@"
5557
Are you ready for the ultimate experience? Check out Pro / Business!
@@ -1158,6 +1160,7 @@ public void set_pending(PackageResult packageResult, ChocolateyConfiguration con
11581160

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

11631166
public void remove_pending(PackageResult packageResult, ChocolateyConfiguration config)
@@ -1177,6 +1180,15 @@ public void remove_pending(PackageResult packageResult, ChocolateyConfiguration
11771180
}
11781181

11791182
var pendingFile = _fileSystem.combine_paths(packageDirectory, ApplicationParameters.PackagePendingFileName);
1183+
var lockName = packageResult.Name.to_lower();
1184+
if (_pendingLocks.ContainsKey(lockName))
1185+
{
1186+
var fileLock = _pendingLocks[lockName];
1187+
_pendingLocks.Remove(lockName);
1188+
fileLock.Close();
1189+
fileLock.Dispose();
1190+
}
1191+
11801192
if (_fileSystem.file_exists(pendingFile)) _fileSystem.delete_file(pendingFile);
11811193
}
11821194

src/chocolatey/infrastructure.app/services/FilesService.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace chocolatey.infrastructure.app.services
1717
{
1818
using System;
1919
using System.IO;
20+
using System.Linq;
2021
using configuration;
2122
using cryptography;
2223
using domain;
@@ -117,7 +118,7 @@ public PackageFiles capture_package_files(string directory, ChocolateyConfigurat
117118
this.Log().Debug(() => "Capturing package files in '{0}'".format_with(directory));
118119
//gather all files in the folder
119120
var files = _fileSystem.get_files(directory, pattern: "*.*", option: SearchOption.AllDirectories);
120-
foreach (string file in files.or_empty_list_if_null())
121+
foreach (string file in files.or_empty_list_if_null().Where(f => !f.EndsWith(ApplicationParameters.PackagePendingFileName)))
121122
{
122123
packageFiles.Files.Add(get_package_file(file));
123124
}

src/chocolatey/infrastructure.app/tasks/RemovePendingPackagesTask.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void handle_message(PreRunMessage message)
6363
foreach (var pendingFile in pendingFiles.or_empty_list_if_null())
6464
{
6565
var packageFolder = _fileSystem.get_directory_name(pendingFile);
66-
var packageFolderName = _fileSystem.get_directory_info_for(packageFolder).Name;
66+
string packageFolderName = _fileSystem.get_directory_info_for(packageFolder).Name;
6767

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

75+
try
76+
{
77+
//attempt to open the pending file. If it is locked, continue
78+
var file = _fileSystem.open_file_exclusive(pendingFile);
79+
file.Close();
80+
file.Dispose();
81+
}
82+
catch (Exception)
83+
{
84+
this.Log().Debug("Pending file found for {0}, but the file is locked by another process.".format_with(packageFolderName));
85+
continue;
86+
}
87+
7588
// wait for the file to be at least x seconds old
7689
// this allows commands running from the package for configuring sources, etc
7790
var fileInfo = _fileSystem.get_file_info_for(pendingFile);

0 commit comments

Comments
 (0)