andreasgal/j2me.js — pull request #717 by mykmelez (2014-12-12 05:29:03+00:00)
Title: determine file existence more consistently

This is the alternative to #713. I touch a bunch of stuff, adding comments and making operators stricter, but the key changes are:

1. In *remove*, remove the file even if it isn't listed in its parent directory's list of files.
2. In *createInternal*, determine whether or not the file exists by calling *exists* rather than consulting the parent directory's list of files.

The problem here is that we have redundant data, since a file's existence can be inferred from both a record for it in the datastore and an entry for it in its parent directory's *files* array. There should be only one source of truth, and most of the code assumes that source of truth is a record in the datastore. These changes make that more explicit.

I still think it'd be better to get rid of the *files* array. It's trivially simple to make it inconsistent with the records in the database; it's just a single call to *store.setItem*. But at the very least, we should rely on it as little as possible. With these changes, only three functions use it: *list* uses it to get the list of files in a directory, *remove* uses it to determine whether or not a directory is empty, and *rename* also uses it to determine whether or not a directory is empty (although it does the wrong thing with the information).