Skip to content

Commit

Permalink
Add more debug logs for downloadTool function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana Kostromskaya authored Mar 21, 2022
1 parent 5dbfaf3 commit 55e3310
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 64 deletions.
12 changes: 6 additions & 6 deletions Strings/resources.resjson/de-DE/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "Tool wird zwischengespeichert: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Wird heruntergeladen: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Archiv wird extrahiert",
"loc.messages.TOOL_LIB_FoundInCache": "Tool im Zwischenspeicher gefunden: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Vorangestellte PATH-Umgebungsvariable mit Verzeichnis: %s"
{
"loc.messages.TOOL_LIB_CachingTool": "Tool wird zwischengespeichert: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Wird heruntergeladen: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Archiv wird extrahiert",
"loc.messages.TOOL_LIB_FoundInCache": "Tool im Zwischenspeicher gefunden: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Vorangestellte PATH-Umgebungsvariable mit Verzeichnis: %s"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/es-ES/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "Herramienta de almacenamiento en caché: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Descargando: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Extrayendo archivo",
"loc.messages.TOOL_LIB_FoundInCache": "Herramienta encontrada en caché: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Anteponiendo la variable de entorno de la ruta con el directorio: %s"
{
"loc.messages.TOOL_LIB_CachingTool": "Herramienta de almacenamiento en caché: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Descargando: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Extrayendo archivo",
"loc.messages.TOOL_LIB_FoundInCache": "Herramienta encontrada en caché: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Anteponiendo la variable de entorno de la ruta con el directorio: %s"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/fr-FR/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "Mise en cache de l’outil : %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Téléchargement : %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Extraction de l'archive",
"loc.messages.TOOL_LIB_FoundInCache": "Outil trouvé dans le cache : %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Préfixation de la variable d’environnement PATH avec le répertoire : %s"
{
"loc.messages.TOOL_LIB_CachingTool": "Mise en cache de l’outil : %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Téléchargement : %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Extraction de larchive",
"loc.messages.TOOL_LIB_FoundInCache": "Outil trouvé dans le cache : %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Préfixation de la variable d’environnement PATH avec le répertoire : %s"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/it-IT/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "Memorizzazione dello strumento %s %s %s nella cache",
"loc.messages.TOOL_LIB_Downloading": "Download di %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Estrazione dell'archivio",
"loc.messages.TOOL_LIB_FoundInCache": "Strumento %s %s %s trovato nella cache",
"loc.messages.TOOL_LIB_PrependPath": "Alla variabile di ambiente PATH verrà anteposta la directory %s"
{
"loc.messages.TOOL_LIB_CachingTool": "Memorizzazione dello strumento %s %s %s nella cache",
"loc.messages.TOOL_LIB_Downloading": "Download di %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Estrazione dell'archivio",
"loc.messages.TOOL_LIB_FoundInCache": "Strumento %s %s %s trovato nella cache",
"loc.messages.TOOL_LIB_PrependPath": "Alla variabile di ambiente PATH verrà anteposta la directory %s"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/ja-JP/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "キャッシュ ツール: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "ダウンロード中: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "アーカイブの展開中",
"loc.messages.TOOL_LIB_FoundInCache": "キャッシュでツールが見つかりました: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "ディレクトリを PATH 環境変数の前に付加しています: %s"
{
"loc.messages.TOOL_LIB_CachingTool": "キャッシュ ツール: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "ダウンロード中: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "アーカイブの展開中",
"loc.messages.TOOL_LIB_FoundInCache": "キャッシュでツールが見つかりました: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "ディレクトリを PATH 環境変数の前に付加しています: %s"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/ko-KR/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "도구를 캐시하는 중: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "다운로드 중: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "보관 파일의 압축을 푸는 중",
"loc.messages.TOOL_LIB_FoundInCache": "캐시에서 도구 발견: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "PATH 환경 변수 앞에 %s 디렉터리 추가"
{
"loc.messages.TOOL_LIB_CachingTool": "도구를 캐시하는 중: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "다운로드 중: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "보관 파일의 압축을 푸는 중",
"loc.messages.TOOL_LIB_FoundInCache": "캐시에서 도구 발견: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "PATH 환경 변수 앞에 %s 디렉터리 추가"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/ru-RU/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "Средство кэширования: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Идет скачивание: %s.",
"loc.messages.TOOL_LIB_ExtractingArchive": "Идет распаковка архива.",
"loc.messages.TOOL_LIB_FoundInCache": "Найдено средство в кэше: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Перед переменной окружения PATH добавляется каталог: %s"
{
"loc.messages.TOOL_LIB_CachingTool": "Средство кэширования: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "Скачивание: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "Идет распаковка архива",
"loc.messages.TOOL_LIB_FoundInCache": "Найдено средство в кэше: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "Перед переменной окружения PATH добавляется каталог: %s"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/zh-CN/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "正在缓存工具: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "正在下载: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "正在提取存档",
"loc.messages.TOOL_LIB_FoundInCache": "在缓存中找到工具: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "正在目录中预置 PATH 环境变量: %s"
{
"loc.messages.TOOL_LIB_CachingTool": "正在缓存工具: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "正在下载: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "正在提取存档",
"loc.messages.TOOL_LIB_FoundInCache": "在缓存中找到工具: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "正在目录中预置 PATH 环境变量: %s"
}
12 changes: 6 additions & 6 deletions Strings/resources.resjson/zh-TW/resources.resjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"loc.messages.TOOL_LIB_CachingTool": "正在快取工具: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "正在下載: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "正在解壓縮封存",
"loc.messages.TOOL_LIB_FoundInCache": "在快取中找到工具: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "正於 PATH 環境變數前加上目錄: %s"
{
"loc.messages.TOOL_LIB_CachingTool": "正在快取工具: %s %s %s",
"loc.messages.TOOL_LIB_Downloading": "正在下載: %s",
"loc.messages.TOOL_LIB_ExtractingArchive": "正在解壓縮封存",
"loc.messages.TOOL_LIB_FoundInCache": "在快取中找到工具: %s %s %s",
"loc.messages.TOOL_LIB_PrependPath": "正於 PATH 環境變數前加上目錄: %s"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-pipelines-tool-lib",
"version": "1.2.0",
"version": "1.2.1",
"description": "Azure Pipelines Tool Installer Lib for CI/CD Tasks",
"main": "tool.js",
"scripts": {
Expand Down
47 changes: 39 additions & 8 deletions tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,10 @@ export async function downloadTool(

// check if it's an absolute path already
var destPath: string;
if(path.isAbsolute(fileName))
{
if (path.isAbsolute(fileName)) {
destPath = fileName;
}
else
{
else {
destPath = path.join(_getAgentTemp(), fileName);
}

Expand All @@ -235,21 +233,30 @@ export async function downloadTool(

tl.debug('downloading');
let response: httpm.HttpClientResponse = await http.get(url, additionalHeaders);

if (response.message.statusCode != 200) {
let err: Error = new Error('Unexpected HTTP response: ' + response.message.statusCode);
err['httpStatusCode'] = response.message.statusCode;
tl.debug(`Failed to download "${fileName}" from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
throw err;
}

let downloadedContentLength = _getContentLengthOfDownloadedFile(response.message.headers['content-length']);

tl.debug('creating stream');
let file: NodeJS.WritableStream = fs.createWriteStream(destPath);
file.on('open', async (fd) => {
try {
let stream = response.message.pipe(file);
stream.on('close', () => {
tl.debug('download complete');
let fileSizeInBytes = _getFileSizeOnDisk(destPath);
if (!isNaN(downloadedContentLength) &&
!isNaN(fileSizeInBytes) &&
fileSizeInBytes !== downloadedContentLength) {
reject(new Error(`Content-Length (${downloadedContentLength} bytes) did not match downloaded file size (${fileSizeInBytes} bytes).`));
}

resolve(destPath);
});
}
Expand All @@ -260,14 +267,38 @@ export async function downloadTool(
file.on('error', (err) => {
file.end();
reject(err);
})
});
}
catch (error) {
reject(error);
}
});
}

function _getContentLengthOfDownloadedFile(contentLengthHeader: string | undefined): number {
let parsedContentLength = parseInt(contentLengthHeader);
if (!isNaN(parsedContentLength)) {
tl.debug(`Content-Length of downloaded file: ${parsedContentLength}`);
} else {
tl.debug(`Content-Length header missing.`);
}

return parsedContentLength;
}

function _getFileSizeOnDisk(filePath: string): number {
try {
let fileStats = fs.statSync(filePath);
let fileSizeInBytes = fileStats.size;
tl.debug(`Downloaded file size: ${fileSizeInBytes} bytes`);
return fileSizeInBytes;
}
catch (err) {
tl.debug(`Unable to find file size for ${filePath}`);
return NaN;
}
}

//---------------------
// Install Functions
//---------------------
Expand Down Expand Up @@ -502,7 +533,7 @@ function _createExtractFolder(dest?: string): string {
}

tl.mkdirP(dest);

return dest;
}

Expand Down Expand Up @@ -559,4 +590,4 @@ function _getAgentTemp(): string {
}

return tempDirectory;
}
}

0 comments on commit 55e3310

Please sign in to comment.