예제 #1
0
        public void Load(FileStream stream)
        {
            using (var reader = new PrimitiveReader(stream, false))
            {
                foreach (var provider in providers)
                {
                    var tempFile = TemporaryFilesManager.Instance.GetTemporaryFile();
                    if (ConfigurationManager.Instance.Get("file-system", "use-cow", false))
                    {
                        FileCopier.Copy(stream.Name, tempFile, true);

                        var size          = reader.ReadInt64();
                        var localPosition = stream.Position;
                        reader.ReadBytes((int)size);
                        provider.BlobIsReady(tempFile, localPosition, size);
                    }
                    else
                    {
                        var size = reader.ReadInt64();
                        using (var fileStream = new FileStream(tempFile, FileMode.OpenOrCreate))
                        {
                            reader.CopyTo(fileStream, size);
                        }
                        provider.BlobIsReady(tempFile, 0, size);
                    }
                }
            }
        }
 private bool UpdateInCache(Uri uri, string withFile)
 {
     using (var progressHandler = EmulationManager.Instance.ProgressMonitor.Start("Updating cache"))
     {
         lock (CacheDirectory)
         {
             var         index = ReadBinariesIndex();
             BinaryEntry entry;
             var         fileId = 0;
             if (!index.TryGetValue(uri, out entry))
             {
                 foreach (var element in index)
                 {
                     fileId = Math.Max(fileId, element.Value.Index) + 1;
                 }
             }
             else
             {
                 fileId = entry.Index;
             }
             FileCopier.Copy(withFile, GetBinaryFileName(fileId), true);
             long size;
             var  checksum = GetChecksumAndSizeFromUri(uri, out size);
             entry = new BinaryEntry(fileId, size, checksum);
             if (!Verify(withFile, entry))
             {
                 return(false);
             }
             index[uri] = entry;
             WriteBinariesIndex(index);
             return(true);
         }
     }
 }
예제 #3
0
        private void UpdateInCache(Uri uri, string withFile)
        {
            using (var progressHandler = EmulationManager.Instance.ProgressMonitor.Start("Updating cache"))
            {
                lock (CacheDirectory)
                {
                    var         index = ReadBinariesIndex();
                    BinaryEntry entry;
                    var         fileId = 0;
                    if (!index.TryGetValue(uri, out entry))
                    {
                        foreach (var element in index)
                        {
                            fileId = Math.Max(fileId, element.Value.Index) + 1;
                        }
                    }
                    else
                    {
                        fileId = entry.Index;
                    }
                    FileCopier.Copy(withFile, GetBinaryFileName(fileId), true);

                    // checksum will be 'null' if the uri pattern does not contain
                    // checksum/size information
                    TryGetChecksumAndSizeFromUri(uri, out var checksum, out var size);
                    index[uri] = new BinaryEntry(fileId, size, checksum);
                    WriteBinariesIndex(index);
                }
            }
        }
예제 #4
0
        public void StoreEntryWithSha(string sha, string filename)
        {
            if (!Enabled || ContainsEntryWithSha(sha))
            {
                return;
            }

            EnsureCacheDirectory();
            using (var locker = new FileLocker(Path.Combine(cacheLocation, lockFileName)))
            {
                FileCopier.Copy(filename, Path.Combine(cacheLocation, sha), true);
                internalCache.Add(sha);
            }
        }
 private bool TryGetFromCache(Uri uri, out string fileName)
 {
     lock (CacheDirectory)
     {
         fileName = null;
         var         index = ReadBinariesIndex();
         BinaryEntry entry;
         if (!index.TryGetValue(uri, out entry))
         {
             return(false);
         }
         var fileToCopy = GetBinaryFileName(entry.Index);
         if (!Verify(fileToCopy, entry))
         {
             return(false);
         }
         fileName = TemporaryFilesManager.Instance.GetTemporaryFile();
         FileCopier.Copy(GetBinaryFileName(entry.Index), fileName, true);
         return(true);
     }
 }