Lines Matching refs:fh

183 const getSyncHandle = async (fh)=>{  argument
184 if(!fh.syncHandle){
186 log("Acquiring sync handle for",fh.filenameAbs);
194 fh.syncHandle = await fh.fileHandle.createSyncAccessHandle();
200 "attempts failed.",fh.filenameAbs
204 "ms and trying again.",fh.filenameAbs,e);
208 log("Got sync handle for",fh.filenameAbs,'in',performance.now() - t,'ms');
209 if(!fh.xLock){
210 __autoLocks.add(fh.fid);
211 log("Auto-locked",fh.fid,fh.filenameAbs);
214 return fh.syncHandle;
227 const closeSyncHandle = async (fh)=>{ argument
228 if(fh.syncHandle){
229 log("Closing sync handle for",fh.filenameAbs);
230 const h = fh.syncHandle;
231 delete fh.syncHandle;
232 delete fh.xLock;
233 __autoLocks.delete(fh.fid);
249 const closeSyncHandleNoThrow = async (fh)=>{ argument
250 try{await closeSyncHandle(fh)}
252 warn("closeSyncHandleNoThrow() ignoring:",e,fh);
269 const affirmNotRO = function(opName,fh){ argument
270 if(fh.readOnly) toss(opName+"(): File is read-only: "+fh.filenameAbs);
272 const affirmLocked = function(opName,fh){ argument
385 const fh = __openFiles[fid];
388 if(fh){
390 await closeSyncHandle(fh);
391 if(fh.deleteOnClose){
392 try{ await fh.dirHandle.removeEntry(fh.filenamePart) }
393 catch(e){ warn("Ignoring dirHandle.removeEntry() failure of",fh,e) }
444 const fh = __openFiles[fid];
448 affirmLocked('xFileSize',fh);
449 rc = await (await getSyncHandle(fh)).getSize();
463 const fh = __openFiles[fid];
465 const oldLockType = fh.xLock;
466 fh.xLock = lockType;
467 if( !fh.syncHandle ){
470 await getSyncHandle(fh);
475 fh.xLock = oldLockType;
531 const fh = __openFiles[fid];
533 affirmLocked('xRead',fh);
535 nRead = (await getSyncHandle(fh)).read(
536 fh.sabView.subarray(0, n),
541 fh.sabView.fill(0, nRead, n);
546 error("xRead() failed",e,fh);
555 const fh = __openFiles[fid];
557 if(!fh.readOnly && fh.syncHandle){
560 await fh.syncHandle.flush();
573 const fh = __openFiles[fid];
576 affirmLocked('xTruncate',fh);
577 affirmNotRO('xTruncate', fh);
578 await (await getSyncHandle(fh)).truncate(size);
580 error("xTruncate():",e,fh);
592 const fh = __openFiles[fid];
594 && fh.syncHandle ){
596 try { await closeSyncHandle(fh) }
609 const fh = __openFiles[fid];
612 affirmLocked('xWrite',fh);
613 affirmNotRO('xWrite', fh);
615 n === (await getSyncHandle(fh))
616 .write(fh.sabView.subarray(0, n),
620 error("xWrite():",e,fh);
760 const fh = __openFiles[fid];
761 await closeSyncHandleNoThrow(fh);
762 log("Auto-unlocked",fid,fh.filenameAbs);