IDBFS file system : error in creating sub_dir in mounted dir

31 views
Skip to first unread message

anshul mahajan

unread,
Mar 24, 2020, 7:04:23 AM3/24/20
to emscripten-discuss
Hi All,

I have got a test-app which is used for testing our application. When we run test-app we create output.xml for each of the test-cases which were executed.
Since in emscripten we can't create a new file on local file system i.e on local machine. On digging I come around IDBFS file system support in emscripten : by using this file system we can mock writing new file to local file system where the actual file are written to indexed db.

So for testing I have created POC attached is the cpp file : untitled.cpp

Command used :  

emcc untitled.cpp -o filetest.html -lidbfs.js -s FETCH=1 -s FORCE_FILESYSTEM=1 -s NO_EXIT_RUNTIME=1

Let me just brief you about the code :

1) I have mounted following directory in IDBFS : "working1"

 EM_ASM(

        FS.mkdir('/working1');

        FS.mount(IDBFS, {}, '/working1');

        

        FS.syncfs(true, function (err) {

          assert(!err);

        });

    );


2) call util_create func which in turn call test func. In test func I am creating new file "/working1/twrite.txt" "/working1/working2/twrite1.txt" and "/working1/twrite2.txt"

3) call sync_idbfs() which is used to persists changes in indexed db i.e. working1



Error : when call read_fs(func used for reading file) on file :"/working1/working2/twrite1.txt" ->  I am getting following error : stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.

please note that in all my printf statement I have got \n and also the flag is passed while compiling.


And also, I am not able to see following file "/working1/working2/twrite1.txt" in indexed db of browser but I am able to see following file twrite.txt and twrite2.txt.

So my question is that , has anyone created a sub directory using IDBFS file system. And pointer on the same i.e what all thing I can try.

Please note that I have unsuccessfully tried following thing :
1) before mounting creating sub directory as well i.e. 
FS.mkdir('/working1'); and FS.mkdir('/working1/working2');

2) before creating new file in sub directory i,e FS.mkdir('/working1/working2'); and creating new file in sub dir.

Regards,

Anshul



 


untitled.cpp

Shlomi Fish

unread,
Mar 27, 2020, 4:25:28 AM3/27/20
to anshul mahajan, emscripte...@googlegroups.com
Hi Anshul,

On Tue, 24 Mar 2020 04:04:23 -0700 (PDT)
anshul mahajan <aans...@gmail.com> wrote:

> Hi All,
>
> I have got a test-app which is used for testing our application. When we
> run test-app we create output.xml for each of the test-cases which were
> executed.
> Since in emscripten we can't create a new file on local file system i.e on
> local machine. On digging I come around IDBFS file system support in
> emscripten : by using this file system we can mock writing new file to
> local file system where the actual file are written to indexed db.
>
> So for testing I have created POC attached is the cpp file : untitled.cpp
>

Calling mkdir() seems to help, see:

https://www.shlomifish.org/Files/files/dirs/stdio-test-2del/2del/filetest.html

Sources:

* https://www.shlomifish.org/Files/files/dirs/stdio-test-2del/2del/untitled.cpp

* https://www.shlomifish.org/Files/files/dirs/stdio-test-2del/2del/build.bash

Regards,

Shlomi
> Command used :
>
> emcc untitled.cpp -o filetest.html -lidbfs.js -s FETCH=1 -s
> FORCE_FILESYSTEM=1 -s NO_EXIT_RUNTIME=1
>
> Let me just brief you about the code :
>
> 1) I have mounted following directory in IDBFS : "working1"
>
> EM_ASM(
>
> FS.mkdir('/working1');
>
> FS.mount(IDBFS, {}, '/working1');
>
>
>
> FS.syncfs(true, function (err) {
>
> assert(!err);
>
> });
>
> );
>
>
> 2) call util_create func which in turn call test func. In test func I am
> creating new file "/working1/twrite.txt" *"/working1/**working2/*
> *twrite1.txt"* and "/working1/twrite2.txt"
>
> 3) call sync_idbfs() which is used to persists changes in indexed db i.e.
> working1
>
>
>
> Error : when call read_fs(func used for reading file) on file :*"/working1/*
> *working2/**twrite1.txt" ->* I am getting following error : stdio streams
> had content in them that was not flushed. you should set EXIT_RUNTIME to 1
> (see the FAQ), or make sure to emit a newline when you printf etc.
>
> please note that in all my printf statement I have got \n and also the flag
> is passed while compiling.
>
>
> And also, I am not able to see following file
> *"/working1/**working2/**twrite1.txt" in indexed db of browser but I am able
> to see following file twrite.txt and twrite2.txt.*
>
> *So my question is that , has anyone created a sub directory using IDBFS
> file system. And pointer on the same i.e what all thing I can try.*
>
> Please note that I have unsuccessfully tried following thing :
> 1) before mounting creating sub directory as well i.e. FS.mkdir('/working1');
> and FS.mkdir('/working1/working2');
>
> 2) before creating new file in sub directory i,e
> FS.mkdir('/working1/working2'); and creating new file in sub dir.
>
> Regards,
>
> Anshul
>
>
>
>
>



--

Shlomi Fish https://www.shlomifish.org/
https://www.shlomifish.org/humour/bits/Can-I-SCO-Now/ - “Can I SCO Now?”

Academic Politics are so vicious precisely because the stakes are so low.
https://quoteinvestigator.com/2013/08/18/acad-politics/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Shlomi Fish

unread,
Mar 27, 2020, 4:30:41 AM3/27/20
to anshul mahajan, emscripte...@googlegroups.com
On Fri, 27 Mar 2020 11:25:20 +0300
Shlomi Fish <shl...@shlomifish.org> wrote:

> Hi Anshul,
>
> On Tue, 24 Mar 2020 04:04:23 -0700 (PDT)
> anshul mahajan <aans...@gmail.com> wrote:

Also see the sources in this github repo:

https://github.com/shlomif/emcc-stdio-test-2del
http://is.gd/i5eMQd - Emma Watson’s Interview for a Software Dev Job

If you ask Taylor Swift "What is the square root of 18.678?", she will answer
"Why the hell does it matter?".
https://www.shlomifish.org/humour/bits/facts/Taylor-Swift/
Reply all
Reply to author
Forward
0 new messages