Diagnostics: new FileHandler for abstracting file operations#2673
Conversation
ffd0d4e to
c45de52
Compare
There was a problem hiding this comment.
This implementation avoids loading the entire file in memory.
c45de52 to
07d6d75
Compare
| throw Error.failedMovingNewFile(from: otherURL, toURL: self.url, error) | ||
| } | ||
|
|
||
| self.fileHandle.closeAndLogErrors() |
There was a problem hiding this comment.
So closing the fileHandle AFTER we've removed the original item won't be a problem? I'd imagine we would need to close it before deleting the file but I might be wrong.
There was a problem hiding this comment.
This is basically just a file descriptor inside. I did this after moving it because we don't want to leave an inconsistent state if any of the move operations fail.
| return result | ||
| } | ||
|
|
||
| func replaceHandler(with otherURL: URL) throws { |
There was a problem hiding this comment.
I wonder if this function should be executed atomically, so if there are multiple threads using this handler, this doesn't cause any issues (We don't do this in Android either)
There was a problem hiding this comment.
That's handled by the fact that this type is an actor :)
https://www.swiftbysundell.com/articles/swift-actors/
| await self.handler.append(line: content) | ||
|
|
||
| let data = try await self.handler.readFile() | ||
| expect(data).to(matchLines(content)) |
There was a problem hiding this comment.
Should we have a test making sure the file ends with a new line break?
There was a problem hiding this comment.
I thought it wasn't that important to add an explicit test, as long as the other logic works as expected (appending an existing file, etc). What do you think?
07d6d75 to
8a69cf4
Compare
**This is an automatic release.** ### Bugfixes * Fix google play purchases missing purchase date (#2703) via Toni Rico (@tonidero) ### Other Changes * `PurchaseTester`: fixed `watchOS` build and ASC deployment (#2701) via NachoSoto (@NachoSoto) * Add `Data.sha1` (#2696) via NachoSoto (@NachoSoto) * Refactor: extract `ErrorResponse` into its own file (#2697) via NachoSoto (@NachoSoto) * Add `Sequence<AdditiveArithmetic>.sum()` (#2694) via NachoSoto (@NachoSoto) * Refactored `Data.asString` implementation (#2695) via NachoSoto (@NachoSoto) * `Diagnostics`: new `FileHandler` for abstracting file operations (#2673) via NachoSoto (@NachoSoto)
- New `PaywallEventStore` using `FileHandler` (#2673) - `MockFileHandler` - `PaywallStoredEvent`: this contains the necessary information to store an event: `PaywallEvent` + user ID - `Created PaywallEventSerializer`
- New `PaywallEventStore` using `FileHandler` (#2673) - `MockFileHandler` - `PaywallStoredEvent`: this contains the necessary information to store an event: `PaywallEvent` + user ID - `Created PaywallEventSerializer`
- New `PaywallEventStore` using `FileHandler` (#2673) - `MockFileHandler` - `PaywallStoredEvent`: this contains the necessary information to store an event: `PaywallEvent` + user ID - `Created PaywallEventSerializer`
- New `PaywallEventStore` using `FileHandler` (#2673) - `MockFileHandler` - `PaywallStoredEvent`: this contains the necessary information to store an event: `PaywallEvent` + user ID - `Created PaywallEventSerializer`
- New `PaywallEventStore` using `FileHandler` (#2673) - `MockFileHandler` - `PaywallStoredEvent`: this contains the necessary information to store an event: `PaywallEvent` + user ID - `Created PaywallEventSerializer`
- New `PaywallEventStore` using `FileHandler` (#2673) - `MockFileHandler` - `PaywallStoredEvent`: this contains the necessary information to store an event: `PaywallEvent` + user ID - `Created PaywallEventSerializer`
- New `PaywallEventStore` using `FileHandler` (#2673) - `MockFileHandler` - `PaywallStoredEvent`: this contains the necessary information to store an event: `PaywallEvent` + user ID - `Created PaywallEventSerializer`
Implemented as an
actorto easily synchronize operations on a file.Simple interface:
