private CodePackageType GetPackageType(string filePath, RunFromPackageContext pkgContext) { // cloud build always builds squashfs if (pkgContext.IsScmRunFromPackage()) { return(CodePackageType.Squashfs); } var uri = new Uri(pkgContext.Url); // check file name since it'll be faster than running `file` if (FileIsAny(_knownPackageExtensions)) { return(CodePackageType.Squashfs); } else if (FileIsAny(".zip")) { return(CodePackageType.Zip); } // Check file magic-number using `file` command. (var output, _, _) = _bashCommandHandler.RunBashCommand($"{BashCommandHandler.FileCommand} -b {filePath}", MetricEventNames.LinuxContainerSpecializationFileCommand); if (output.StartsWith(SquashfsPrefix, StringComparison.OrdinalIgnoreCase)) { return(CodePackageType.Squashfs); } else if (output.StartsWith(ZipPrefix, StringComparison.OrdinalIgnoreCase)) { return(CodePackageType.Zip); } else { throw new InvalidOperationException($"Can't find CodePackageType to match {filePath}"); } bool FileIsAny(params string[] options) => options.Any(o => uri.AbsolutePath.EndsWith(o, StringComparison.OrdinalIgnoreCase)); }
private void AriaDownload(string directory, string fileName, Uri zipUri, bool isWarmupRequest, string downloadMetricName) { (string stdout, string stderr, int exitCode) = _bashCommandHandler.RunBashCommand( $"{Aria2CExecutable} --allow-overwrite -x12 -d {directory} -o {fileName} '{zipUri}'", downloadMetricName); if (exitCode != 0) { var msg = $"Error downloading package. stdout: {stdout}, stderr: {stderr}, exitCode: {exitCode}"; _logger.LogError(msg); throw new InvalidOperationException(msg); } var fileInfo = FileUtility.FileInfoFromFileName(Path.Combine(directory, fileName)); _logger.LogInformation("'{fileInfo.Length}' bytes downloaded. IsWarmupRequest = '{isWarmupRequest}'", fileInfo.Length, isWarmupRequest); }