Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #31 from mozilla-b2g/bail-if-thing-exists
Browse files Browse the repository at this point in the history
Bug 1177833 - Gaia shouldn't download b2g always r=aus
  • Loading branch information
Gareth Aye committed Jun 26, 2015
2 parents 7c265f1 + 3402f23 commit 732cf50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import detectOS from './detectos';
import detectURL from './detecturl';
import download from './download';
import extract from './extract';
import { readdir } from 'mz/fs';
import * as buildinfo from './moz_build_info';

debug = debug('mozilla-download/main');
Expand Down Expand Up @@ -47,6 +48,18 @@ parser.addArgument(['dest'], {

export default async function main(args=parser.parseArgs()) {
try {
// Bail if thing exists
try {
let contents = await readdir(args.dest);
if (contents && contents.length) {
// We have dest dir and it has contents
debug('Found b2g at dest', args.dest);
return;
}
} catch (error) {
}

debug('No b2g found. Will download to', args.dest);
let url = await detectURL(args);
debug('Artifact url', url);
let path = await download(url, args);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/b2g/random
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wha
14 changes: 13 additions & 1 deletion test/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import { tempdir } from '../src/temp';

suite('main', function() {
let cases = [
{
name: 'already exists',
args: {
product: 'b2g-desktop',
os: 'linux-x86_64',
branch: 'mozilla-central',
dest: `${__dirname}/fixtures/b2g`
},
verify: function() {
assert.deepEqual(fs.readdirSync(`${__dirname}/fixtures/b2g`), ['random']);
}
},
{
name: 'mozilla-central linux-x86_64 b2g-desktop opt',
args: {
Expand Down Expand Up @@ -97,7 +109,7 @@ suite('main', function() {
}

let dest = await tempdir();
testCase.args.dest = dest;
testCase.args.dest = testCase.args.dest || dest;
await main(testCase.args);
testCase.verify();
});
Expand Down

0 comments on commit 732cf50

Please sign in to comment.