Skip to content

Commit e5c65b6

Browse files
author
Tatyana Kostromskaya
authored
Resolve comments
1 parent f99e312 commit e5c65b6

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

test/units/toolTests.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,6 @@ describe('Tool Tests', function () {
132132
});
133133
});
134134

135-
it('different content-length and file size on disk', async function() {
136-
const headers: nock.ReplyHeaders = { 'content-length': '200' };
137-
nock('https://microsoft.com')
138-
.get('/bytes/36')
139-
.reply(200, {
140-
username: 'bad',
141-
password: 'size'
142-
}, headers);
143-
144-
return new Promise<void>(async(resolve, reject)=> {
145-
try {
146-
let errorCodeUrl: string = "https://microsoft.com/bytes/36";
147-
let downPath: string = await toolLib.downloadTool(errorCodeUrl);
148-
149-
reject('content-length of file and size of file on disk should not match, but they do');
150-
}
151-
catch (err){
152-
assert.equal(err.message, `Content-Length (200 bytes) did not match downloaded file size (36 bytes).`);
153-
resolve();
154-
}
155-
});
156-
});
157-
158135
it('works with redirect code 302', async function () {
159136
nock('https://microsoft.com')
160137
.get('/redirect-to')

tool.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,15 @@ export async function downloadTool(
255255
let stream = response.message.pipe(file);
256256
stream.on('close', () => {
257257
tl.debug('download complete');
258-
let fileSizeInBytes = _getFileSizeOnDisk(destPath);
258+
let fileSizeInBytes: number;
259+
try {
260+
fileSizeInBytes = _getFileSizeOnDisk(destPath);
261+
}
262+
catch (err) {
263+
fileSizeInBytes = NaN;
264+
tl.warning(`Unable to check file size of ${destPath} due to error: ${err.Message}`);
265+
}
266+
259267
if (!isNaN(fileSizeInBytes)) {
260268
tl.debug(`Downloaded file size: ${fileSizeInBytes} bytes`);
261269
} else {
@@ -265,8 +273,7 @@ export async function downloadTool(
265273
if (!isNaN(downloadedContentLength) &&
266274
!isNaN(fileSizeInBytes) &&
267275
fileSizeInBytes !== downloadedContentLength) {
268-
let err: Error = new Error(`Content-Length (${downloadedContentLength} bytes) did not match downloaded file size (${fileSizeInBytes} bytes).`);
269-
reject(err);
276+
tl.warning(`Content-Length (${downloadedContentLength} bytes) did not match downloaded file size (${fileSizeInBytes} bytes).`);
270277
}
271278

272279
resolve(destPath);
@@ -308,15 +315,9 @@ function _getContentLengthOfDownloadedFile(response: httpm.HttpClientResponse):
308315
* @param filePath the path to the file, saved to the disk
309316
*/
310317
function _getFileSizeOnDisk(filePath: string): number {
311-
try {
312-
let fileStats = fs.statSync(filePath);
313-
let fileSizeInBytes = fileStats.size;
314-
return fileSizeInBytes;
315-
}
316-
catch (err) {
317-
tl.warning(`Unable to find file size for ${filePath} due to error: ${err.Message}`);
318-
return NaN;
319-
}
318+
let fileStats = fs.statSync(filePath);
319+
let fileSizeInBytes = fileStats.size;
320+
return fileSizeInBytes;
320321
}
321322

322323
//---------------------

0 commit comments

Comments
 (0)