Bari.Core.Build.Cache.MemoryBuildCache.Restore C# (CSharp) Method

Restore() public method

Restores the stored files for a given builder to a file system directory

The cache only stores the latest stored results and this is what will be restored to the target directory. To verify if it was generated with the correct dependency fingerprint, use IBuildCache.Contains.

To ensure thread safety, use IBuildCache.LockForBuilder.

public Restore ( BuildKey builder, IFileSystemDirectory targetRoot, bool aggressive, Regex aggressiveExceptions = null ) : ISet
builder BuildKey Builder key
targetRoot IFileSystemDirectory Target file system directory
aggressive bool If true, files in the target directory won't be checked by hash before overriding them
aggressiveExceptions Regex Exceptions to the aggresivve mode. Can be null if not used.
return ISet
        public ISet<TargetRelativePath> Restore(BuildKey builder, IFileSystemDirectory targetRoot, bool aggressive, Regex[] aggressiveExceptions = null)
        {
            MemoryCacheItem item;
            lock (cache)
                cache.TryGetValue(builder, out item);

            if (item != null)
            {
                var outputs = item.Outputs;
                var paths = new HashSet<TargetRelativePath>();
                foreach (var pair in outputs)
                {
                    if (pair.Value != null)
                    {
                        using (var stream = targetRoot.CreateBinaryFile(pair.Key))
                            stream.Write(pair.Value, 0, pair.Value.Length);
                    }

                    paths.Add(pair.Key);
                }

                return paths;
            }
            else
            {
                return new HashSet<TargetRelativePath>();
            }
        }