Skip to content

Commit ec9f42e

Browse files
committed
Merge branch 'master' into merge-2.1.1-release
* master: (build) Switch to a PowerShell step (maint) synced local '.templates/' with remote '.github/GitReleaseManager/.templates/' (build) Bump Recipe package to latest version (maint) Remove unnecessary whitespace (#996) Create config directory if it doesn't exist (maint) Remove unused pragmas (#967) Parse Info for Error, Warn, and Fatal (maint) Remove mention of services no longer used (tests) Update Pester tests to be consistent (tests) Move the Pester tests to be consistent (maint) synced local '.templates/' with remote '.github/GitReleaseManager/.templates/' (maint) Update GRM configuration
2 parents 652e49b + 88cb4f2 commit ec9f42e

File tree

5 files changed

+65
-10
lines changed

5 files changed

+65
-10
lines changed

.templates/default/release-info.sbn

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{{
22
if issues.count > 0
33
if commits.count > 0
4-
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}) which resulted in [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) being closed.
4+
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}) which resulted in [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?{{ milestone.query_string }}) being closed.
55
{{ else
6-
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) closed.
6+
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?{{ milestone.query_string }}) closed.
77
{{ end
88
else if commits.count > 0
99
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}).

Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public class ChocolateyService : IChocolateyService
4747
private readonly IConfigService _configService;
4848
private GetChocolatey _choco;
4949
private string _localAppDataPath = string.Empty;
50-
#pragma warning disable SA1401 // Fields must be private
51-
#pragma warning restore SA1401 // Fields must be private
50+
private const string ErrorRegex = "^\\s*(ERROR|FATAL|WARN)";
5251

5352
public ChocolateyService(IMapper mapper, IProgressService progressService, IChocolateyConfigSettingsService configSettingsService, IXmlService xmlService, IFileSystem fileSystem, IConfigService configService)
5453
{
@@ -677,6 +676,13 @@ private static List<string> GetErrors(out Action<LogMessage> grabErrors)
677676
case LogLevel.Error:
678677
case LogLevel.Fatal:
679678
errors.Add(m.Message);
679+
break;
680+
case LogLevel.Info:
681+
if (System.Text.RegularExpressions.Regex.IsMatch(m.Message, ErrorRegex))
682+
{
683+
errors.Add(m.Message);
684+
}
685+
680686
break;
681687
}
682688
};

Source/ChocolateyGui.Common.Windows/Startup/ChocolateyGuiModule.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,22 @@ protected override void Load(ContainerBuilder builder)
148148
var userDatabase = new LiteDatabase($"filename={Path.Combine(Bootstrapper.LocalAppDataPath, "data.db")};upgrade=true");
149149

