@@ -142,22 +142,27 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
142
142
dirHandle = await dirHandle . getDirectoryHandle ( folder , { create : isReadWrite } ) ;
143
143
}
144
144
}
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 ) {
146
149
if ( e ?. name === 'NotFoundError' ) {
147
150
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 ;
150
156
}
151
- console . debug ( `File ${ path } does not exists, aborting as we are in read-only mode` ) ;
157
+ } else {
158
+ throw e ;
152
159
}
153
- throw e ;
154
- } ) ;
160
+ }
155
161
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
+ } ) ;
161
166
BROWSER_RUNTIME . _preparedHandles [ path ] = handle ;
162
167
return {
163
168
path,
@@ -178,10 +183,10 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
178
183
throw new Error ( `Unsupported protocol ${ protocol } for paths ${ filePaths } with protocol ${ protocol } ` ) ;
179
184
} ,
180
185
/** 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 [ ] > {
182
187
if ( protocol === DuckDBDataProtocol . BROWSER_FSACCESS && this . prepareFileHandles ) {
183
188
const filePaths = [ dbPath , `${ dbPath } .wal` ] ;
184
- return this . prepareFileHandles ( filePaths , protocol , accessMode ) ;
189
+ return this . prepareFileHandles ( filePaths , protocol , accessMode , multiWindowMode ) ;
185
190
}
186
191
throw new Error ( `Unsupported protocol ${ protocol } for path ${ dbPath } with protocol ${ protocol } ` ) ;
187
192
} ,
0 commit comments