Exemplo n.º 1
0
            void checksumPackage(ReleaseEntry downloadedRelease)
            {
                var targetPackage = new FileInfo(
                    Path.Combine(rootAppDirectory, "packages", downloadedRelease.Filename));

                if (!targetPackage.Exists)
                {
                    this.Log().Error("File {0} should exist but doesn't", targetPackage.FullName);

                    throw new Exception("Checksummed file doesn't exist: " + targetPackage.FullName);
                }

                if (targetPackage.Length != downloadedRelease.Filesize)
                {
                    this.Log().Error("File Length should be {0}, is {1}", downloadedRelease.Filesize, targetPackage.Length);
                    targetPackage.Delete();

                    throw new Exception("Checksummed file size doesn't match: " + targetPackage.FullName);
                }

                using (var file = targetPackage.OpenRead()) {
                    var hash = Utility.CalculateStreamSHA1(file);

                    if (!hash.Equals(downloadedRelease.SHA1, StringComparison.OrdinalIgnoreCase))
                    {
                        this.Log().Error("File SHA1 should be {0}, is {1}", downloadedRelease.SHA1, hash);
                        targetPackage.Delete();
                        throw new Exception("Checksum doesn't match: " + targetPackage.FullName);
                    }
                }
            }
Exemplo n.º 2
0
        Task <IDisposable> acquireUpdateLock()
        {
            if (updateLock != null)
            {
                return(Task.FromResult(updateLock));
            }

            return(Task.Run(() => {
                var key = Utility.CalculateStreamSHA1(new MemoryStream(Encoding.UTF8.GetBytes(rootAppDirectory)));

                IDisposable theLock;
                try {
                    theLock = ModeDetector.InUnitTestRunner() ?
                              Disposable.Create(() => {}) : new SingleGlobalInstance(key, TimeSpan.FromMilliseconds(2000));
                } catch (TimeoutException) {
                    throw new TimeoutException("Couldn't acquire update lock, another instance may be running updates");
                }

                var ret = Disposable.Create(() => {
                    theLock.Dispose();
                    updateLock = null;
                });

                updateLock = ret;
                return ret;
            }));
        }
Exemplo n.º 3
0
        public static ReleaseEntry GenerateFromFile(Stream file, string filename, string baseUrl = null)
        {
            Contract.Requires(file != null && file.CanRead);
            Contract.Requires(!String.IsNullOrEmpty(filename));

            var hash = Utility.CalculateStreamSHA1(file);

            return(new ReleaseEntry(hash, filename, file.Length, filenameIsDeltaFile(filename), baseUrl));
        }
Exemplo n.º 4
0
            bool isPackageOk(ReleaseEntry downloadedRelease)
            {
                var targetPackage = new FileInfo(
                    Path.Combine(rootAppDirectory, "packages", downloadedRelease.Filename));

                if (!targetPackage.Exists)
                {
                    return(false);
                }

                if (targetPackage.Length != downloadedRelease.Filesize)
                {
                    return(false);
                }

                using (var file = targetPackage.OpenRead()) {
                    var hash = Utility.CalculateStreamSHA1(file);
                    return(hash.Equals(downloadedRelease.SHA1, StringComparison.OrdinalIgnoreCase));
                }
            }
Exemplo n.º 5
0
 public static ReleaseEntry GenerateFromFile(Stream file, string filename, string baseUrl = null) =>
 new ReleaseEntry(Utility.CalculateStreamSHA1(file), filename, file.Length, filenameIsDeltaFile(filename), baseUrl, null);