-
Notifications
You must be signed in to change notification settings - Fork 336
Consolidate test temp helpers and move file I/O + lock platform code into src/platform (#793 follow-up) #851
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
Open
bmehta001
wants to merge
3
commits into
main
Choose a base branch
from
bhamehta/flcore/platform-test-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| // Cross-platform orchestration for CrossProcessFileLock. The platform-specific | ||
| // pieces — the lock handle (State) and its releasing destructor, | ||
| // FormatProcessInfo, the CrossProcessFileLock destructor/constructor, and | ||
| // TryAcquireForDirectory — live in | ||
| // src/platform/{windows,posix}/cross_process_file_lock.cc. | ||
| #include "platform/cross_process_file_lock.h" | ||
| #include "exception.h" | ||
|
|
||
| #include <foundry_local/foundry_local_c.h> | ||
|
|
||
| #include <chrono> | ||
| #include <thread> | ||
|
|
||
| namespace fl { | ||
|
|
||
| std::unique_ptr<CrossProcessFileLock> CrossProcessFileLock::WaitForDirectoryLock( | ||
| const std::filesystem::path& directory, | ||
| const CancellationPredicate& is_cancelled, | ||
| ILogger& logger, | ||
| std::chrono::milliseconds poll_interval, | ||
| std::chrono::milliseconds timeout) { | ||
| auto deadline = std::chrono::steady_clock::now() + timeout; | ||
| // `is_cancelled` is the caller's progress callback, which also serves as the | ||
| // liveness heartbeat — it emits 0% on every invocation. We therefore poll it | ||
| // on a single cadence (once per `poll_interval`) rather than on a separate | ||
| // fast cancellation tick: a faster tick would spam the user callback (~10x/s) | ||
| // for the entire wait, and cancelling a multi-minute cross-process wait a | ||
| // second sooner is imperceptible. There is no separate cancellation channel | ||
| // to decouple the heartbeat from. | ||
| while (true) { | ||
| if (is_cancelled && is_cancelled()) { | ||
| FL_THROW(FOUNDRY_LOCAL_ERROR_OPERATION_CANCELLED, "lock acquisition cancelled"); | ||
| } | ||
| auto lock = CrossProcessFileLock::TryAcquireForDirectory(directory, logger); | ||
| if (lock) { | ||
| return lock; | ||
| } | ||
| if (std::chrono::steady_clock::now() >= deadline) { | ||
| FL_THROW(FOUNDRY_LOCAL_ERROR_INTERNAL, | ||
| "timed out waiting for cross-process download lock on '" + directory.string() + "'"); | ||
| } | ||
| std::this_thread::sleep_for(poll_interval); | ||
| } | ||
| } | ||
|
|
||
| } // namespace fl |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <filesystem> | ||
| #include <string> | ||
|
|
||
| namespace fl::platform { | ||
|
|
||
| /// Native file handle (a Win32 HANDLE or a POSIX file descriptor) carried as an | ||
| /// integer so callers don't depend on platform headers. `kInvalidFileHandle` | ||
| /// matches both INVALID_HANDLE_VALUE ((HANDLE)-1) and a POSIX fd of -1. | ||
| inline constexpr std::intptr_t kInvalidFileHandle = -1; | ||
|
|
||
| /// Open an existing file for positional read/write. Returns a handle that is not | ||
| /// `kInvalidFileHandle` on success; on failure returns `kInvalidFileHandle` and | ||
| /// sets `error` to a human-readable OS error (e.g. "Win32 err 5" / "errno 13"). | ||
| std::intptr_t OpenWritableFile(const std::filesystem::path& path, std::string& error); | ||
|
|
||
| /// Write all `len` bytes from `data` at byte offset `offset`. Safe for concurrent | ||
| /// calls on the same handle targeting disjoint ranges. Returns true on success; | ||
| /// on failure returns false and sets `error` (e.g. "pwrite failed at offset N | ||
| /// (errno M)"). | ||
| bool WriteFileAt(std::intptr_t handle, std::int64_t offset, const std::uint8_t* data, std::size_t len, | ||
| std::string& error); | ||
|
|
||
| /// Close `handle`. Returns true on success; on failure returns false and sets | ||
| /// `error`. A failing close can surface a deferred write error, so the data may | ||
| /// be incomplete even when every write succeeded. | ||
| bool CloseFile(std::intptr_t handle, std::string& error); | ||
|
|
||
| } // namespace fl::platform |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.