@@ -82,6 +82,10 @@ function eventFired<T>(
8282}
8383
8484type OpenDatabaseOptions = {
85+ /**
86+ * A location that is managed by the extension.
87+ */
88+ extensionManagedLocation ?: string ;
8589 isTutorialDatabase ?: boolean ;
8690 /**
8791 * Whether to add a workspace folder containing the source archive to the workspace. Default is true.
@@ -141,6 +145,7 @@ export class DatabaseManager extends DisposableObject {
141145 makeSelected = true ,
142146 displayName ?: string ,
143147 {
148+ extensionManagedLocation,
144149 isTutorialDatabase = false ,
145150 addSourceArchiveFolder = addDatabaseSourceToWorkspace ( ) ,
146151 } : OpenDatabaseOptions = { } ,
@@ -149,6 +154,7 @@ export class DatabaseManager extends DisposableObject {
149154 uri ,
150155 origin ,
151156 displayName ,
157+ extensionManagedLocation ,
152158 ) ;
153159
154160 return await this . addExistingDatabaseItem (
@@ -202,6 +208,7 @@ export class DatabaseManager extends DisposableObject {
202208 uri : vscode . Uri ,
203209 origin : DatabaseOrigin | undefined ,
204210 displayName : string | undefined ,
211+ extensionManagedLocation ?: string ,
205212 ) : Promise < DatabaseItemImpl > {
206213 const contents = await DatabaseResolver . resolveDatabaseContents ( uri ) ;
207214 const fullOptions : FullDatabaseOptions = {
@@ -210,6 +217,7 @@ export class DatabaseManager extends DisposableObject {
210217 dateAdded : Date . now ( ) ,
211218 language : await this . getPrimaryLanguage ( uri . fsPath ) ,
212219 origin,
220+ extensionManagedLocation,
213221 } ;
214222 const databaseItem = new DatabaseItemImpl ( uri , contents , fullOptions ) ;
215223
@@ -370,6 +378,7 @@ export class DatabaseManager extends DisposableObject {
370378 let dateAdded = undefined ;
371379 let language = undefined ;
372380 let origin = undefined ;
381+ let extensionManagedLocation = undefined ;
373382 if ( state . options ) {
374383 if ( typeof state . options . displayName === "string" ) {
375384 displayName = state . options . displayName ;
@@ -379,6 +388,7 @@ export class DatabaseManager extends DisposableObject {
379388 }
380389 language = state . options . language ;
381390 origin = state . options . origin ;
391+ extensionManagedLocation = state . options . extensionManagedLocation ;
382392 }
383393
384394 const dbBaseUri = vscode . Uri . parse ( state . uri , true ) ;
@@ -392,6 +402,7 @@ export class DatabaseManager extends DisposableObject {
392402 dateAdded,
393403 language,
394404 origin,
405+ extensionManagedLocation,
395406 } ;
396407 const item = new DatabaseItemImpl ( dbBaseUri , undefined , fullOptions ) ;
397408
@@ -583,15 +594,20 @@ export class DatabaseManager extends DisposableObject {
583594 // Remove this database item from the allow-list
584595 await this . deregisterDatabase ( item ) ;
585596
597+ // Find whether we know directly which directory we should remove
598+ const directoryToRemove = item . extensionManagedLocation
599+ ? vscode . Uri . file ( item . extensionManagedLocation )
600+ : item . databaseUri ;
601+
586602 // Delete folder from file system only if it is controlled by the extension
587- if ( this . isExtensionControlledLocation ( item . databaseUri ) ) {
603+ if ( this . isExtensionControlledLocation ( directoryToRemove ) ) {
588604 void extLogger . log ( "Deleting database from filesystem." ) ;
589- await remove ( item . databaseUri . fsPath ) . then (
590- ( ) => void extLogger . log ( `Deleted '${ item . databaseUri . fsPath } '` ) ,
605+ await remove ( directoryToRemove . fsPath ) . then (
606+ ( ) => void extLogger . log ( `Deleted '${ directoryToRemove . fsPath } '` ) ,
591607 ( e : unknown ) =>
592608 void extLogger . log (
593609 `Failed to delete '${
594- item . databaseUri . fsPath
610+ directoryToRemove . fsPath
595611 } '. Reason: ${ getErrorMessage ( e ) } `,
596612 ) ,
597613 ) ;
0 commit comments