-
Notifications
You must be signed in to change notification settings - Fork 142
Update CLI log-cleaning function to preserve files if present #2811
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
Conversation
cliUtil tests use nested JSON structure to pass intended mocked structure to memfs' fromJSON method. This method does not parse nested JSON properly and carries on silently, resulting in misleading test results. Update test suite to not use nested JSON where possible, and where necessary use .fromNestedJSON instead.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2811 +/- ##
==========================================
+ Coverage 71.83% 71.85% +0.02%
==========================================
Files 134 134
Lines 7331 7340 +9
Branches 1622 1503 -119
==========================================
+ Hits 5266 5274 +8
- Misses 1937 2020 +83
+ Partials 128 46 -82 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull request overview
This PR fixes a bug where MarkBind CLI creates a _markbind/logs directory during markbind serve that doesn't get cleaned up when the command fails on an invalid folder. The fix changes the cleanup strategy from force-deleting directories to using rmdir, which only removes empty directories, thereby preserving any existing user files.
Changes:
- Replaced
fs.rmSync()withfs.rmdirSync()in a newtryDeleteFolder()helper function that silently skips non-empty directories - Added comprehensive test cases covering empty directories, non-empty directories, and partial cleanup scenarios
- Included unrelated package-lock.json updates (peer dependency flags and optional encoding package)
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/cli/src/util/cliUtil.js | Introduced tryDeleteFolder() function using rmdirSync() to delete only empty directories, with error handling for non-empty directories |
| packages/cli/test/unit/cliUtil.test.js | Updated and added test cases to verify the new behavior of preserving non-empty directories during cleanup |
| package-lock.json | Contains numerous peer dependency flag changes and adds an optional encoding package (appears unrelated to the main fix) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gerteck
left a comment
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.
LGTM, thanks @Harjun751
|
@gerteck Each PR must have a SEMVER impact label, please remember to label the PR properly. |
What is the purpose of this pull request?
This is a re-PR over #2810.
Wanted to try out cherry-picking, and that PR had a lot of visual noise from my repeated poking of Copilot.
Resolves #2767
Overview of changes:
Update CLI clean functionality to use
rmdirinstead of a force delete. This preserves the folder structure in the situation where files already exist in them. Added test cases to account for this case.Anything you'd like to highlight/discuss:
There is one instance in the cliUtil where I use
console.warnto print out a warning message. It should only occur when the system fails to delete an empty directory for an unexpected reason (e.g. permissions). I specifically useconsolebecause it felt odd to me to import and create a new instance of logger (which we're cleaning up after in that context...).Relevant snippet:
Testing instructions:
Proposed commit message: (wrap lines at 72 characters)
Update CLI clean function to preserve existing files
Checklist: ☑️
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major,r.Minor,r.Patch.Breaking change release note preparation (if applicable):