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

Make MemoryRandomAccessFile handle the file being moved from under it #157

Merged
merged 4 commits into from
Jul 1, 2020
Merged

Make MemoryRandomAccessFile handle the file being moved from under it #157

merged 4 commits into from
Jul 1, 2020

Conversation

jamesderlin
Copy link
Collaborator

@jamesderlin jamesderlin commented Jun 25, 2020

Fix MemoryRandomAccessFile to use only its FileNode and never the
corresponding MemoryFile. While the MemoryRandomAccessFile (the
equivalent of a file handle) is open, its FileNode should never
change, but the original MemoryFile might become backed by a
different node if the file is moved, removed, or replaced.

POSIX systems typically allow this; Windows typically doesn't. For
now, make MemoryFileSystem follow the typical POSIX behavior. (In
the long-term, MemoryFileSystem perhaps should have configurable
behavior.)

Similarly, make MemoryFile.openWrite's IOSink resolve the
FileNode immediately instead of adding it to an async queue.
Otherwise node resolution could return a different FileNode than
what was originally intended.

Eagerly resolving the FileNode has the side-effect of potentially
throwing exceptions earlier than expected. I therefore added a
mechanism to defer throwing.

Bonus:

  • Make rename tests verify the path of the returned
    FileSystemEntity.
  • Add explicit types to fix analysis warnings that I introduced.

Fix `MemoryRandomAccessFile` to use only its `FileNode` and never the
corresponding `MemoryFile`.  While the `MemoryRandomAccessFile` (the
equivalent of a file handle) is open, its `FileNode` should never
change, but the original `MemoryFile` might become backed by a
different node if the file is moved, removed, or replaced.

POSIX systems typically allow this; Windows typically doesn't.  For
now, make `MemoryFileSystem` follow the typical POSIX behavior. (In
the long-term, `MemoryFileSystem` perhaps should have configurable
behavior.)
@jamesderlin
Copy link
Collaborator Author

Note to reviewers: I've made each of the individual commits logically distinct, so looking at the individual diffs for them might be easier.

Make `MemoryFile.openWrite`'s `IOSink` resolve the `FileNode`
immediately instead of adding it to an async queue.  Otherwise node
resolution could return a different `FileNode` than what was
originally intended.

Eagerly resolving the `FileNode` has the side-effect of potentially
throwing exceptions earlier than expected.  I therefore added a
mechanism to defer throwing.
@jamesderlin
Copy link
Collaborator Author

Ping? (@dnfield ?)

FileNode node;
Exception deferredException;

// Resolve the backing immediately to ensure that the [FileNode] we write
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably check that the style is posix style here (see https://github.com/google/file.dart/blob/master/packages/file/lib/src/backends/memory/memory_file_system.dart#L46). I think it'd probably be fairly simple given that to implement the windows type behavior - wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that checking style would be a good way to configure the behavior. I don't think here would be the right place to do it. Windows typically wouldn't allow renaming/moving/deleting files with open handles in the first place, so I don't know what (if anything) we should do differently here. (I also currently don't have a Windows machine handy with Dart set up to verify dart:io's File's behavior there.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a bug tracking work on that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. I will file one.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Successfully merging this pull request may close these issues.

2 participants