150150
LiteDatabase globalDatabase;
151+
var globalConfigDirectory = Path.Combine(Bootstrapper.AppDataPath, "Config");
152+
var globalConfigDatabaseFile = Path.Combine(globalConfigDirectory, "data.db");
153+
151154
if (Hacks.IsElevated)
152155
{
153-
globalDatabase = new LiteDatabase($"filename={Path.Combine(Bootstrapper.AppDataPath, "Config", "data.db")};upgrade=true");
156+
if (!Directory.Exists(globalConfigDirectory))
157+
{
158+
Directory.CreateDirectory(globalConfigDirectory);
159+
Hacks.LockDirectory(globalConfigDirectory);
160+
}
161+
162+
globalDatabase = new LiteDatabase($"filename={globalConfigDatabaseFile};upgrade=true");
154163
}
155164
else
156165
{
157-
if (!File.Exists(Path.Combine(Bootstrapper.AppDataPath, "Config", "data.db")))
166+
if (!File.Exists(globalConfigDatabaseFile))
158167
{
159168
// Since the global configuration database file doesn't exist, we must be running in a state where an administrator user
160169
// has never run Chocolatey GUI. In this case, use null, which will mean attempts to use the global database will be ignored.
@@ -163,7 +172,7 @@ protected override void Load(ContainerBuilder builder)
163172
else
164173
{
165174
// Since this is a non-administrator user, they should only have read permissions to this database
166-
globalDatabase = new LiteDatabase($"filename={Path.Combine(Bootstrapper.AppDataPath, "Config", "data.db")};readonly=true");
175+
globalDatabase = new LiteDatabase($"filename={globalConfigDatabaseFile};readonly=true");
167176
}
168177
}
169178

Source/ChocolateyGui.Common/Hacks.cs

+31
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,43 @@
55
// </copyright>
66
// --------------------------------------------------------------------------------------------------------------------
77

8+
using System;
9+
using System.IO;
10+
using System.Security.AccessControl;
811
using System.Security.Principal;
912

1013
namespace ChocolateyGui.Common
1114
{
1215
public static class Hacks
1316
{
1417
public static bool IsElevated => (WindowsIdentity.GetCurrent().Owner?.IsWellKnown(WellKnownSidType.BuiltinAdministratorsSid)).GetValueOrDefault(false);
18+
19+
// TODO: Replace this LockDirectory with calls to DotNetFileSystem's LockDirectory when https://github.com/chocolatey/ChocolateyGUI/issues/1046 is completed.
20+
/// <summary>
21+
/// Lock the given directory path to just Administrators being able to write. This method is copied from chocolatey.infrastructure.filesystem.DotNetFileSystem, and should be replaced with that call when the minimum Chocolatey.lib is bumped to 2.2.0 or greater.
22+
/// </summary>
23+
/// <param name="directoryPath">Directory path to lock down.</param>
24+
public static void LockDirectory(string directoryPath)
25+
{
26+
var permissions = Directory.GetAccessControl(directoryPath);
27+
var rules = permissions.GetAccessRules(includeExplicit: true, includeInherited: true, targetType: typeof(NTAccount));
28+
29+
// We first need to remove all rules
30+
foreach (FileSystemAccessRule rule in rules)
31+
{
32+
permissions.RemoveAccessRuleAll(rule);
33+
}
34+
35+
var bultinAdmins = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null).Translate(typeof(NTAccount));
36+
var localsystem = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null).Translate(typeof(NTAccount));
37+
var builtinUsers = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null).Translate(typeof(NTAccount));
38+
var inheritanceFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
39+
permissions.SetAccessRule(new FileSystemAccessRule(bultinAdmins, FileSystemRights.FullControl, inheritanceFlags, PropagationFlags.None, AccessControlType.Allow));
40+
permissions.SetAccessRule(new FileSystemAccessRule(localsystem, FileSystemRights.FullControl, inheritanceFlags, PropagationFlags.None, AccessControlType.Allow));
41+
permissions.SetAccessRule(new FileSystemAccessRule(builtinUsers, FileSystemRights.ReadAndExecute, inheritanceFlags, PropagationFlags.None, AccessControlType.Allow));
42+
permissions.SetOwner(bultinAdmins);
43+
permissions.SetAccessRuleProtection(isProtected: true, preserveInheritance: false);
44+
Directory.SetAccessControl(directoryPath, permissions);
45+
}
1546
}
1647
}

Source/ChocolateyGuiCli/Startup/ChocolateyGuiCliModule.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,22 @@ protected override void Load(ContainerBuilder builder)
4848
var userDatabase = new LiteDatabase($"filename={Path.Combine(Bootstrapper.LocalAppDataPath, "data.db")};upgrade=true");
4949

5050
LiteDatabase globalDatabase;
51+
var globalConfigDirectory = Path.Combine(Bootstrapper.AppDataPath, "Config");
52+
var globalConfigDatabaseFile = Path.Combine(globalConfigDirectory, "data.db");
53+
5154
if (Hacks.IsElevated)
5255
{
53-
globalDatabase = new LiteDatabase($"filename={Path.Combine(Bootstrapper.AppDataPath, "Config", "data.db")};upgrade=true");
56+
if (!Directory.Exists(globalConfigDirectory))
57+
{
58+
Directory.CreateDirectory(globalConfigDirectory);
59+
Hacks.LockDirectory(globalConfigDirectory);
60+
}
61+
62+
globalDatabase = new LiteDatabase($"filename={globalConfigDatabaseFile};upgrade=true");
5463
}
5564
else
5665
{
57-
if (!File.Exists(Path.Combine(Bootstrapper.AppDataPath, "Config", "data.db")))
66+
if (!File.Exists(globalConfigDatabaseFile))
5867
{
5968
// Since the global configuration database file doesn't exist, we must be running in a state where an administrator user
6069
// has never run Chocolatey GUI. In this case, use null, which will mean attempts to use the global database will be ignored.
@@ -63,7 +72,7 @@ protected override void Load(ContainerBuilder builder)
6372
else
6473
{
6574
// Since this is a non-administrator user, they should only have read permissions to this database
66-
globalDatabase = new LiteDatabase($"filename={Path.Combine(Bootstrapper.AppDataPath, "Config", "data.db")};readonly=true");
75+
globalDatabase = new LiteDatabase($"filename={globalConfigDatabaseFile};readonly=true");
6776
}
6877
}
6978

0 commit comments

Comments
 (0)