Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Thrown File Exists #5044

Closed
pbferre opened this issue Mar 17, 2017 · 5 comments
Closed

Exception Thrown File Exists #5044

pbferre opened this issue Mar 17, 2017 · 5 comments
Labels

Comments

@pbferre
Copy link

pbferre commented Mar 17, 2017

I have been going through the Emscripten tutorials and tests. I modified to hello_world_file.cpp test to use NODEFS, rather than pre-loading the text file. Here is my modified code:

#include <stdio.h>
#include <stdlib.h>
#include <emscripten.h>
#include <string.h>

int main() {
  EM_ASM(
    FS.mkdir('/tmp');
    FS.mount(NODEFS, { root: '.' }, '/tmp');
  );
  
  FILE *file = fopen("/tmp/tests/hello_world_file.txt", "rb");
  if (!file) {
    printf("Cannot open file:\n");
    return 1;
  }
  while (!feof(file)) {
    char c = fgetc(file);
    if (c != EOF) {
      putchar(c);
    }
  }
  fclose (file);
  return 0;
}

The code compiles fine, but when I run it, I get an exception thrown with an error complaining that a file already exists. Here is the output:

C:\Program Files\Emscripten\emscripten\1.35.0>node a.out.js
exception thrown: Error: File exists,Error
    at Object.FS.ensureErrnoError (C:\Program Files\Emscripten\emscripten\1.35.0\a.out.js:4169:35)
    at Object.FS.staticInit (C:\Program Files\Emscripten\emscripten\1.35.0\a.out.js:4177:12)
    at Object.<anonymous> (C:\Program Files\Emscripten\emscripten\1.35.0\a.out.js:5723:4)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3

C:\Program Files\Emscripten\emscripten\1.35.0\a.out.js:97
      throw ex;
      ^
Error
    at Object.FS.ensureErrnoError (C:\Program Files\Emscripten\emscripten\1.35.0\a.out.js:4169:35)
    at Object.FS.staticInit (C:\Program Files\Emscripten\emscripten\1.35.0\a.out.js:4177:12)
    at Object.<anonymous> (C:\Program Files\Emscripten\emscripten\1.35.0\a.out.js:5723:4)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3

Any ideas?

@pbferre
Copy link
Author

pbferre commented Mar 17, 2017

I changed the name of the folder, and the program is working fine. The only thing I can see is that there is a 'tmp' folder 4 levels down in the directory tree from where the a.out.js file was created. Is that a thing, you cannot pass a name to FS.mkdir that is the same as the name of any folder in the directory tree?

@kripken
Copy link
Member

kripken commented Mar 17, 2017

That shouldn't happen, but it could be a weird bug. Does renaming the tmp folder 4 levels down change things?

I suspect that FS.mkdir('/tmp'); is trying to create tmp at the highest level (not a subdir), and your machine already has such a folder.

@bryangingechen
Copy link
Contributor

I ran into a similar issue today except with a call to FS.mkdir('/home'). After some digging, I believe the underlying issue is that /home and /tmp are created automatically by default here: https://github.com/emscripten-core/emscripten/blob/incoming/src/library_fs.js#L1288

I'll submit a PR to document this shortly.

@stale
Copy link

stale bot commented May 12, 2020

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label May 12, 2020
@stale stale bot closed this as completed May 19, 2020
@vadimkantorov
Copy link

It would be nice also if the exception listed the offending file path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants