@@ -12,7 +12,7 @@ import { ProgressCallback, showAndLogErrorMessage, withProgress, showAndLogInfor
1212 * @param databasesManager the DatabaseManager
1313 * @param storagePath where to store the unzipped database.
1414 */
15- export async function promptImportInternetDatabase ( databasesManager : DatabaseManager , storagePath : string ) : Promise < DatabaseItem | undefined > {
15+ export async function promptImportInternetDatabase ( databasesManager : DatabaseManager , storagePath : string ) : Promise < DatabaseItem | undefined > {
1616 let item : DatabaseItem | undefined = undefined ;
1717
1818 try {
@@ -46,7 +46,7 @@ export async function promptImportInternetDatabase(databasesManager: DatabaseMan
4646 * @param databasesManager the DatabaseManager
4747 * @param storagePath where to store the unzipped database.
4848 */
49- export async function importArchiveDatabase ( databaseUrl : string , databasesManager : DatabaseManager , storagePath : string ) : Promise < DatabaseItem | undefined > {
49+ export async function importArchiveDatabase ( databaseUrl : string , databasesManager : DatabaseManager , storagePath : string ) : Promise < DatabaseItem | undefined > {
5050 let item : DatabaseItem | undefined = undefined ;
5151 try {
5252 const progressOptions : ProgressOptions = {
@@ -106,7 +106,7 @@ async function databaseArchiveFetcher(
106106 // find the path to the database. The actual database might be in a sub-folder
107107 const dbPath = await findDirWithFile ( unzipPath , '.dbinfo' , 'codeql-database.yml' ) ;
108108 if ( dbPath ) {
109- const item = await databasesManager . openDatabase ( Uri . parse ( dbPath ) ) ;
109+ const item = await databasesManager . openDatabase ( Uri . parse ( `file: ${ dbPath } ` ) ) ;
110110 databasesManager . setCurrentDatabaseItem ( item ) ;
111111 return item ;
112112 } else {
@@ -115,14 +115,21 @@ async function databaseArchiveFetcher(
115115}
116116
117117async function getStorageFolder ( storagePath : string , urlStr : string ) {
118+ // we need to generate a folder name for the unzipped archive,
119+ // this needs to be human readable since we may use this name as the initial
120+ // name for the database
118121 const url = Uri . parse ( urlStr ) ;
119- let lastName = path . basename ( url . path ) . substring ( 0 , 255 ) ;
122+ // MacOS has a max filename length of 255
123+ // and remove a few extra chars in case we need to add a counter at the end.
124+ let lastName = path . basename ( url . path ) . substring ( 0 , 250 ) ;
120125 if ( lastName . endsWith ( ".zip" ) ) {
121126 lastName = lastName . substring ( 0 , lastName . length - 4 ) ;
122127 }
123128
124129 const realpath = await fs . realpath ( storagePath ) ;
125130 let folderName = path . join ( realpath , lastName ) ;
131+
132+ // avoid overwriting existing folders
126133 let counter = 0 ;
127134 while ( await fs . pathExists ( folderName ) ) {
128135 counter ++ ;
@@ -155,7 +162,7 @@ async function readAndUnzip(databaseUrl: string, unzipPath: string) {
155162
156163 await new Promise ( ( resolve , reject ) => {
157164 // we already know this is a file scheme
158- const databaseFile = Uri . parse ( databaseUrl ) . path ;
165+ const databaseFile = Uri . parse ( databaseUrl ) . fsPath ;
159166 const stream = fs . createReadStream ( databaseFile ) ;
160167 stream . on ( 'error' , reject ) ;
161168 unzipStream . on ( 'error' , reject ) ;
0 commit comments