private byte[] GetTransformedBinaryPackage(string workingDirectory, TransformedPackageMetadata metadata) { if (this.HasBinaryPackage(metadata)) { // We have it already downloaded in the cache. var file = Path.Combine( _packageCacheConfiguration.GetCacheDirectory(), this.GetPackageName(metadata)); using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { var data = new byte[stream.Length]; stream.Read(data, 0, data.Length); return(data); } } var packageData = metadata.Transformer.Transform( workingDirectory, metadata.SourceURI, metadata.GitRef, metadata.Platform, PackageManager.ARCHIVE_FORMAT_TAR_LZMA); if (packageData == null) { throw new InvalidOperationException("Unable to transform " + metadata.SourceURI + " for usage as a Protobuild package."); } var saveFile = Path.Combine( _packageCacheConfiguration.GetCacheDirectory(), this.GetPackageName(metadata)); var attempts = 10; while (attempts > 0) { try { using (var stream = new FileStream(saveFile, FileMode.Create, FileAccess.Write, FileShare.None)) { stream.Write(packageData, 0, packageData.Length); } break; } catch (IOException) { // On Windows, we can't write out the package file if another instance of Protobuild // is writing it out at the moment. Just wait and retry in another second. RedirectableConsole.WriteLine("WARNING: Unable to write downloaded package file (attempt " + (11 - attempts) + " / 10)"); System.Threading.Thread.Sleep(5000); attempts--; } } return(packageData); }
private void ResolveTransformed(string workingDirectory, TransformedPackageMetadata transformedMetadata, string folder, string templateName, bool forceUpgrade) { switch (transformedMetadata.PackageType) { case PackageManager.PACKAGE_TYPE_LIBRARY: ResolveLibraryBinary(workingDirectory, transformedMetadata, Path.Combine(workingDirectory, folder), forceUpgrade, () => { var package = GetTransformedBinaryPackage(workingDirectory, transformedMetadata); if (package == null) { throw new InvalidOperationException("Unable to transform " + transformedMetadata.SourceURI + " for usage as a Protobuild package."); } return(package); }); break; default: throw new InvalidOperationException("Unable to resolve binary package with type '" + transformedMetadata.PackageType + "' using transformer-based package."); } }
private void ResolveTransformed(TransformedPackageMetadata transformedMetadata, string folder, string templateName, bool forceUpgrade) { switch (transformedMetadata.PackageType) { case PackageManager.PACKAGE_TYPE_LIBRARY: ResolveLibraryBinary(transformedMetadata, folder, forceUpgrade, () => { var package = GetTransformedBinaryPackage(transformedMetadata); if (package == null) { throw new InvalidOperationException("Unable to transform " + transformedMetadata.SourceURI + " for usage as a Protobuild package."); } return package; }); break; default: throw new InvalidOperationException("Unable to resolve binary package with type '" + transformedMetadata.PackageType + "' using transformer-based package."); } }
private byte[] GetTransformedBinaryPackage(TransformedPackageMetadata metadata) { if (this.HasBinaryPackage(metadata)) { // We have it already downloaded in the cache. var file = Path.Combine( _packageCacheConfiguration.GetCacheDirectory(), this.GetPackageName(metadata)); using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { var data = new byte[stream.Length]; stream.Read(data, 0, data.Length); return data; } } var packageData = metadata.Transformer.Transform( metadata.SourceURI, metadata.GitRef, metadata.Platform, PackageManager.ARCHIVE_FORMAT_TAR_LZMA); if (packageData == null) { throw new InvalidOperationException("Unable to transform " + metadata.SourceURI + " for usage as a Protobuild package."); } var saveFile = Path.Combine( _packageCacheConfiguration.GetCacheDirectory(), this.GetPackageName(metadata)); var attempts = 10; while (attempts > 0) { try { using (var stream = new FileStream(saveFile, FileMode.Create, FileAccess.Write, FileShare.None)) { stream.Write(packageData, 0, packageData.Length); } break; } catch (IOException ex) { // On Windows, we can't write out the package file if another instance of Protobuild // is writing it out at the moment. Just wait and retry in another second. Console.WriteLine("WARNING: Unable to write downloaded package file (attempt " + (11 - attempts) + " / 10)"); System.Threading.Thread.Sleep(5000); attempts--; } } return packageData; }