@@ -55,6 +55,7 @@ import { TodoAttributes } from "./models/todo";
5555import { HeaderAttributes } from "./models/header" ;
5656import { LicenseReferenceAttributes } from "./models/licenseReference" ;
5757import { LicenseRuleReferenceAttributes } from "./models/licenseRuleReference" ;
58+ import { NO_RESOURCES_ERROR } from "../constants/errors" ;
5859
5960const { version : workbenchVersion } = packageJson ;
6061
@@ -309,8 +310,6 @@ export class WorkbenchDB {
309310 const stream = fs . createReadStream ( jsonFilePath , { encoding : "utf8" } ) ;
310311 let files_count = 0 ;
311312 let dirs_count = 0 ;
312- let rootPath : string | null = null ;
313- let hasRootPath = false ;
314313 const batchSize = 1000 ;
315314 let files : Resource [ ] = [ ] ;
316315 const parsedFilePaths = new Set < string > ( ) ;
@@ -380,12 +379,6 @@ export class WorkbenchDB {
380379 . on ( "data" , function ( file ?: Resource ) {
381380 if ( ! file ) return ;
382381
383- if ( ! rootPath ) {
384- rootPath = file . path . split ( "/" ) [ 0 ] ;
385- }
386- if ( rootPath === file . path ) {
387- hasRootPath = true ;
388- }
389382 // @TODO : When/if scancode reports directories in its header, this needs
390383 // to be replaced.
391384 if ( parsedFilePaths . size === 0 ) {
@@ -435,21 +428,14 @@ export class WorkbenchDB {
435428 // Add root directory into data
436429 // See https://github.com/nexB/scancode-toolkit/issues/543
437430 promiseChain
438- . then ( ( ) => {
439- if ( ! hasRootPath ) {
440- rootPath = rootPath || "no-files" ;
441- files . push ( {
442- path : rootPath ,
443- name : rootPath ,
444- type : "directory" ,
445- files_count : files_count ,
446- } ) ;
447- parsedFilePaths . add ( rootPath ) ;
448- }
449- } )
450431 . then ( ( ) =>
451432 this . _imputeIntermediateDirectories ( files , parsedFilePaths )
452433 )
434+ . then ( ( ) => {
435+ if ( files . length === 0 ) {
436+ throw new Error ( NO_RESOURCES_ERROR ) ;
437+ }
438+ } )
453439 . then ( ( ) => this . _batchCreateFiles ( files ) )
454440 . then ( ( ) => this . db . Header . create ( TopLevelData . parsedHeader ) )
455441 . then ( ( ) => {
@@ -470,10 +456,12 @@ export class WorkbenchDB {
470456 . then ( ( ) => {
471457 onProgressUpdate ( 100 ) ;
472458 console . info ( "JSON parse completed (final step)" ) ;
473- console . timeEnd ( "json-parse-time" ) ;
474459 resolve ( ) ;
475460 } )
476- . catch ( ( e : unknown ) => reject ( e ) ) ;
461+ . catch ( ( e : unknown ) => reject ( e ) )
462+ . finally ( ( ) => {
463+ console . timeEnd ( "json-parse-time" ) ;
464+ } ) ;
477465 } )
478466 . on ( "error" , ( err : unknown ) => {
479467 console . error (
0 commit comments