fix(patch): cherry-pick 81ccd80 to release/v0.28.0-preview.5-pr-18406 to patch version v0.28.0-preview.5 and create version 0.28.0-preview.6#18651
Conversation
Summary of ChangesHello @gemini-cli-robot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request is an automated cherry-pick to patch a preview release, primarily focusing on enhancing the robustness and reliability of folder trust management. It introduces asynchronous and atomic file operations for saving trusted folder configurations, utilizing the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the 'trusted folders' functionality to use asynchronous file operations and ensure atomic writes, primarily by introducing the 'proper-lockfile' dependency. The trustedFolders.setValue method is updated to be asynchronous, utilizing file locking to prevent race conditions during concurrent updates and implementing a safe write pattern (write to temp file, then rename) to avoid data corruption. The changes also include updating various UI components and hooks to correctly await the now-asynchronous setValue calls, and modifying test suites to reflect these asynchronous behaviors and to test real file system interactions with locking. A review comment specifically highlighted the need to replace synchronous fs.existsSync calls with asynchronous alternatives like fsPromises.access within the setValue method to prevent blocking the event loop, which was addressed in the code changes.
| if (!fs.existsSync(dirPath)) { | ||
| await fsPromises.mkdir(dirPath, { recursive: true }); | ||
| } | ||
|
|
||
| // lockfile requires the file to exist | ||
| if (!fs.existsSync(this.user.path)) { | ||
| await fsPromises.writeFile(this.user.path, JSON.stringify({}, null, 2), { | ||
| mode: 0o600, | ||
| }); | ||
| } |
There was a problem hiding this comment.
This block uses synchronous fs.existsSync calls within an async function, which can block the event loop. It's better to use asynchronous alternatives. For creating the directory, the check is redundant as mkdir with { recursive: true } handles it. For checking if the file exists before locking, you can use fsPromises.access in a try/catch block. This aligns with the general preference for asynchronous file system operations to avoid blocking the event loop.
| if (!fs.existsSync(dirPath)) { | |
| await fsPromises.mkdir(dirPath, { recursive: true }); | |
| } | |
| // lockfile requires the file to exist | |
| if (!fs.existsSync(this.user.path)) { | |
| await fsPromises.writeFile(this.user.path, JSON.stringify({}, null, 2), { | |
| mode: 0o600, | |
| }); | |
| } | |
| await fsPromises.mkdir(dirPath, { recursive: true }); | |
| // lockfile requires the file to exist | |
| try { | |
| await fsPromises.access(this.user.path); | |
| } catch { | |
| await fsPromises.writeFile(this.user.path, JSON.stringify({}, null, 2), { | |
| mode: 0o600, | |
| }); | |
| } |
References
- Use asynchronous file system operations (e.g.,
fs.promises.readFile) instead of synchronous ones (e.g.,fs.readFileSync) to avoid blocking the event loop.
|
Size Change: +28.2 kB (+0.12%) Total Size: 23.7 MB
ℹ️ View Unchanged
|
9506601
into
release/v0.28.0-preview.5-pr-18406
This PR automatically cherry-picks commit 81ccd80 to patch version v0.28.0-preview.5 in the preview release to create version 0.28.0-preview.6.