chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
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
//            Copyright Keysight Technologies 2012-2019
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Tap.Shared;
 
namespace OpenTap.Package
{
    /// <summary>
    /// Implements a IPackageRepository that queries a local directory for OpenTAP packages.
    /// </summary>
    public class FilePackageRepository : IPackageRepository, IPackageDownloadProgress
    {
        
#pragma warning disable 1591 // TODO: Add XML Comments in this file, then remove this
        private static TraceSource log = Log.CreateSource("FilePackageRepository");
        internal const string TapPluginCache = ".PackageCache";
        static readonly object cacheLock = new object();
        static readonly object loadLock = new object();
 
        private List<string> allFiles = new List<string>();
        private PackageDef[] allPackages;
 
        /// <summary>
        /// Constructs a FilePackageRepository for a directory
        /// </summary>
        /// <param name="path">Relative or absolute path or URI to a directory or a file. If file, the repository will be the directory containing the file</param>
        /// <exception cref="NotSupportedException">Path is not a valid file package repository</exception>
        public FilePackageRepository(string path)
        {
            // if path is the path root, for example C: and the path is not "/".
            // then we need to add a '\' so "C:" becomes "C:\".
            // On other systems (Linux, mac, .. where path == "/") we do nothing.
            if (Path.IsPathRooted(path) && path !="/" && Path.GetPathRoot(path) == path)
            {
                path = Path.GetPathRoot(path).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
            }
            
            if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out Uri uri))
            {
                // This is true for UNC paths on Windows
                if (uri.IsAbsoluteUri && uri.HostNameType is UriHostNameType.Dns or UriHostNameType.IPv4 or UriHostNameType.IPv6)
                {
                    AbsolutePath = uri.LocalPath;
                    Url = uri.AbsoluteUri.TrimEnd(new[] { '\\', '/' });;
                }
                else
                {
                    string absolutePath = null;
                    if (uri.IsAbsoluteUri)
                    {
                        if (uri.Scheme != Uri.UriSchemeFile)
                            throw new NotSupportedException($"Scheme {uri.Scheme} is not supported as a file package repository ({path}).");
                        absolutePath = uri.AbsolutePath;
                    }
                    else
                    {
                        absolutePath = Path.GetFullPath(path);
                    }
 
                    if (File.Exists(absolutePath))
                        AbsolutePath = Path.GetFullPath(Path.GetDirectoryName(absolutePath));
                    else
                        AbsolutePath = Path.GetFullPath(absolutePath);
                        
                    AbsolutePath = Uri.UnescapeDataString(AbsolutePath);
 
                    Url = new Uri(AbsolutePath).AbsoluteUri;
                }
            }
            else
                throw new NotSupportedException($"{path} is not supported as a file package repository.");
        }
        public void Reset()
        {
            allPackages = null;
            LoadPath(new CancellationToken());
        }
 
        private void LoadPath(CancellationToken cancellationToken)
        {
            if (allPackages != null)
                return;
 
            if (File.Exists(AbsolutePath) || Directory.Exists(AbsolutePath) == false)
            {
                allPackages = Array.Empty<PackageDef>();
 
                if (AbsolutePath.TrimEnd('/', '\\') != PackageDef.SystemWideInstallationDirectory.TrimEnd('/', '\\')) // Let's ignore this error if the repo is the system wide directory.
                    throw new DirectoryNotFoundException($"File package repository directory not found at: {Url}");
 
                return;
            }
 
            lock (loadLock)
            {
                if (allPackages != null)
                    return;
 
                allFiles = GetAllFiles(AbsolutePath, cancellationToken);
                cancellationToken.ThrowIfCancellationRequested();
                allPackages = GetAllPackages(allFiles).ToArray();
 
                // the following code tries to delete unused cache files
                // It loops through all files and checks if they are a .PackageCache file
                // if they are and they are not used by any current repository, delete it.
 
                var caches = PackageManagerSettings.Current.Repositories.Select(x => x.Url)
                    .Append(PackageCacheHelper.PackageCacheDirectory)
                    .Select(p => GetCache(p).CacheFileName)
                    .ToHashSet();
                foreach (var file in allFiles)
                {
                    var filename = Path.GetFileName(file);
                    if (filename.StartsWith(TapPluginCache) == false) continue;
                    if (caches.Contains(filename)) continue;
                    try
                    {
                        File.Delete(file);
                    }
                    catch
                    {
                        // This is fine
                    }
                }
            }
        }
 
        Action<string, long, long> IPackageDownloadProgress.OnProgressUpdate { get; set; }
 
        internal string AbsolutePath;
 
        #region IPackageRepository Implementation
        public string Url { get; set; }
        public void DownloadPackage(IPackageIdentifier package, string destination, CancellationToken cancellationToken)
        {
            PackageDef packageDef = null;
 
            // If the requested package is a file we do not want to start searching the entire repo.
            if (package is PackageDef def && File.Exists((def.PackageSource as FilePackageDefSource)?.PackageFilePath))
            {
                log.Debug("Downloading file without searching repository.");
                packageDef = def;
            }
            else
                LoadPath(cancellationToken);
 
            if (packageDef == null)
                packageDef = allPackages.FirstOrDefault(p => p.Equals(package));
 
            bool finished = false;
            try
            {
                var packageFilePath = (packageDef?.PackageSource as FilePackageDefSource)?.PackageFilePath;
 
                if (packageDef == null || packageFilePath == null)
                    throw new Exception($"Could not download '{package.Name}', because it does not exists");
 
                if (PathUtils.AreEqual(packageFilePath, destination))
                {
                    finished = true;
                    return; // No reason to copy..
                }
                if (Path.GetExtension(packageFilePath).ToLower() == ".tappackages") // If package is a .TapPackages file, unpack it.
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    var packagesFiles = PluginInstaller.UnpackPackage(packageFilePath, Path.GetTempPath());
                    string path = null;
                    foreach (var packageFile in packagesFiles)
                    {
                        var internalPackage = PackageDef.FromPackage(packageFile);
                        if (internalPackage.Name == packageDef.Name && internalPackage.Version == packageDef.Version)
                        {
                            path = packageFile;
                            break;
                        }
                    }
 
                    if (string.IsNullOrEmpty(path) == false)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        FileCopy(path, destination);
                        finished = true;
                    }
 
                    foreach (var packageFile in packagesFiles)
                    {
                        if (File.Exists(packageFile))
                            File.Delete(packageFile);
                    }
                }
                else
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    FileCopy(packageFilePath, destination);
                    finished = true;
                }
            }
            catch (Exception ex)
            {
                if (!(ex.InnerException is TaskCanceledException))
                {
                    throw;
                }
            }
            finally
            {
                if ((!finished || cancellationToken.IsCancellationRequested) && File.Exists(destination))
                    File.Delete(destination);
            }
        }
 
        // Copying files can be very slow if it is from a network location.
        // this file-copy action copies and notifies of progress.
        void FileCopy(string source, string destination)
        {
            var tmpDestination = destination + ".part-" + Guid.NewGuid();
            using (FileLock.Create(destination + ".lock"))
            {
                if (File.Exists(destination) && PathUtils.CompareFiles(source, destination))
                    return;
 
                using (var readStream = File.OpenRead(source))
                using (var writeStream = File.OpenWrite(tmpDestination))
                {
                    var task = Task.Run(() => readStream.CopyTo(writeStream));
                    ConsoleUtils.ReportProgressTillEnd(task, $"Copying {source} to {destination}",
                        () => writeStream.Position,
                        () => readStream.Length,
                        (header, pos, len) =>
                        {
                            ConsoleUtils.printProgress(header, pos, len);
                            (this as IPackageDownloadProgress).OnProgressUpdate?.Invoke(header, pos, len);
                        });
                }
 
                File.Delete(destination);
                // on most operative systems the same folder would be on the same disk, so this is a no-op.
                try
                {
                    File.Move(tmpDestination, destination);
                }
                catch
                {
 
                }
            }
        }
        public string[] GetPackageNames(CancellationToken cancellationToken, params IPackageIdentifier[] compatibleWith)
        {
            LoadPath(cancellationToken);
 
            if (this.allPackages == null || this.allFiles == null) return null;
            var packages = this.allPackages.ToList();
 
            // Check if package dependencies are compatible
            compatibleWith = CheckCompatibleWith(compatibleWith);
            if (compatibleWith != null)
                packages = packages.Where(p => p.Dependencies.All(d => compatibleWith.All(r => IsCompatible(d, r)))).ToList();
 
            return packages
                .Select(p => p.Name)
                .Distinct()
                .ToArray();
        }
        public string[] GetPackageNames(string @class, CancellationToken cancellationToken, params IPackageIdentifier[] compatibleWith)
        {
            LoadPath(cancellationToken);
 
            if (this.allPackages == null || this.allFiles == null) return null;
            var packages = this.allPackages.Where(p => p.Class == @class).ToList();
 
            // Check if package dependencies are compatible
            compatibleWith = CheckCompatibleWith(compatibleWith);
            if (compatibleWith != null)
                packages = packages.Where(p => p.Dependencies.All(d => compatibleWith.All(r => IsCompatible(d, r)))).ToList();
 
            return packages
                .Select(p => p.Name)
                .Distinct()
                .ToArray();
        }
        public PackageVersion[] GetPackageVersions(string packageName, CancellationToken cancellationToken, params IPackageIdentifier[] compatibleWith)
        {
            LoadPath(cancellationToken);
 
            if (this.allPackages == null || this.allFiles == null) return null;
            var packages = this.allPackages.ToList();
 
            // Check if package dependencies are compatible
            compatibleWith = CheckCompatibleWith(compatibleWith);
            if (compatibleWith != null)
                packages = packages.Where(p => p.Dependencies.All(d => compatibleWith.All(r => IsCompatible(d, r)))).ToList();
 
            return packages
                .Where(p => p.Name == packageName)
                .Select(p => new PackageVersion(packageName, p.Version, p.OS, p.Architecture, p.Date,
                    p.Files.Where(f => string.IsNullOrWhiteSpace(f.LicenseRequired) == false).Select(f => f.LicenseRequired).ToList()))
                .Distinct()
                .ToArray();
        }
 
        public PackageDef[] GetAllPackages(CancellationToken cancellationToken)
        {
            LoadPath(cancellationToken);
            return allPackages;
        }
        
        public PackageDef[] GetPackages(PackageSpecifier pid, CancellationToken cancellationToken, params IPackageIdentifier[] compatibleWith)
        {
            LoadPath(cancellationToken);
 
            if (this.allPackages == null || this.allFiles == null) return null;
 
            // Filter packages
            var openTapIdentifier = new PackageIdentifier("OpenTAP", PluginManager.GetOpenTapAssembly().SemanticVersion.ToString(), CpuArchitecture.Unspecified, null);
            var packages = new List<PackageDef>();
            compatibleWith = CheckCompatibleWith(compatibleWith);
 
            foreach (var package in allPackages)
            {
                if (string.IsNullOrWhiteSpace(pid.Name) == false && (pid.Name != package.Name))
                    continue;
                if (!pid.Version.IsCompatible(package.Version))
                    continue;
                if (package.IsPlatformCompatible(pid.Architecture, pid.OS) == false)
                    continue;
 
                // Check if package dependencies are compatible
                if (package.Dependencies.All(d => compatibleWith.All(r => IsCompatible(d, r))) == false)
                    continue;
 
                packages.Add(package);
            }
 
            // If we should not check compatibility, take the one that is most compatible.
            if (compatibleWith?.Length == 0)
            {
                List<Tuple<int, PackageDef>> filteredPackages = new List<Tuple<int, PackageDef>>();
                foreach (var item in packages)
                {
                    filteredPackages.Add(Tuple.Create(item.Dependencies.Count(d => IsCompatible(d, openTapIdentifier)), item));
                }
 
                // Find most compatible packages
                packages = filteredPackages
                    .OrderByDescending(p => (double) p.Item1 / p.Item2.Dependencies.Count)
                    .ThenByDescending(p => p.Item2.Version).Select(p => p.Item2).ToList();
            }
 
            // Select the latest of each packagename left
            return packages
                .GroupBy(p => p.Name).Select(g => g.FirstOrDefault(x => x.Architecture == pid.Architecture) ?? g.First())
                .ToArray();
        }
        public  PackageDef[] CheckForUpdates(IPackageIdentifier[] packages, CancellationToken cancellationToken)
        {
            LoadPath(cancellationToken);
 
            if (allPackages == null || allFiles == null) return null;
 
            List<PackageDef> latestPackages = new List<PackageDef>();
            var openTapIdentifier = new PackageIdentifier("OpenTAP", PluginManager.GetOpenTapAssembly().SemanticVersion.ToString(), CpuArchitecture.Unspecified, null);
 
            // Find updated packages
            foreach (var packageIdentifier in packages)
            {
                if (packageIdentifier == null)
                    continue;
 
                var package = new PackageIdentifier(packageIdentifier);
 
                // Try finding a OpenTAP package
                var latest = allPackages
                    .Where(p => package?.Name == p?.Name)
                    .Where(p => string.IsNullOrWhiteSpace(p?.Version?.PreRelease)) // Only suggest upgrading to released versions
                    .Where(p => p.Dependencies.All(dep => IsCompatible(dep, openTapIdentifier))).FirstOrDefault(p => p.Version != null && p.Version.CompareTo(package.Version) > 0);
 
                if (latest != null)
                    latestPackages.Add(latest);
            }
 
            return latestPackages.ToArray();
        }
        #endregion
 
        #region file system
        private void CreatePackageCache(IEnumerable<PackageDef> packages, FileRepositoryCache cache)
        {
            string currentDir = FileSystemHelper.GetCurrentInstallationDirectory();
            // Delete existing cache
            List<string> caches = Directory.GetFiles(currentDir, $"{TapPluginCache}.{cache.Hash}*").ToList();
            caches.ForEach(File.Delete);
            
            string fullPath = Path.Combine(currentDir, cache.CacheFileName);
 
 
            // Serialize all packages and Save cache
            using(var f = File.OpenWrite(fullPath))
            {
                using (var gz = new GZipStream(f, CompressionLevel.Optimal, leaveOpen: true))
                {
                    PackageDef.SaveManyTo(gz, packages);
                }
            }
        }
        private List<string> GetAllFiles(string path, CancellationToken cancellationToken)
        {
            var result = new List<string>();
            var dirs = new Queue<DirectoryInfo>();
            dirs.Enqueue(new DirectoryInfo(path));
 
            while (dirs.Any() && cancellationToken.IsCancellationRequested == false)
            {
                var dir = dirs.Dequeue();
                try
                {
                    var content = dir.EnumerateDirectories();
                    foreach (var subDir in content)
                    {
                        dirs.Enqueue(subDir);
                    }
 
                    result.AddRange(dir.EnumerateFiles().Select(f => f.FullName));
                }
                catch (Exception)
                {
                    log.Debug($"Access to path {dir.FullName} denied. Ignoring.");
                }
            }
            
            return result;
        }
        private PackageDef[] loadPackagesFromFile(IEnumerable<FileInfo> allFiles)
        {
            var allPackages = new List<PackageDef>();
            var packagesFiles = allFiles.Where(f => f.Extension.ToLower() == ".tappackages").ToHashSet();
 
            // Deserializer .TapPackages files
            Parallel.ForEach(packagesFiles, packagesFile =>
            {
                List<PackageDef> packages;
                try
                {
                    packages = PackageDef.FromPackages(packagesFile.FullName);
                    if (packages == null) return;
                }
                catch (Exception e)
                {
                    log.Error($"Could not unpackage '{packagesFile.FullName}'");
                    log.Debug(e);
                    return;
                }
 
                packages.ForEach(p =>
                {
#pragma warning disable 618
                    p.Location = packagesFile.FullName;
#pragma warning restore 618
                    p.PackageSource = new FileRepositoryPackageDefSource
                    {
                        RepositoryUrl = Url,
                        PackageFilePath = packagesFile.FullName
                    };
                });
                lock (allPackages)
                {
                    allPackages.AddRange(packages);
                }
            });
 
            // Deserialize all regular packages
            Parallel.ForEach(allFiles, pluginFile =>
            {
                if (packagesFiles.Contains(pluginFile))
                    return;
 
                PackageDef package;
                try
                {
                    package = PackageDef.FromPackage(pluginFile.FullName);
                    if (package == null) return;
                }
                catch
                {
                    return;
                }
 
                package.PackageSource = new FileRepositoryPackageDefSource
                {
                    RepositoryUrl = Url,
                    PackageFilePath = pluginFile.FullName
                };
 
                lock (allPackages)
                {
                    allPackages.Add(package);
                }
            });
 
            return allPackages.ToArray();
        }
 
        private List<PackageDef> GetAllPackages(List<string> allFiles)
        {
            // Get cache
            var cache = GetCache();
 
            // Find TapPackages in repo
            var allFileInfos = allFiles.Select(f => new FileInfo(f)).Where(f => f.Extension.ToLower() == ".tapplugin" || f.Extension.ToLower() == ".tappackage" || f.Extension.ToLower() == ".tappackages").ToList();
 
            cache.CachePackageCount = allFileInfos.Count;
            
            List<PackageDef> allPackages = null;
            lock (cacheLock)
            {
                try
                {
                    if (File.Exists(cache.CacheFileName))
                    {
                        if (allFileInfos.Count == cache.CachePackageCount)
                        {
                            var sw = Stopwatch.StartNew();
                            // Load cache
                            using (var str = File.OpenRead(cache.CacheFileName))
                                allPackages = PackageDef.ManyFromXml(new GZipStream(str, CompressionMode.Decompress)).ToList();
    
                            log.Debug(sw, "Loading cache: {0}", cache.CacheFileName);
                            
                            // Check if any files has been replaced
                            if (allPackages.Any(p => !allFiles.Any(f =>
                            {
                                var packageFilePath = (p.PackageSource as FileRepositoryPackageDefSource)?.PackageFilePath;
                                return string.IsNullOrWhiteSpace(packageFilePath) == false && PathUtils.AreEqual(f, Path.GetFullPath(packageFilePath));
                            })))
                                allPackages = null;
 
                            // Check if the cache is the newest file
                            if (allPackages != null && allFileInfos.Any() && (allFileInfos.Max(f => f.LastWriteTimeUtc) > new FileInfo(cache.CacheFileName).LastWriteTimeUtc))
                                allPackages = null;
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Warning("Error while reading package cache from '{0}'. Rebuilding cache.", cache.CacheFileName);
                    log.Debug(ex);
                }
 
                if (allPackages == null)
                {
                    // Get all packages
                    var sw = Stopwatch.StartNew();
                    allPackages = loadPackagesFromFile(allFileInfos).ToList();
                    cache.CachePackageCount = allFileInfos.Count;
 
                    // Create cache
                    try
                    {
                        CreatePackageCache(allPackages, cache);
                        log.Debug(sw, "Rebuilding cache: {0}", cache.CacheFileName);
                    }
                    catch (Exception ex)
                    {
                        // This can fail if the package cache is in use.
                        // For example if another thread or process is loading the cache while we are trying to write it.
                        // This is not that serious, as the cache will just be regenerated later.
                        log.Debug($"Unable to update package cache: '{ex.Message}'");
                        log.Debug(ex);
                    }
                }
            }
 
            // Order packages
            allPackages = allPackages.OrderByDescending(p => p.Version).ToList();
 
            return allPackages;
        }
        #endregion
 
        #region helper
        private static bool IsCompatible(PackageDependency dep, IPackageIdentifier packageIdentifier)
        {
            try
            {
                if (dep.Name == packageIdentifier.Name)
                {
                    return dep.Version.IsCompatible(packageIdentifier.Version);
                }
            }
            catch
            {
                log.Warning("Dependency '{0}' is not compatible with '{1}'.", dep.Name, packageIdentifier.Name);
                throw;
            }
 
            return true;
        }
        private IPackageIdentifier[] CheckCompatibleWith(IPackageIdentifier[] compatibleWith)
        {
            var list = compatibleWith?.ToList();
 
            var openTap = list?.FirstOrDefault(p => p.Name == "OpenTAP");
            if (openTap != null)
            {
                list.AddRange(new []
                {
                    new PackageIdentifier("Tap", openTap.Version, openTap.Architecture, openTap.OS),
                    new PackageIdentifier("TAP Base", openTap.Version, openTap.Architecture, openTap.OS)
                });
            }
 
            return list?.ToArray();
        }
 
        private FileRepositoryCache GetCache(string url = null)
        {
            var hash = String.Format("{0:X8}", MurMurHash3.Hash(url ?? Url));
            var files = Directory.GetFiles(FileSystemHelper.GetCurrentInstallationDirectory(), $"{TapPluginCache}*");
            var filePath = files.FirstOrDefault(f => f.Contains(hash));
 
            if (File.Exists(filePath))
            {
                var matches = Regex.Split(Path.GetFileName(filePath), "\\.");
 
                if (int.TryParse(matches[3], out int count))
                    return new FileRepositoryCache() {Hash = hash, CachePackageCount = count};
            }
 
            return new FileRepositoryCache() {Hash = hash};
        }
        #endregion
        
        /// <summary>  Creates a display friendly string of this. </summary>
        public override string ToString() =>  $"[FilePackageRepository: {Url}]";
    }
}