Skip to content

No way to get a reference to a file that is opened #24

@tomayac

Description

@tomayac

The problem

Files that you know only the name of may be open.

(async () => {
  const randomName = Math.random().toString().substr(2);
  try {
    // Create a file, but keep no reference to it.
    await storageFoundation.open(randomName);
    console.log('Created', randomName);
    // Delete all files.
    storageFoundation.getAll().then((names) => names.forEach(async (name) => { 
      console.log('Deleting', name);
      // This fails, since the just created file is open.
      await storageFoundation.delete(name);
      // Throws a `DOMException: File is open` error.
      // At the same time there is no way to close the file, since all I have
      // at this stage is the file's `name`, and I can't call `NativeIOFile.close()`
      // without a file reference.
    }));
  } catch (err) {
    console.error(err.name, err.message);
  }
})();

Possible solution

Make it possible to get a reference to a file and make its state queryable like so:

const file = await storageFoundation.getFileReference(name);
if (await file.isOpen()) {
  await file.close();
}
// Deleting would now succeed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions