From 4f3454295d332f4b41ad84224d0e5b5dc6e20eb8 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 17 Sep 2015 22:08:45 -0500 Subject: [PATCH 1/3] (maint) formatting --- .../services/FilesServiceSpecs.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs index 6f555332a5..b5cc3278df 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs @@ -1,4 +1,19 @@ -namespace chocolatey.tests.integration.infrastructure.app.services +// Copyright © 2011 - Present RealDimensions Software, LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace chocolatey.tests.integration.infrastructure.app.services { using System; using System.IO; @@ -9,7 +24,6 @@ using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.domain; using chocolatey.infrastructure.app.services; - using chocolatey.infrastructure.commands; using chocolatey.infrastructure.cryptography; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.results; @@ -89,4 +103,4 @@ public void should_return_a_special_code_for_locked_files() } } } -} \ No newline at end of file +} From 4fa636255a786a9828abc430af81c1ae7e8f2a8d Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 17 Sep 2015 22:09:13 -0500 Subject: [PATCH 2/3] (resharper) line breaks at 195 characters --- src/chocolatey.sln.DotSettings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chocolatey.sln.DotSettings b/src/chocolatey.sln.DotSettings index 7b2230c3a1..1c48d3f556 100644 --- a/src/chocolatey.sln.DotSettings +++ b/src/chocolatey.sln.DotSettings @@ -6,7 +6,7 @@ <?xml version="1.0" encoding="utf-16"?><Profile name="sensible"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSUseVar><BehavourStyle>CAN_CHANGE_TO_IMPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>ALWAYS_EXPLICIT</ForeachVariableStyle></CSUseVar><CSharpFormatDocComments>True</CSharpFormatDocComments><CSUpdateFileHeader>True</CSUpdateFileHeader></Profile> sensible False - 220 + 195 False True Copyright © 2011 - Present RealDimensions Software, LLC From d5dd42f127b043d725ad30ee1c13060d4c5db4de Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 17 Sep 2015 22:10:46 -0500 Subject: [PATCH 3/3] (GH-364) Only update the config if changed Do not try to write to the config file unless something has changed. --- .../infrastructure.app/services/FilesServiceSpecs.cs | 4 +++- src/chocolatey/infrastructure/services/XmlService.cs | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs index b5cc3278df..18af879850 100644 --- a/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs +++ b/src/chocolatey.tests.integration/infrastructure.app/services/FilesServiceSpecs.cs @@ -35,10 +35,12 @@ public abstract class FilesServiceSpecsBase : TinySpec { protected FilesService Service; protected IFileSystem FileSystem = new DotNetFileSystem(); + protected IHashProvider HashProvider; public override void Context() { - Service = new FilesService(new XmlService(FileSystem), FileSystem, new CrytpoHashProvider(FileSystem, CryptoHashProviderType.Md5)); + HashProvider = new CrytpoHashProvider(FileSystem, CryptoHashProviderType.Md5); + Service = new FilesService(new XmlService(FileSystem, HashProvider), FileSystem, new CrytpoHashProvider(FileSystem, CryptoHashProviderType.Md5)); } } diff --git a/src/chocolatey/infrastructure/services/XmlService.cs b/src/chocolatey/infrastructure/services/XmlService.cs index 18bcd8d577..c56f0297e6 100644 --- a/src/chocolatey/infrastructure/services/XmlService.cs +++ b/src/chocolatey/infrastructure/services/XmlService.cs @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.services using System.Text; using System.Xml; using System.Xml.Serialization; + using cryptography; using filesystem; using tolerance; @@ -28,10 +29,12 @@ namespace chocolatey.infrastructure.services public sealed class XmlService : IXmlService { private readonly IFileSystem _fileSystem; + private readonly IHashProvider _hashProvider; - public XmlService(IFileSystem fileSystem) + public XmlService(IFileSystem fileSystem, IHashProvider hashProvider) { _fileSystem = fileSystem; + _hashProvider = hashProvider; } public XmlType deserialize(string xmlFilePath) @@ -74,7 +77,11 @@ public void serialize(XmlType xmlType, string xmlFilePath) textWriter.Close(); textWriter.Dispose(); - _fileSystem.copy_file(xmlUpdateFilePath, xmlFilePath, overwriteExisting: true); + if (!_hashProvider.hash_file(xmlFilePath).is_equal_to(_hashProvider.hash_file(xmlUpdateFilePath))) + { + _fileSystem.copy_file(xmlUpdateFilePath, xmlFilePath, overwriteExisting: true); + } + _fileSystem.delete_file(xmlUpdateFilePath); }, "Error serializing type {0}".format_with(typeof(XmlType)),