@@ -142,22 +142,27 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
142142 dirHandle = await dirHandle . getDirectoryHandle ( folder , { create : isReadWrite } ) ;
143143 }
144144 }
145- const fileHandle = await dirHandle . getFileHandle ( fileName , { create : false } ) . catch ( e => {
145+ let fileHandle :FileSystemFileHandle ;
146+ try {
147+ fileHandle = await dirHandle . getFileHandle ( fileName , { create : false } ) ;
148+ } catch ( e :any ) {
146149 if ( e ?. name === 'NotFoundError' ) {
147150 if ( isReadWrite ) {
148- console . debug ( `File ${ path } does not exists yet, creating...` ) ;
149- return dirHandle . getFileHandle ( fileName , { create : true } ) ;
151+ console . debug ( `File ${ path } does not exists yet, creating...` ) ;
152+ fileHandle = await dirHandle . getFileHandle ( fileName , { create : true } ) ;
153+ } else {
154+ console . debug ( `File ${ path } does not exists, aborting as we are in read-only mode` ) ;
155+ throw e ;
150156 }
151- console . debug ( `File ${ path } does not exists, aborting as we are in read-only mode` ) ;
157+ } else {
158+ throw e ;
152159 }
153- throw e ;
154- } ) ;
160+ }
155161 try {
156- let createSyncAccessMode :'read-only' | 'readwrite' | 'readwrite-unsafe' = "read-only" ;
157- if ( isReadWrite ) {
158- createSyncAccessMode = isReadWrite ? "readwrite" : "readwrite-unsafe" ;
159- }
160- const handle = await fileHandle . createSyncAccessHandle ( createSyncAccessMode ) ;
162+ let syncAccessHandleMode :FileSystemSyncAccessHandleMode = isReadWrite ? "readwrite" : "readwrite-unsafe" ;
163+ const handle = await fileHandle . createSyncAccessHandle ( {
164+ mode : syncAccessHandleMode
165+ } ) ;
161166 BROWSER_RUNTIME . _preparedHandles [ path ] = handle ;
162167 return {
163168 path,
@@ -178,10 +183,10 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
178183 throw new Error ( `Unsupported protocol ${ protocol } for paths ${ filePaths } with protocol ${ protocol } ` ) ;
179184 } ,
180185 /** Prepare a file handle that could only be acquired asynchronously */
181- async prepareDBFileHandle ( dbPath : string , protocol : DuckDBDataProtocol , accessMode : DuckDBAccessMode ) : Promise < PreparedDBFileHandle [ ] > {
186+ async prepareDBFileHandle ( dbPath : string , protocol : DuckDBDataProtocol , accessMode : DuckDBAccessMode , multiWindowMode : boolean ) : Promise < PreparedDBFileHandle [ ] > {
182187 if ( protocol === DuckDBDataProtocol . BROWSER_FSACCESS && this . prepareFileHandles ) {
183188 const filePaths = [ dbPath , `${ dbPath } .wal` ] ;
184- return this . prepareFileHandles ( filePaths , protocol , accessMode ) ;
189+ return this . prepareFileHandles ( filePaths , protocol , accessMode , multiWindowMode ) ;
185190 }
186191 throw new Error ( `Unsupported protocol ${ protocol } for path ${ dbPath } with protocol ${ protocol } ` ) ;
187192 } ,
0 commit comments