Skip to content

Commit 988c7ec

Browse files
committed
Grab scanfile header infomation in new format #323
Signed-off-by: Steven Esser <[email protected]>
1 parent dc9e330 commit 988c7ec

File tree

4 files changed

+5600
-2
lines changed

4 files changed

+5600
-2
lines changed

assets/app/js/aboutCodeDB.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,14 @@ class AboutCodeDB {
260260
stream
261261
.pipe(JSONStream.parse('files.*'))
262262
.on('header', (header) => {
263-
if ('header' in header) {
264-
header = header.header;
263+
if ('headers' in header) {
264+
// FIXME: This should be smarter
265+
const header_data = header.headers[0];
266+
header = {
267+
scancode_notice: header_data.notice,
268+
scancode_version: header_data.tool_version,
269+
scancode_options: header_data.options
270+
};
265271
}
266272
$.extend(header, {
267273
aboutcode_manager_version: version,

test/aboutCodeDB.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,36 @@ describe('checkAboutCodeDB', () => {
197197
.then(() => aboutCodeDB.db.Url.count())
198198
.then((urlCount) => assert.strictEqual(urlCount, 30));
199199
});
200+
it('should get header information from a legacy scan file', () => {
201+
const test_file = __dirname + '/data/aboutcodeDB/legacy-header.json';
202+
const aboutCodeDB = new AboutCodeDB();
203+
204+
return aboutCodeDB.sync
205+
.then(() => aboutCodeDB.db.File.count())
206+
.then((rowCount) => assert.strictEqual(rowCount, 0))
207+
.then(() => aboutCodeDB.addFromJson(test_file))
208+
.then(() => aboutCodeDB.db.Header.findOne({where: {id: 1}}))
209+
.then((header) => {
210+
assert.strictEqual(header.scancode_version, '2.9.2');
211+
assert.isNotNull(header.scancode_notice);
212+
assert.isNotNull(header.scancode_options);
213+
});
214+
});
215+
it('should get header information from a v2.9.8 scan file', () => {
216+
const test_file = __dirname + '/data/aboutcodeDB/2.9.8-header.json';
217+
const aboutCodeDB = new AboutCodeDB();
218+
219+
return aboutCodeDB.sync
220+
.then(() => aboutCodeDB.db.File.count())
221+
.then((rowCount) => assert.strictEqual(rowCount, 0))
222+
.then(() => aboutCodeDB.addFromJson(test_file))
223+
.then(() => aboutCodeDB.db.Header.findOne({where: {id: 1}}))
224+
.then((header) => {
225+
assert.strictEqual(header.scancode_version, '2.9.8');
226+
assert.isNotNull(header.scancode_notice);
227+
assert.isNotNull(header.scancode_options);
228+
});
229+
});
200230
});
201231

202232
describe('getDuplicatePaths', () => {

0 commit comments

Comments
 (0)