Example #1
0
        public bool TryGet(LfxHash hash, out LfxBlob blob)
        {
            // try local store
            blob = default(LfxBlob);
            if (m_store.TryGet(hash, out blob))
            {
                return(true);
            }

            // no parent, no hope
            if (m_parentCache == null)
            {
                return(false);
            }

            // try parent store
            LfxBlob parentBlob;

            if (!m_parentCache.TryGet(hash, out parentBlob))
            {
                return(false);
            }

            // promote to local store
            blob = m_store.Add(parentBlob);
            return(true);
        }
Example #2
0
        public static LfxPointer Create(Stream stream)
        {
            stream = new StreamCounter(stream);
            var hash  = LfxHash.Compute(stream);
            var count = stream.Position;

            return(Create(hash, count));
        }
Example #3
0
 private string GetPath(LfxHash hash)
 {
     return(Path.Combine(
                m_dir,
                hash.ToString().Substring(0, 2),
                hash.ToString().Substring(2, 2),
                hash
                ));
 }
Example #4
0
        public static LfxPointer Create(LfxHash hash, long count)
        {
            var pointer = new LfxPointer();

            pointer.Add(VersionKey, Version1Uri.ToString());
            pointer.Add(SizeKey, $"{count}");
            pointer.Add(OidKey, $"{OidHashMethodSha256}:{hash}");
            return(pointer);
        }
Example #5
0
        public bool TryGet(LfxHash hash, out LfxBlob blob)
        {
            blob = default(LfxBlob);
            var path = GetPath(hash);

            if (!File.Exists(path))
            {
                return(false);
            }
            blob = new LfxBlob(this, hash, path);
            return(true);
        }
Example #6
0
        private LfxBlob Add(Stream stream, LfxHash hash)
        {
            // insert
            var path = GetPath(hash);

            if (!File.Exists(path))
            {
                IODirectory.CreateDirectory(Path.GetDirectoryName(path));
                using (var targetStream = File.OpenWrite(path))
                    stream.CopyTo(targetStream);
            }

            return(new LfxBlob(this, hash, path));
        }
Example #7
0
 internal LfxBlob(LfxBlobStore store, LfxHash hash, string path)
 {
     m_store = store;
     m_hash  = hash;
     m_file  = path;
 }
Example #8
0
        public bool Promote(LfxHash hash)
        {
            LfxBlob blob;

            return(TryGet(hash, out blob));
        }
Example #9
0
 public bool Equals(LfxHash other) => m_value != null && m_value == other.m_value;
Example #10
0
 public static LfxHash ComputeHash(this byte[] bytes, int count) => LfxHash.Compute(bytes, count);
Example #11
0
 public static LfxHash ComputeHash(this byte[] bytes) => LfxHash.Compute(bytes);
Example #12
0
 public static LfxHash ComputeHash(this Stream stream) => LfxHash.Compute(stream);
Example #13
0
 public static LfxHash ComputeHash(this string value) => LfxHash.Compute(value);
Example #14
0
        public bool Contains(LfxHash hash)
        {
            LfxBlob blob;

            return(TryGet(hash, out blob));
        }
Example #15
0
 public IEnumerator <LfxBlob> GetEnumerator()
 {
     return(Files
            .Select(o => new LfxBlob(this, LfxHash.Parse(Path.GetFileName(o)), o))
            .GetEnumerator());
 }
Example #16
0
        public static LfxPointer Create(string path, LfxHash?hash = null)
        {
            LfxPointer pointer;

            var length = new FileInfo(path).Length;

            if (hash == null)
            {
                hash = LfxHash.Compute(path);
            }
            pointer = Create(hash.Value, length);

            var config = LfxConfig.Load(path);

            // simple
            if (config.Type == LfxPointerType.Simple)
            {
                return(pointer);
            }

            var url     = config.Url;
            var relPath = config.ConfigFile.Path.MakeRelativePath(path);

            if (config.HasPattern)
            {
                // change base of relPath to config file containing pattern
                relPath = config.Pattern.ConfigFile.Path.MakeRelativePath(path);
                url     = Regex.Replace(
                    input: relPath,
                    pattern: config.Pattern,
                    replacement: config.Url
                    );
            }

            // curl
            if (config.Type == LfxPointerType.Curl)
            {
                return(pointer.AddUrl(url.ToUrl()));
            }

            // default hint is relPath
            var hint = relPath;

            if (config.HasHint)
            {
                // hardcoded hint (very rare)
                hint = config.Hint.Value;
                if (config.HasPattern)
                {
                    // substituted hint (nuget case)
                    hint = Regex.Replace(
                        input: relPath,
                        pattern: config.Pattern,
                        replacement: config.Hint
                        );
                }
            }

            // archive
            if (config.Type == LfxPointerType.Archive)
            {
                return(pointer.AddArchive(url.ToUrl(), hint));
            }

            // self extracting archive
            return(pointer.AddSelfExtractingArchive(url.ToUrl(), hint, config.Args));
        }