Introduces a new RunOnBackgroundThread template method which abstracts away
most of the boilerplate needed to run sync I/O tasks with result reported by a
JS Promise on a background thread.
Differential Revision: https://phabricator.services.mozilla.com/D85296
This change completely overhauls the way errors are handled in `IOUtils`. With
the introduction of the new `IOError` type, a useful error message is paired
with an `nsresult` at the error site. This provides erroneous callers with more
information about what went wrong, while improving consistency with mapping
errors to `DOMExceptions`.
For error sites where it is not immediately clear what went wrong, messages can
be omitted. A default error message will be filled in corresponding with the
wrapped `nsresult` when the operation is rejected to the calling JavaScript.
Differential Revision: https://phabricator.services.mozilla.com/D84736
This change introduces some new methods to reduce repeated boilerplate around
promise usage in success paths of `IOUtils` method implementations.
Differential Revision: https://phabricator.services.mozilla.com/D84735
This changes most private methods of `IOUtils` to use the `Result` monad as a
return type instead of a bare `nsresult`. This improves consistency of all of
the public method implementations, and will allow for the shared patterns to be
abstracted in a follow-up patch.
Differential Revision: https://phabricator.services.mozilla.com/D84734
This patch introduces a new private `IOUtils::WriteAtomicSync` method, which
fully encapsulates the behaviour of `IOUtils::writeAtomic`. The private
`IOUtils::WriteSync` method has also been updated to use the `Result` monad as
a return type, which is favourable over a bare `nsresult`.
These changes together simplify the implementation of the public method, and
lay some of the ground work to further improve error handling in `IOUtils`.
Differential Revision: https://phabricator.services.mozilla.com/D84733
This patch fully encapsulates the behaviour of the IOUtils::read method behind
the private `IOUtils::ReadSync` method. Error handling for these methods has
been updated to use the `Result` monad, which is favourable over a bare
`nsresult`.
This lays some of the ground work to further improve error handling in
`IOUtils`.
Differential Revision: https://phabricator.services.mozilla.com/D84732
This patch introduces a new `REJECT_IF_RELATIVE_PATH` macro for use in
`IOUtils`. Its usage ensures that every method rejects in the same way when
unsupported relative paths are passed as parameters to `IOUtils` public
methods.
Differential Revision: https://phabricator.services.mozilla.com/D84731
Introduces a new RunOnBackgroundThread template method which abstracts away
most of the boilerplate needed to run sync I/O tasks with result reported by a
JS Promise on a background thread.
Differential Revision: https://phabricator.services.mozilla.com/D85296
This change completely overhauls the way errors are handled in `IOUtils`. With
the introduction of the new `IOError` type, a useful error message is paired
with an `nsresult` at the error site. This provides erroneous callers with more
information about what went wrong, while improving consistency with mapping
errors to `DOMExceptions`.
For error sites where it is not immediately clear what went wrong, messages can
be omitted. A default error message will be filled in corresponding with the
wrapped `nsresult` when the operation is rejected to the calling JavaScript.
Differential Revision: https://phabricator.services.mozilla.com/D84736
This change introduces some new methods to reduce repeated boilerplate around
promise usage in success paths of `IOUtils` method implementations.
Differential Revision: https://phabricator.services.mozilla.com/D84735
This changes most private methods of `IOUtils` to use the `Result` monad as a
return type instead of a bare `nsresult`. This improves consistency of all of
the public method implementations, and will allow for the shared patterns to be
abstracted in a follow-up patch.
Differential Revision: https://phabricator.services.mozilla.com/D84734
This patch introduces a new private `IOUtils::WriteAtomicSync` method, which
fully encapsulates the behaviour of `IOUtils::writeAtomic`. The private
`IOUtils::WriteSync` method has also been updated to use the `Result` monad as
a return type, which is favourable over a bare `nsresult`.
These changes together simplify the implementation of the public method, and
lay some of the ground work to further improve error handling in `IOUtils`.
Differential Revision: https://phabricator.services.mozilla.com/D84733
This patch fully encapsulates the behaviour of the IOUtils::read method behind
the private `IOUtils::ReadSync` method. Error handling for these methods has
been updated to use the `Result` monad, which is favourable over a bare
`nsresult`.
This lays some of the ground work to further improve error handling in
`IOUtils`.
Differential Revision: https://phabricator.services.mozilla.com/D84732
This patch introduces a new `REJECT_IF_RELATIVE_PATH` macro for use in
`IOUtils`. Its usage ensures that every method rejects in the same way when
unsupported relative paths are passed as parameters to `IOUtils` public
methods.
Differential Revision: https://phabricator.services.mozilla.com/D84731
This patch introduces a makeDirectory method to the IOUtils interface, which
allows for creating directories on disk.
Differential Revision: https://phabricator.services.mozilla.com/D83996
This patch introduces a remove method to the IOUtils interface, which allows
for removing files and directories on disk. It is a simple wrapper around
the nsIFile::Remove method.
Differential Revision: https://phabricator.services.mozilla.com/D83663
This patch attempts to fix the permanent win mingw build failure caused
by use of the undeclared identifiers 'S_IFLNK' and 'S_IFSOCK' in
dom/system/OSFileConstants.cpp
These identifiers are only ever declared on Unix systems (Linux, macOS,
Android, etc.), so the `ifdef` guard around the use of these constants
has been updated appropriately.
Differential Revision: https://phabricator.services.mozilla.com/D83844
This patch introduces a remove method to the IOUtils interface, which allows
for removing files and directories on disk. It is a simple wrapper around
the nsIFile::Remove method.
Differential Revision: https://phabricator.services.mozilla.com/D83663
This patch refactors the existing IOUtils::writeAtomic method to add support for the `tmpPath` and `backupFile` options.
Differential Revision: https://phabricator.services.mozilla.com/D82601
This patch introduces a move method to the IOUtils interface, which allows
for renaming/moving files or directories on disk. Source and destination
files may be specified either by an absolute path, or a relative path from
the current working directory.
This method has well-defined behaviour similar to the POSIX mv command
(except that this may create missing directories as necessary).
The behaviour is briefly summarized below:
1. If the source is a file that exists:
a. If the destination is a file that does not exist, the source is
renamed (and re-parented as a child of the destination parent
directory). The destination parent directory will be created if
necessary.
b. If the destination is a file that does exist, the destination is
replaced with the source (unless the noOverwrite option is true).
2. If the source is a directory that exists:
a. If the destination is a directory, then the source directory is
re-parented such that it becomes a child of the destination.
b. If the destination does not exist, then the source is renamed,
creating additional directories if needed.
c. If the destination is a file, then an error occurs.
3. If the source does not exist, an error occurs.
Differential Revision: https://phabricator.services.mozilla.com/D82202
This patch refactors the existing IOUtils::writeAtomic method to add support for the `tmpPath` and `backupFile` options.
Differential Revision: https://phabricator.services.mozilla.com/D82601
This patch introduces a move method to the IOUtils interface, which allows
for renaming/moving files or directories on disk. Source and destination
files may be specified either by an absolute path, or a relative path from
the current working directory.
This method has well-defined behaviour similar to the POSIX mv command
(except that this may create missing directories as necessary).
The behaviour is briefly summarized below:
1. If the source is a file that exists:
a. If the destination is a file that does not exist, the source is
renamed (and re-parented as a child of the destination parent
directory). The destination parent directory will be created if
necessary.
b. If the destination is a file that does exist, the destination is
replaced with the source (unless the noOverwrite option is true).
2. If the source is a directory that exists:
a. If the destination is a directory, then the source directory is
re-parented such that it becomes a child of the destination.
b. If the destination does not exist, then the source is renamed,
creating additional directories if needed.
c. If the destination is a file, then an error occurs.
3. If the source does not exist, an error occurs.
Differential Revision: https://phabricator.services.mozilla.com/D82202
This patch introduces a minimal, asynchronous Web IDL interface for
reading/writing whole files in privileged chrome code (main-thread and web
workers). All I/O is performed on a background thread. Pending I/O blocks
Firefox shutdown.
Differential Revision: https://phabricator.services.mozilla.com/D78134
The class PR_CloseDelete is a useful deleter for automatically closing NSPR File
Descriptors when used with UniquePtr. This patch extracts this class from
nsTerminator.cpp to dom/system so it may easily be used by new Gecko code.
Differential Revision: https://phabricator.services.mozilla.com/D80719
This patch introduces a minimal, asynchronous Web IDL interface for
reading/writing whole files in privileged chrome code (main-thread and web
workers). All I/O is performed on a background thread. Pending I/O blocks
Firefox shutdown.
Differential Revision: https://phabricator.services.mozilla.com/D78134
The class PR_CloseDelete is a useful deleter for automatically closing NSPR File
Descriptors when used with UniquePtr. This patch extracts this class from
nsTerminator.cpp to dom/system so it may easily be used by new Gecko code.
Differential Revision: https://phabricator.services.mozilla.com/D80719
In this bug we're moving away from monolithic JNI headers to class-specific
headers so that we don't have to rebuild the world every time we make a change
to a JNI interface.
Differential Revision: https://phabricator.services.mozilla.com/D75380