-
Notifications
You must be signed in to change notification settings - Fork 315
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
Diagnostics
: new FileHandler
for abstracting file operations
#2673
Conversation
ffd0d4e
to
c45de52
Compare
} | ||
|
||
/// Deletes the first N lines from the file, without loading the entire file in memory. | ||
func removeFirstLines(_ count: Int) async throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation avoids loading the entire file in memory.
c45de52
to
07d6d75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
throw Error.failedMovingNewFile(from: otherURL, toURL: self.url, error) | ||
} | ||
|
||
self.fileHandle.closeAndLogErrors() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's handled by the fact that this type is an actor
:)
https://www.swiftbysundell.com/articles/swift-actors/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh right!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a test making sure the file ends with a new line break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense 👍
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
actor
to easily synchronize operations on a file.Simple interface: