P.S. Please ignore the code in the previous letter.
This is more "feature-full" (not working, but has explicit syncfs calls):

```
let FS;
async function run() {
  Module = await createMyModule();

  FS = Module.FS;

  FS.mkdir('/project');

  FS.mount(FS.filesystems.IDBFS, {}, '/project');
  await sync();
  FS.chdir('/project');

  console.log(FS.analyzePath('content').exists);  // <---- shows false on both 
runs!

  FS.writeFile('content', '...'); // write file on first run, expecting to see 
it on the second

  await sync();
}

async function sync() {
   // should save/load existing data here? (doesn't work)
  await new Promise((res, rej) => {
    FS.syncfs(true, err => err ? rej(err) : res());
  });
}

(async () => {
  await run();
  await run();
})();
```

> On 10 Feb 2023, at 09:43, Ilya Kantor <ilia...@gmail.com> wrote:
> 
> Well... Yes, if we look at it this way, kind of makes a point.
> 
> Does this code seem good?
> 
> I expect the FS to keep the context of /project, but it doesn't (compiling 
> with -lidbfs.js).
> 
> async function initModule() {
>   Module = await createMyModule();
> 
>   let FS = Module.FS;
> 
>   FS.mkdir('/project');
>   FS.mount(FS.filesystems.IDBFS, {}, '/project');
>   FS.chdir('/project');
> }
> 
> 
>> On 10 Feb 2023, at 02:06, chi...@gmail.com <chi...@gmail.com> wrote:
>> 
>> MEMFS is an in-MEMory FileSytem. What you need is IndexedDB-based FS.
>> 
>> On Friday, February 10, 2023 at 3:54:00 AM UTC+4 ili...@gmail.com wrote:
>>> I'm sorry to say so, but WASM memory and FS are two different things by 
>>> design.
>>> 
>>> There's no need to make things more complex than keeping FS while resetting 
>>> memory.
>>> I do it with my computer every day (almost) ;)
>>> 
>>> Kind regards,
>>> Ilya Kantor
>>> 
>>> 
>>>> On 10 Feb 2023, at 00:05, 'Sam Clegg' via emscripten-discuss 
>>>> <emscripte...@googlegroups.com <>> wrote:
>>>> 
>>> 
>>>> If you are using MEMFS then its contents would (by design) be reset when 
>>>> you reset your memory.
>>>> 
>>>> If you want to preserve data between runs you would need some kind of 
>>>> persistent store.   Perhaps IDBFS?
>>>> 
>>>> On Thu, Feb 9, 2023 at 2:34 PM Ilya Kantor <ili...@gmail.com <>> wrote:
>>>>> That's a great hint, thank you!
>>>>> 
>>>>> I tried to do so, but bumped into a problem: I need to pass FS from the 
>>>>> old module to the new one.
>>>>> I'm using the most basic default MEMFS.
>>>>> 
>>>>> Any idea how to do it?
>>>>> 
>>>>> Or maybe I should recursively walk and copy files? That's not the most 
>>>>> elegant solution, but should work.
>>>>> 
>>>>> Kind regards,
>>>>> Ilya Kantor
>>>>> 
>>>>>> On 9 Feb 2023, at 20:30, 'Sam Clegg' via emscripten-discuss 
>>>>>> <emscripte...@googlegroups.com <>> wrote:
>>>>>> 
>>>>>> Hi Ilya,
>>>>>> 
>>>>>> Emscripten doesn't have any way to do that today (at least not that I 
>>>>>> know of).
>>>>>> 
>>>>>> Your best bet is probably to use `-sMODULARIZE` and then construct a new 
>>>>>> instance for each time you want to call `main`.   i.e `new MyModule()` 
>>>>>> each time.
>>>>>> 
>>>>>> cheers,
>>>>>> sam
>>>>>> 
>>>>>> On Thu, Feb 9, 2023 at 11:18 AM Ilya Kantor <ili...@gmail.com <>> wrote:
>>>>>>> Hello,
>>>>>>> 
>>>>>>> I use Emscripten to compile a CLI application, and then run its _main 
>>>>>>> many times.
>>>>>>> 
>>>>>>> The problem is that it expects every call to be "from the scratch", 
>>>>>>> with uninitialized data structures.
>>>>>>> 
>>>>>>> Right now, e.g. a file has `struct my_type s`, and initializes it on 
>>>>>>> the first run, then it survives till the second run and spoils it.
>>>>>>> 
>>>>>>> How to re-init WASM, to clear memory for new  runs (start afresh) while 
>>>>>>> keeping FS untouched?
>>>>>>> 
>>>>>>> 
>>>>>>> -- 
>>>>>>> You received this message because you are subscribed to the Google 
>>>>>>> Groups "emscripten-discuss" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>>>> an email to emscripten-disc...@googlegroups.com <>.
>>>>>>> To view this discussion on the web visit 
>>>>>>> https://groups.google.com/d/msgid/emscripten-discuss/140af2b7-874c-4308-8563-044e066fd89fn%40googlegroups.com
>>>>>>>  
>>>>>>> <https://groups.google.com/d/msgid/emscripten-discuss/140af2b7-874c-4308-8563-044e066fd89fn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>>>>> 
>>>>>> 
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "emscripten-discuss" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>>> an email to emscripten-disc...@googlegroups.com <>.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28RpzVOUzTAr3zO5bX%2BQWTq%3DdMn08Xwc2y9odMFZKmw-g%40mail.gmail.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28RpzVOUzTAr3zO5bX%2BQWTq%3DdMn08Xwc2y9odMFZKmw-g%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>>>>> 
>>>>> 
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "emscripten-discuss" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>>>> email to emscripten-disc...@googlegroups.com <>.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/emscripten-discuss/D9B1D151-C606-4E89-AC79-823E58B61BA0%40gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/emscripten-discuss/D9B1D151-C606-4E89-AC79-823E58B61BA0%40gmail.com?utm_medium=email&utm_source=footer>.
>>>> 
>>>> 
>>>> -- 
>>>> You received this message because you are subscribed to the Google Groups 
>>>> "emscripten-discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>>> email to emscripten-disc...@googlegroups.com <>.
>>> 
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2-yO%2BOY6ANUzuBU5qOfv6BikyTonT5oUomOU4FbfHAwTA%40mail.gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2-yO%2BOY6ANUzuBU5qOfv6BikyTonT5oUomOU4FbfHAwTA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>>> 
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to emscripten-discuss+unsubscr...@googlegroups.com 
>> <mailto:emscripten-discuss+unsubscr...@googlegroups.com>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/emscripten-discuss/75d18653-26af-4e33-add0-d5f65a16cb20n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/emscripten-discuss/75d18653-26af-4e33-add0-d5f65a16cb20n%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/820626C3-6E25-411A-8F56-E6D01032ED31%40gmail.com.

Reply via email to