Skip to content

Exception Thrown File Exists #5044

Closed
Closed

Description

@pbferre

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?

Activity

  1. pbferre commented on Mar 17, 2017

    @pbferre
    Author

    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?

  2. kripken commented on Mar 17, 2017

    @kripken
    Member

    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.

  3. bryangingechen commented on May 13, 2019

    @bryangingechen
    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.

  4. stale commented on May 12, 2020

    @stale

    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.

  5. vadimkantorov commented on Sep 27, 2020

    @vadimkantorov

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions