forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNugetService.cs
More file actions
3181 lines (2685 loc) · 179 KB
/
Copy pathNugetService.cs
File metadata and controls
3181 lines (2685 loc) · 179 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright © 2017 - 2023 Chocolatey Software, Inc
// Copyright © 2011 - 2017 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.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using Chocolatey.NuGet.Frameworks;
using chocolatey.infrastructure.adapters;
using chocolatey.infrastructure.app.configuration;
using chocolatey.infrastructure.app.domain;
using chocolatey.infrastructure.app.nuget;
using chocolatey.infrastructure.app.utility;
using chocolatey.infrastructure.commandline;
using chocolatey.infrastructure.cryptography;
using chocolatey.infrastructure.guards;
using chocolatey.infrastructure.logging;
using chocolatey.infrastructure.platforms;
using chocolatey.infrastructure.results;
using chocolatey.infrastructure.services;
using chocolatey.infrastructure.tolerance;
using DateTime = chocolatey.infrastructure.adapters.DateTime;
using Environment = System.Environment;
using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.PackageManagement;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Protocol;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.Resolver;
using NuGet.Versioning;
namespace chocolatey.infrastructure.app.services
{
//todo: #2575 - this monolith is too large. Refactor once test coverage is up.
public class NugetService : INugetService
{
private readonly IFileSystem _fileSystem;
private readonly ILogger _nugetLogger;
private readonly IChocolateyPackageInformationService _packageInfoService;
private readonly IFilesService _filesService;
private readonly IRuleService _ruleService;
//private readonly PackageDownloader _packageDownloader;
private readonly Lazy<IDateTime> _datetime = new Lazy<IDateTime>(() => new DateTime());
private IDateTime DateTime
{
get { return _datetime.Value; }
}
internal const string InstallWithFilePathDeprecationMessage = @"
The ability to specify a direct path to a .nuspec or .nupkg file for installation
is deprecated and will be removed in v2.0.0. Instead of using the full path
to a .nupkg file, use the --source option to specify the containing directory,
and ensure any packages have been packed into a .nupkg file before attempting to
install them.
";
/// <summary>
/// Initializes a new instance of the <see cref="NugetService" /> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="nugetLogger">The nuget logger</param>
/// <param name="packageInfoService">Package information service</param>
/// <param name="filesService">The files service</param>
/// <param name="ruleService">The rule service</param>
public NugetService(
IFileSystem fileSystem,
ILogger nugetLogger,
IChocolateyPackageInformationService packageInfoService,
IFilesService filesService,
IRuleService ruleService)
{
_fileSystem = fileSystem;
_nugetLogger = nugetLogger;
_packageInfoService = packageInfoService;
_filesService = filesService;
_ruleService = ruleService;
}
public string SourceType
{
get { return SourceTypes.Normal; }
}
public void EnsureSourceAppInstalled(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> ensureAction)
{
// nothing to do. Nuget.Core is already part of Chocolatey
}
public virtual int Count(ChocolateyConfiguration config)
{
if (config.ListCommand.LocalOnly)
{
config.Sources = ApplicationParameters.PackagesLocation;
config.Prerelease = true;
if (!_fileSystem.DirectoryExists(ApplicationParameters.PackagesLocation))
{
return 0;
}
}
var pageValue = config.ListCommand.Page;
try
{
var sourceCacheContext = new ChocolateySourceCacheContext(config);
return NugetList.GetCount(config, _nugetLogger, _fileSystem, sourceCacheContext);
}
finally
{
config.ListCommand.Page = pageValue;
}
}
public virtual void ListDryRun(ChocolateyConfiguration config)
{
this.Log().Info("{0} would have searched for '{1}' against the following source(s) :\"{2}\"".FormatWith(
ApplicationParameters.Name,
config.Input,
config.Sources
));
}
public virtual IEnumerable<PackageResult> List(ChocolateyConfiguration config)
{
var count = 0;
var sources = config.Sources;
var prerelease = config.Prerelease;
var includeVersionOverrides = config.ListCommand.IncludeVersionOverrides;
if (config.ListCommand.LocalOnly)
{
config.Sources = ApplicationParameters.PackagesLocation;
config.Prerelease = true;
config.ListCommand.IncludeVersionOverrides = true;
if (!_fileSystem.DirectoryExists(ApplicationParameters.PackagesLocation))
{
yield break;
}
}
if ((config.ListCommand.ApprovedOnly || config.ListCommand.DownloadCacheAvailable || config.ListCommand.NotBroken) && config.RegularOutput)
{
// This warning has been added here, to provide context to the user, and a follow up issue
// has been added here: https://github.com/chocolatey/choco/issues/3139 to address the actual
// issue that causes this warning to be required.
this.Log().Warn(@"
Starting vith Chocolatey CLI v2.0.0, changes have been made to the
`choco search` command which means that filtering of packages using the
`--approved-only`, `--download-cache`, and `--not-broken` options are
now performed within Chocolatey CLI. Previously, this filtering would
have been performed on the Chocolatey Community Repository. As a result,
it is possible that incomplete package lists are returned from a command
that uses these options.");
}
if (config.RegularOutput)
{
this.Log().Debug(() => "Running list with the following filter = '{0}'".FormatWith(config.Input));
}
if (config.RegularOutput)
{
this.Log().Debug(ChocolateyLoggers.Verbose, () => "--- Start of List ---");
}
foreach (var pkg in NugetList.GetPackages(config, _nugetLogger, _fileSystem))
{
var package = pkg; // for lamda access
string packageArgumentsUnencrypted = null;
ChocolateyPackageMetadata packageLocalMetadata;
string packageInstallLocation = null;
string deploymentLocation = null;
if (package.PackagePath != null && !string.IsNullOrWhiteSpace(package.PackagePath))
{
packageLocalMetadata = new ChocolateyPackageMetadata(package.PackagePath, _fileSystem);
packageInstallLocation = _fileSystem.GetDirectoryName(package.PackagePath);
}
else
{
packageLocalMetadata = null;
}
if (config.ListCommand.LocalOnly && packageLocalMetadata != null)
{
var packageInfo = _packageInfoService.Get(packageLocalMetadata);
if (config.ListCommand.IncludeVersionOverrides)
{
if (packageInfo.VersionOverride != null)
{
packageLocalMetadata.OverrideOriginalVersion(packageInfo.VersionOverride);
}
}
deploymentLocation = packageInfo.DeploymentLocation;
if (!string.IsNullOrWhiteSpace(packageInfo.Arguments))
{
var decryptedArguments = ArgumentsUtility.DecryptPackageArgumentsFile(_fileSystem, packageInfo.Package.Id, packageInfo.Package.Version.ToNormalizedStringChecked());
packageArgumentsUnencrypted = "\n Remembered Package Arguments: \n {0}".FormatWith(string.Join(Environment.NewLine + " ", decryptedArguments));
}
}
if (!config.QuietOutput)
{
var logger = config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal;
if (config.RegularOutput)
{
this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}{1}{2}{3}".FormatWith(
packageLocalMetadata != null ? packageLocalMetadata.Version.ToFullStringChecked() : package.Identity.Version.ToFullStringChecked(),
package.IsApproved ? " [Approved]" : string.Empty,
package.IsDownloadCacheAvailable ? " Downloads cached for licensed users" : string.Empty,
package.PackageTestResultStatus == "Failing" && package.IsDownloadCacheAvailable ? " - Possibly broken for FOSS users (due to original download location changes by vendor)" : package.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty
))
);
if (config.Verbose && !config.ListCommand.IdOnly)
{
this.Log().Info(() =>
@" Title: {0} | Published: {1}{2}{3}
Number of Downloads: {4} | Downloads for this version: {5}
Package url{6}
Chocolatey Package Source: {7}{8}
Tags: {9}
Software Site: {10}
Software License: {11}{12}{13}{14}{15}{16}
Description: {17}{18}{19}{20}
".FormatWith(
package.Title.EscapeCurlyBraces(),
package.Published.GetValueOrDefault().UtcDateTime.ToShortDateString(),
package.IsApproved ? "{0} Package approved {1} on {2}.".FormatWith(
Environment.NewLine,
string.IsNullOrWhiteSpace(package.PackageReviewer) ? "as a trusted package" : "by " + package.PackageReviewer,
package.PackageApprovedDate.GetValueOrDefault().ToString("MMM dd yyyy HH:mm:ss")
) : string.Empty,
string.IsNullOrWhiteSpace(package.PackageTestResultStatus) || package.PackageTestResultStatus.IsEqualTo("unknown") ? string.Empty : "{0} Package testing status: {1} on {2}.".FormatWith(
Environment.NewLine,
package.PackageTestResultStatus,
package.PackageValidationResultDate.GetValueOrDefault().ToString("MMM dd yyyy HH:mm:ss")
),
(package.DownloadCount == null || package.DownloadCount <= 0) ? "n/a" : package.DownloadCount.ToStringSafe(),
(package.VersionDownloadCount == null || package.VersionDownloadCount <= 0) ? "n/a" : package.VersionDownloadCount.ToStringSafe(),
package.PackageDetailsUrl == null || string.IsNullOrWhiteSpace(package.PackageDetailsUrl.AbsoluteUri) ? string.Empty : " " + package.PackageDetailsUrl.AbsoluteUri,
!string.IsNullOrWhiteSpace(package.PackageSourceUrl.ToStringSafe())
? package.PackageSourceUrl.ToStringSafe()
: "n/a",
string.IsNullOrWhiteSpace(package.PackageHash) ? string.Empty : "{0} Package Checksum: '{1}' ({2})".FormatWith(
Environment.NewLine,
package.PackageHash,
package.PackageHashAlgorithm
),
package.Tags.TrimSafe().EscapeCurlyBraces(),
package.ProjectUrl != null ? package.ProjectUrl.ToStringSafe() : "n/a",
package.LicenseUrl != null && !string.IsNullOrWhiteSpace(package.LicenseUrl.ToStringSafe()) ? package.LicenseUrl.ToStringSafe() : "n/a",
!string.IsNullOrWhiteSpace(package.ProjectSourceUrl.ToStringSafe()) ? "{0} Software Source: {1}".FormatWith(Environment.NewLine, package.ProjectSourceUrl.ToStringSafe()) : string.Empty,
!string.IsNullOrWhiteSpace(package.DocsUrl.ToStringSafe()) ? "{0} Documentation: {1}".FormatWith(Environment.NewLine, package.DocsUrl.ToStringSafe()) : string.Empty,
!string.IsNullOrWhiteSpace(package.MailingListUrl.ToStringSafe()) ? "{0} Mailing List: {1}".FormatWith(Environment.NewLine, package.MailingListUrl.ToStringSafe()) : string.Empty,
!string.IsNullOrWhiteSpace(package.BugTrackerUrl.ToStringSafe()) ? "{0} Issues: {1}".FormatWith(Environment.NewLine, package.BugTrackerUrl.ToStringSafe()) : string.Empty,
package.Summary != null && !string.IsNullOrWhiteSpace(package.Summary.ToStringSafe()) ? "\r\n Summary: {0}".FormatWith(package.Summary.EscapeCurlyBraces().ToStringSafe()) : string.Empty,
package.Description.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n "),
!string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty,
!string.IsNullOrWhiteSpace(deploymentLocation) ? "{0} Deployed to: '{1}'".FormatWith(Environment.NewLine, deploymentLocation) : string.Empty,
packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty
));
}
}
else
{
this.Log().Info(logger, () => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : "|{0}".FormatWith(package.Identity.Version.ToFullStringChecked())));
}
}
else
{
this.Log().Debug(() => "{0}{1}".FormatWith(package.Identity.Id, config.ListCommand.IdOnly ? string.Empty : " {0}".FormatWith(package.Identity.Version.ToFullStringChecked())));
}
count++;
if (packageLocalMetadata is null)
{
yield return new PackageResult(package, null, config.Sources);
}
else
{
yield return new PackageResult(packageLocalMetadata, package, config.ListCommand.LocalOnly ? packageInstallLocation : null, config.Sources);
}
}
if (config.RegularOutput)
{
this.Log().Debug(ChocolateyLoggers.Verbose, () => "--- End of List ---");
}
if (config.RegularOutput && !config.QuietOutput)
{
this.Log().Warn(() => @"{0} packages {1}.".FormatWith(count, config.ListCommand.LocalOnly ? "installed" : "found"));
}
config.Sources = sources;
config.Prerelease = prerelease;
config.ListCommand.IncludeVersionOverrides = includeVersionOverrides;
if (!config.ListCommand.Page.HasValue && !config.ListCommand.LocalOnly)
{
var logType = config.RegularOutput ? ChocolateyLoggers.Important : ChocolateyLoggers.LogFileOnly;
if (NugetList.ThresholdHit)
{
this.Log().Warn(logType, "The threshold of {0:N0} packages per source has been met. Please refine your search, or specify a page to find any more results.".FormatWith(NugetList.LastPackageLimitUsed));
}
else if (NugetList.LowerThresholdHit)
{
this.Log().Warn(logType, "Over {0:N0} packages was found per source, there may be more packages available that was filtered out. Please refine your search, or specify a page to check for more packages.".FormatWith(NugetList.LastPackageLimitUsed * 0.9));
}
}
}
public void PackDryRun(ChocolateyConfiguration config)
{
this.Log().Info("{0} would have searched for a nuspec file in \"{1}\" and attempted to compile it.".FormatWith(
ApplicationParameters.Name,
config.OutputDirectory ?? _fileSystem.GetCurrentDirectory()
));
}
public virtual string GetPackageFileOrThrow(ChocolateyConfiguration config, string extension)
{
Func<IFileSystem, string> getLocalFiles = (fileSystem) =>
{
var filesFound = fileSystem.GetFiles(fileSystem.GetCurrentDirectory(), "*" + extension).ToList().OrEmpty();
Ensure.That(() => filesFound)
.Meets((files) => files.Count() == 1,
(name, value) => { throw new FileNotFoundException("No {0} files (or more than 1) were found to build in '{1}'. Please specify the {0} file or try in a different directory.".FormatWith(extension, _fileSystem.GetCurrentDirectory())); });
return filesFound.FirstOrDefault();
};
var filePath = !string.IsNullOrWhiteSpace(config.Input) ? config.Input : getLocalFiles.Invoke(_fileSystem);
Ensure.That(() => filePath).Meets((file) => _fileSystem.GetFileExtension(file).IsEqualTo(extension) && _fileSystem.FileExists(file),
(name, value) => { throw new ArgumentException("File specified is either not found or not a {0} file. '{1}'".FormatWith(extension, value)); });
return filePath;
}
public virtual void Pack(ChocolateyConfiguration config)
{
var nuspecFilePath = GetPackageFileOrThrow(config, PackagingConstants.ManifestExtension);
ValidateNuspec(nuspecFilePath, config);
var nuspecDirectory = _fileSystem.GetFullPath(_fileSystem.GetDirectoryName(nuspecFilePath));
if (string.IsNullOrWhiteSpace(nuspecDirectory))
{
nuspecDirectory = _fileSystem.GetCurrentDirectory();
}
// Use case-insensitive properties like "nuget pack".
var properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// Add any other properties passed to the pack command overriding any present.
foreach (var property in config.PackCommand.Properties)
{
this.Log().Debug(() => "Setting property '{0}': {1}".FormatWith(
property.Key,
property.Value));
properties[property.Key] = property.Value;
}
// Set the version property if the flag is set
if (!string.IsNullOrWhiteSpace(config.Version))
{
this.Log().Debug(() => "Setting property 'version': {0}".FormatWith(
config.Version));
properties["version"] = config.Version;
}
// Initialize the property provider based on what was passed in using the properties flag
var propertyProvider = new DictionaryPropertyProvider(properties);
//Allows empty directories to be distributed in templates via .template packages, issue #1003
var includeEmptyDirectories = true;
//No need to be deterministic, it's ok to include timestamps
var deterministic = false;
var builder = new PackageBuilder(nuspecFilePath, nuspecDirectory, propertyProvider.GetPropertyValue, includeEmptyDirectories, deterministic, _nugetLogger);
if (!string.IsNullOrWhiteSpace(config.Version))
{
builder.Version = new NuGetVersion(config.Version);
}
var outputFile = builder.Id + "." + builder.Version.ToNormalizedStringChecked() + NuGetConstants.PackageExtension;
var outputFolder = config.OutputDirectory ?? _fileSystem.GetCurrentDirectory();
var outputPath = _fileSystem.CombinePaths(outputFolder, outputFile);
config.Sources = outputFolder;
this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Normal, () => "Attempting to build package from '{0}'.".FormatWith(_fileSystem.GetFileName(nuspecFilePath)));
_fileSystem.EnsureDirectoryExists(outputFolder);
var createdPackage = NugetPack.BuildPackage(builder, _fileSystem, outputPath);
// package.Validate().Any(v => v.Level == PackageIssueLevel.Error)
if (!createdPackage)
{
throw new ApplicationException("Unable to create nupkg. See the log for error details.");
}
//todo: #602 analyze package
//if (package != null)
//{
// AnalyzePackage(package);
//}
this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Important, () => "Successfully created package '{0}'".FormatWith(outputPath));
}
public void PushDryRun(ChocolateyConfiguration config)
{
var nupkgFilePath = GetPackageFileOrThrow(config, NuGetConstants.PackageExtension);
this.Log().Info(() => "Would have attempted to push '{0}' to source '{1}'.".FormatWith(_fileSystem.GetFileName(nupkgFilePath), config.Sources));
}
public virtual void Push(ChocolateyConfiguration config)
{
var nupkgFilePath = GetPackageFileOrThrow(config, NuGetConstants.PackageExtension);
var nupkgFileName = _fileSystem.GetFileName(nupkgFilePath);
if (config.RegularOutput)
{
this.Log().Info(() => "Attempting to push {0} to {1}".FormatWith(nupkgFileName, config.Sources));
}
var sourceCacheContext = new ChocolateySourceCacheContext(config);
NugetPush.PushPackage(config, _fileSystem.GetFullPath(nupkgFilePath), _nugetLogger, nupkgFileName, _fileSystem, sourceCacheContext);
if (config.RegularOutput && (config.Sources.IsEqualTo(ApplicationParameters.ChocolateyCommunityFeedPushSource) || config.Sources.IsEqualTo(ApplicationParameters.ChocolateyCommunityFeedPushSourceOld)))
{
this.Log().Warn(ChocolateyLoggers.Important, () => @"
Your package will go through automated checks and may be subject to
human moderation. You should receive email(s) with the automated
testing results. If you don't receive them within 1-3 business days,
please use the 'Contact Site Admins' on the package page to contact the
moderators. If your package is subject to human moderation there is no
guarantee on the length of time that this can take to complete. This
depends on the availability of moderators, number of packages in the
queue at this time, as well as many other factors.
You can check where your package is in the moderation queue here:
https://ch0.co/moderation
For more information about the moderation process, see the docs:
https://docs.chocolatey.org/en-us/community-repository/moderation/
Please ensure your registered email address is correct and emails from
moderation at chocolatey dot org are not being sent to your spam/junk
folder.");
}
}
public void InstallDryRun(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
//todo: #2576 noop should see if packages are already installed and adjust message, amiright?!
this.Log().Info("{0} would have used NuGet to install packages (if they are not already installed):{1}{2}".FormatWith(
ApplicationParameters.Name,
Environment.NewLine,
config.PackageNames
));
var tempInstallsLocation = _fileSystem.CombinePaths(_fileSystem.GetTempPath(), ApplicationParameters.Name, "TempInstalls_" + DateTime.Now.ToString("yyyyMMdd_HHmmss_ffff"));
_fileSystem.EnsureDirectoryExists(tempInstallsLocation);
var installLocation = ApplicationParameters.PackagesLocation;
ApplicationParameters.PackagesLocation = tempInstallsLocation;
Install(config, continueAction);
_fileSystem.DeleteDirectory(tempInstallsLocation, recursive: true);
ApplicationParameters.PackagesLocation = installLocation;
}
public virtual ConcurrentDictionary<string, PackageResult> Install(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
return Install(config, continueAction, beforeModifyAction: null);
}
public virtual ConcurrentDictionary<string, PackageResult> Install(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction)
{
_fileSystem.EnsureDirectoryExists(ApplicationParameters.PackagesLocation);
var packageResultsToReturn = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
SetRemotePackageNamesIfAllSpecified(config, () => { });
NuGetVersion version = !string.IsNullOrWhiteSpace(config.Version) ? NuGetVersion.Parse(config.Version) : null;
if (config.Force)
{
config.AllowDowngrade = true;
}
var sourceCacheContext = new ChocolateySourceCacheContext(config);
var remoteRepositories = NugetCommon.GetRemoteRepositories(config, _nugetLogger, _fileSystem);
var remoteEndpoints = NugetCommon.GetRepositoryResources(remoteRepositories, sourceCacheContext);
var localRepositorySource = NugetCommon.GetLocalRepository();
var pathResolver = NugetCommon.GetPathResolver(_fileSystem);
var nugetProject = new FolderNuGetProject(ApplicationParameters.PackagesLocation, pathResolver, NuGetFramework.AnyFramework);
var projectContext = new ChocolateyNuGetProjectContext(config, _nugetLogger);
IList<string> packageNames = config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).OrEmpty().ToList();
if (packageNames.Count == 1)
{
var packageName = packageNames.DefaultIfEmpty(string.Empty).FirstOrDefault();
if (packageName.EndsWith(NuGetConstants.PackageExtension) || packageName.EndsWith(PackagingConstants.ManifestExtension))
{
this.Log().Warn(ChocolateyLoggers.Important, "DEPRECATION WARNING");
this.Log().Warn(InstallWithFilePathDeprecationMessage);
this.Log().Debug("Updating source and package name to handle *.nupkg or *.nuspec file.");
packageNames.Clear();
config.Sources = _fileSystem.GetDirectoryName(_fileSystem.GetFullPath(packageName));
if (packageName.EndsWith(PackagingConstants.ManifestExtension))
{
packageNames.Add(_fileSystem.GetFilenameWithoutExtension(packageName));
this.Log().Debug("Building nuspec file prior to install.");
config.Input = packageName;
// build package
Pack(config);
}
else
{
using (var packageFile = new PackageArchiveReader(_fileSystem.GetFullPath(packageName)))
{
version = packageFile.NuspecReader.GetVersion();
packageNames.Add(packageFile.NuspecReader.GetId());
packageFile.Dispose();
}
}
}
}
// this is when someone points the source directly at a nupkg
// e.g. -source c:\somelocation\somewhere\packagename.nupkg
if (config.Sources.ToStringSafe().EndsWith(NuGetConstants.PackageExtension))
{
config.Sources = _fileSystem.GetDirectoryName(_fileSystem.GetFullPath(config.Sources));
}
config.CreateBackup();
foreach (var packageName in packageNames.OrEmpty())
{
// We need to ensure we are using a clean configuration file
// before we start reading it.
config.RevertChanges();
var allLocalPackages = GetInstalledPackages(config).ToList();
var packagesToInstall = new List<IPackageSearchMetadata>();
var packagesToUninstall = new HashSet<PackageResult>();
var sourcePackageDependencyInfos = new HashSet<SourcePackageDependencyInfo>(PackageIdentityComparer.Default);
var localPackageToRemoveDependencyInfos = new HashSet<SourcePackageDependencyInfo>(PackageIdentityComparer.Default);
var installedPackage = allLocalPackages.FirstOrDefault(p => p.Name.IsEqualTo(packageName));
if (Platform.GetPlatform() != PlatformType.Windows && !packageName.EndsWith(".template"))
{
var logMessage = "{0} is not a supported package on non-Windows systems.{1}Only template packages are currently supported.".FormatWith(packageName, Environment.NewLine);
this.Log().Warn(ChocolateyLoggers.Important, logMessage);
}
if (installedPackage != null && (version == null || version == installedPackage.PackageMetadata.Version) && !config.Force)
{
var logMessage = "{0} v{1} already installed.{2} Use --force to reinstall, specify a version to install, or try upgrade.".FormatWith(installedPackage.Name, installedPackage.Version, Environment.NewLine);
var nullResult = packageResultsToReturn.GetOrAdd(packageName, installedPackage);
nullResult.Messages.Add(new ResultMessage(ResultType.Warn, logMessage));
nullResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage));
this.Log().Warn(ChocolateyLoggers.Important, logMessage);
continue;
}
NuGetVersion latestPackageVersion = null;
if (installedPackage != null && (version == null || version == installedPackage.PackageMetadata.Version) && config.Force)
{
this.Log().Warn(ChocolateyLoggers.Important, () => @"{0} v{1} already installed. Forcing reinstall of version '{1}'.
Please use upgrade if you meant to upgrade to a new version.".FormatWith(installedPackage.Name, installedPackage.Version));
//This is set to ensure the same package version is reinstalled
latestPackageVersion = installedPackage.PackageMetadata.Version;
}
if (installedPackage != null && version != null && version < installedPackage.PackageMetadata.Version && !config.AllowDowngrade)
{
var logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to install older versions.".FormatWith(installedPackage.Name, installedPackage.Version, Environment.NewLine);
var nullResult = packageResultsToReturn.GetOrAdd(packageName, installedPackage);
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
continue;
}
if (latestPackageVersion is null && version != null)
{
latestPackageVersion = version;
}
var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, sourceCacheContext, remoteEndpoints, latestPackageVersion);
if (availablePackage == null)
{
var logMessage = @"{0} not installed. The package was not found with the source(s) listed.
Source(s): '{1}'
NOTE: When you specify explicit sources, it overrides default sources.
If the package version is a prerelease and you didn't specify `--pre`,
the package may not be found.{2}{3}".FormatWith(packageName, config.Sources, string.IsNullOrWhiteSpace(config.Version)
? string.Empty
: @"
Version was specified as '{0}'. It is possible that version
does not exist for '{1}' at the source specified.".FormatWith(config.Version, packageName),
@"
Please see https://docs.chocolatey.org/en-us/troubleshooting for more
assistance.");
this.Log().Error(ChocolateyLoggers.Important, logMessage);
var noPkgResult = packageResultsToReturn.GetOrAdd(packageName, new PackageResult(packageName, version.ToFullStringChecked(), null));
noPkgResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
continue;
}
var oldPrerelease = config.Prerelease;
config.Prerelease = config.Prerelease || availablePackage.Identity.Version.IsPrerelease;
NugetCommon.GetPackageDependencies(availablePackage.Identity, NuGetFramework.AnyFramework, sourceCacheContext, _nugetLogger, remoteEndpoints, sourcePackageDependencyInfos, new HashSet<PackageDependency>(), config).GetAwaiter().GetResult();
config.Prerelease = oldPrerelease;
if (installedPackage != null && (installedPackage.PackageMetadata.Version == availablePackage.Identity.Version) && config.Force)
{
packagesToUninstall.Add(installedPackage);
}
if (config.ForceDependencies && installedPackage != null)
{
NugetCommon.GetLocalPackageDependencies(installedPackage.Identity, NuGetFramework.AnyFramework, allLocalPackages, localPackageToRemoveDependencyInfos);
foreach (var dependencyInfo in localPackageToRemoveDependencyInfos)
{
packagesToUninstall.Add(allLocalPackages.FirstOrDefault(p => p.Identity.Equals(dependencyInfo)));
}
}
packagesToInstall.Add(availablePackage);
var targetIdsToInstall = packagesToInstall.Select(p => p.Identity.Id);
var localPackagesDependencyInfos = allLocalPackages
// If we're forcing dependencies, we only need to know which dependencies are installed locally
.Where(p => config.ForceDependencies
? targetIdsToInstall.Contains(p.Name, StringComparer.OrdinalIgnoreCase)
: !targetIdsToInstall.Contains(p.Name, StringComparer.OrdinalIgnoreCase))
.Select(
p => new SourcePackageDependencyInfo(
p.SearchMetadata.Identity,
p.PackageMetadata.DependencyGroups.SelectMany(x => x.Packages).ToList(),
true,
localRepositorySource,
null,
null));
var removedSources = RemovePinnedSourceDependencies(sourcePackageDependencyInfos, allLocalPackages);
sourcePackageDependencyInfos.AddRange(localPackagesDependencyInfos);
if (removedSources.Count > 0 && version == null)
{
RemoveInvalidDependenciesAndParents(availablePackage, removedSources, sourcePackageDependencyInfos, localPackagesDependencyInfos);
}
var dependencyResolver = new PackageResolver();
var allPackagesIdentities = Enumerable.Empty<PackageIdentity>();
if (availablePackage.DependencySets.Any() || localPackagesDependencyInfos.Any(d => d.Dependencies.Any(dd => dd.Id == availablePackage.Identity.Id)))
{
allPackagesIdentities = allLocalPackages
// We exclude any installed package that does have a dependency that is missing,
// except if that dependency is one of the targets the user requested.
// If we do not exclude such packages, we will get a resolving exception later.
.Where(p => IsDependentOnTargetPackages(p, targetIdsToInstall) || !HasMissingDependency(p, allLocalPackages))
.Select(p => p.SearchMetadata.Identity)
// If we're forcing dependencies, we only need to know which dependencies are installed locally, not the entire list of packages
.Where(p => config.ForceDependencies
? sourcePackageDependencyInfos.Any(s => s.Id == p.Id)
: !targetIdsToInstall.Contains(p.Id, StringComparer.OrdinalIgnoreCase)).ToList();
}
var allPackagesReferences = allPackagesIdentities.Select(p => new PackageReference(p, NuGetFramework.AnyFramework));
var resolverContext = new PackageResolverContext(
dependencyBehavior: DependencyBehavior.Highest,
targetIds: targetIdsToInstall,
requiredPackageIds: allPackagesIdentities.Select(p => p.Id),
packagesConfig: allPackagesReferences,
preferredVersions: allPackagesIdentities.Where(p => !p.Id.Equals(packageName, StringComparison.OrdinalIgnoreCase)),
availablePackages: sourcePackageDependencyInfos,
packageSources: remoteRepositories.Select(s => s.PackageSource),
log: _nugetLogger
);
IEnumerable<SourcePackageDependencyInfo> resolvedPackages = new List<SourcePackageDependencyInfo>();
if (config.IgnoreDependencies)
{
resolvedPackages = packagesToInstall.Select(p => sourcePackageDependencyInfos.Single(x => p.Identity.Equals(new PackageIdentity(x.Id, x.Version))));
if (config.ForceDependencies)
{
//TODO Log warning here about dependencies being removed and not being reinstalled?
foreach (var packageToUninstall in packagesToUninstall.Where(p => !resolvedPackages.Contains(p.Identity)))
{
try
{
nugetProject.DeletePackage(packageToUninstall.Identity, projectContext, CancellationToken.None).GetAwaiter().GetResult();
RemovePackageFromCache(config, packageToUninstall.PackageMetadata);
}
catch (Exception ex)
{
var forcedResult = packageResultsToReturn.GetOrAdd(packageToUninstall.Identity.Id, packageToUninstall);
forcedResult.Messages.Add(new ResultMessage(ResultType.Note, "Removing old version"));
var logMessage = "{0}:{1} {2}".FormatWith("Unable to remove existing package", Environment.NewLine, ex.Message);
this.Log().Warn(logMessage);
forcedResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage));
}
}
}
}
else
{
try
{
resolvedPackages = dependencyResolver.Resolve(resolverContext, CancellationToken.None)
.Select(p => sourcePackageDependencyInfos.Single(x => PackageIdentityComparer.Default.Equals(x, p)));
if (!config.ForceDependencies)
{
var identitiesToUninstall = packagesToUninstall.Select(x => x.Identity);
resolvedPackages = resolvedPackages.Where(p => !(localPackagesDependencyInfos.Contains(p) && !identitiesToUninstall.Contains(p)));
// If forcing dependencies, then dependencies already added to packages to remove.
// If not forcing dependencies, then package needs to be removed so it can be upgraded to the new version required by the parent
packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase)));
}
}
catch (NuGetResolverConstraintException ex)
{
var logMessage = GetDependencyResolutionErrorMessage(ex);
this.Log().Error(ChocolateyLoggers.Important, logMessage);
foreach (var pkgMetadata in packagesToInstall)
{
var errorResult = packageResultsToReturn.GetOrAdd(pkgMetadata.Identity.Id, new PackageResult(pkgMetadata, pathResolver.GetInstallPath(pkgMetadata.Identity)));
errorResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
}
}
catch (Exception ex)
{
this.Log().Warn("Need to add specific handling for exception type {0}".FormatWith(ex.GetType().Name));
this.Log().Warn(ex.Message);
}
}
foreach (SourcePackageDependencyInfo packageDependencyInfo in resolvedPackages)
{
var packageRemoteMetadata = packagesToInstall.FirstOrDefault(p => p.Identity.Equals(packageDependencyInfo));
if (packageRemoteMetadata is null)
{
var endpoint = NuGetEndpointResources.GetResourcesBySource(packageDependencyInfo.Source, sourceCacheContext);
packageRemoteMetadata = endpoint.PackageMetadataResource
.GetMetadataAsync(packageDependencyInfo, sourceCacheContext, _nugetLogger, CancellationToken.None)
.GetAwaiter().GetResult();
}
var shouldAddForcedResultMessage = false;
var packageToUninstall = packagesToUninstall.FirstOrDefault(p => p.PackageMetadata.Id.Equals(packageDependencyInfo.Id, StringComparison.OrdinalIgnoreCase));
if (packageToUninstall != null)
{
shouldAddForcedResultMessage = true;
BackupAndRunBeforeModify(packageToUninstall, config, beforeModifyAction);
packageToUninstall.InstallLocation = pathResolver.GetInstallPath(packageToUninstall.Identity);
try
{
// This deletes satellite files and stuff
//But it does not throw or return false if it fails to delete something...
var ableToDelete = nugetProject.DeletePackage(packageToUninstall.Identity, projectContext, CancellationToken.None, shouldDeleteDirectory: false).GetAwaiter().GetResult();
//So removing directly manually so as to throw if needed.
_fileSystem.DeleteDirectoryChecked(packageToUninstall.InstallLocation, true, true, true);
RemovePackageFromCache(config, packageToUninstall.PackageMetadata);
}
catch (Exception ex)
{
var forcedResult = packageResultsToReturn.GetOrAdd(packageToUninstall.Name, packageToUninstall);
forcedResult.Messages.Add(new ResultMessage(ResultType.Note, "Backing up and removing old version"));
var logMessage = "{0}:{1} {2}".FormatWith("Unable to remove existing package prior to forced reinstall", Environment.NewLine, ex.Message);
this.Log().Warn(logMessage);
forcedResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage));
forcedResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
if (continueAction != null)
{
continueAction.Invoke(forcedResult, config);
}
continue;
}
}
try
{
//TODO, do sanity check here.
var endpoint = NuGetEndpointResources.GetResourcesBySource(packageDependencyInfo.Source, sourceCacheContext);
var downloadResource = endpoint.DownloadResource;
_fileSystem.DeleteFile(pathResolver.GetInstalledPackageFilePath(packageDependencyInfo));
this.Log().Info("Downloading package from source '{0}'".FormatWith(packageDependencyInfo.Source));
this.Log().Debug("Package download location '{0}'".FormatWith(packageDependencyInfo.DownloadUri));
ChocolateyProgressInfo.ShouldDisplayDownloadProgress = config.Features.ShowDownloadProgress;
using (var downloadResult = downloadResource.GetDownloadResourceResultAsync(
packageDependencyInfo,
new PackageDownloadContext(sourceCacheContext),
NuGetEnvironment.GetFolderPath(NuGetFolderPath.Temp),
_nugetLogger, CancellationToken.None).GetAwaiter().GetResult())
{
ValidatePackageHash(config, packageDependencyInfo, downloadResult);
nugetProject.InstallPackageAsync(
packageDependencyInfo,
downloadResult,
projectContext,
CancellationToken.None).GetAwaiter().GetResult();
}
var installedPath = nugetProject.GetInstalledPath(packageDependencyInfo);
NormalizeNuspecCasing(packageRemoteMetadata, installedPath);
RemovePackageFromNugetCache(packageRemoteMetadata);
var manifestPath = nugetProject.GetInstalledManifestFilePath(packageDependencyInfo);
var packageMetadata = new ChocolateyPackageMetadata(manifestPath, _fileSystem);
this.Log().Info(ChocolateyLoggers.Important, "{0}{1} v{2}{3}{4}{5}".FormatWith(
System.Environment.NewLine,
packageMetadata.Id,
packageMetadata.Version.ToFullStringChecked(),
config.Force ? " (forced)" : string.Empty,
packageRemoteMetadata.IsApproved ? " [Approved]" : string.Empty,
packageRemoteMetadata.PackageTestResultStatus == "Failing" && packageRemoteMetadata.IsDownloadCacheAvailable ? " - Likely broken for FOSS users (due to download location changes)" : packageRemoteMetadata.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty
));
var packageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath));
if (shouldAddForcedResultMessage)
{
packageResult.Messages.Add(new ResultMessage(ResultType.Note, "Backing up and removing old version"));
}
packageResult.InstallLocation = installedPath;
packageResult.Messages.Add(new ResultMessage(ResultType.Debug, ApplicationParameters.Messages.ContinueChocolateyAction));
var elementsList = _ruleService.ValidateRules(manifestPath)
.Where(r => r.Severity == infrastructure.rules.RuleType.Error && !string.IsNullOrEmpty(r.Id))
.WhereUnsupportedOrDeprecated()
.Select(r => "{0}: {1}".FormatWith(r.Id, r.Message))
.ToList();
if (elementsList.Count > 0)
{
var message = "Issues found with nuspec elements\r\n" + elementsList.Join("\r\n");
packageResult.Messages.Add(new ResultMessage(ResultType.Warn, message));
}
if (continueAction != null)
{
continueAction.Invoke(packageResult, config);
}
}
catch (Exception ex)
{
var message = ex.Message;
var webException = ex as System.Net.WebException;
if (webException != null)
{
var response = webException.Response as HttpWebResponse;
if (response != null && !string.IsNullOrWhiteSpace(response.StatusDescription))
{
message += " {0}".FormatWith(response.StatusDescription);
}
}
var logMessage = "{0} not installed. An error occurred during installation:{1} {2}".FormatWith(packageDependencyInfo.Id, Environment.NewLine, message);
this.Log().Error(ChocolateyLoggers.Important, logMessage);
var errorResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id, new PackageResult(packageDependencyInfo.Id, version.ToFullStringChecked(), null));
errorResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
if (errorResult.ExitCode == 0)
{
errorResult.ExitCode = 1;
}
if (continueAction != null)
{
continueAction.Invoke(errorResult, config);
}
}
}
}
// Reset the configuration again once we are completely done with the processing of
// configurations, and make sure that we are removing any backup that was created
// as part of this run.
config.RevertChanges(removeBackup: true);
return packageResultsToReturn;
}
protected virtual string GetDependencyResolutionErrorMessage(NuGetResolverConstraintException exception)
{
if (exception.Message.StartsWith("Unable to resolve dependency '"))
{
return exception.Message;
}
var errorMessagePatterns = new string[]
{
@"constraint: (?<packageId>\w+)\s\(",
@"Circular dependency detected '(?<packageId>\w+) "
};
string invalidDependencyName = null;
foreach (var pattern in errorMessagePatterns)
{
var invalidDependencyMatch = Regex.Match(exception.Message, pattern, RegexOptions.IgnoreCase);
if (invalidDependencyMatch.Groups["packageId"].Success)
{
invalidDependencyName = invalidDependencyMatch.Groups["packageId"].Value;
break;
}
}
if (invalidDependencyName == null)
{
this.Log().Debug("Could not find invalid dependency name in dependency resolution message, add another match pattern to handle this case");
return $"Unable to resolve dependency: {exception.Message}";
}
return $"Unable to resolve dependency '{invalidDependencyName}': {exception.Message}";
}
public virtual void EnsureBackupDirectoryRemoved(string packageName)
{
var rollbackDirectory = _fileSystem.GetFullPath(_fileSystem.CombinePaths(ApplicationParameters.PackageBackupLocation, packageName));
if (!_fileSystem.DirectoryExists(rollbackDirectory))
{
//search for folder
var possibleRollbacks = _fileSystem.GetDirectories(ApplicationParameters.PackageBackupLocation, packageName + "*");
if (possibleRollbacks != null && possibleRollbacks.Count() != 0)
{
rollbackDirectory = possibleRollbacks.OrderByDescending(p => p).DefaultIfEmpty(string.Empty).FirstOrDefault();
}
rollbackDirectory = _fileSystem.GetFullPath(rollbackDirectory);
}
if (string.IsNullOrWhiteSpace(rollbackDirectory) || !_fileSystem.DirectoryExists(rollbackDirectory))
{
return;
}