Skip to content
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

fs: fix rmSync to handle non-ASCII characters #56934

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Yeaseen
Copy link

@Yeaseen Yeaseen commented Feb 6, 2025

This is a fresh version of PR #56117

Update fs.rmSync to properly handle file paths that include non-ASCII characters. This change prevents crashes and errors when attempting to delete files with international or special characters in their names.

Add two tests in test/parallel/ to ensure that files with non-ASCII characters can be deleted without issues. This covers cases that previously caused unexpected behavior or crashes on certain file systems.

Fixes: #56049

@lemire I had to close the previous PR due to some conflicts. Please review this. Thank you!

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Feb 6, 2025
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you don't need to open a new PR to address the conflicts - usually it's fine to just rebase against the latest main branch, squash the commits if that's easier, and force push to your PR branch.

src/node_file.cc Outdated Show resolved Hide resolved
@Yeaseen
Copy link
Author

Yeaseen commented Feb 6, 2025

@joyeecheung, thanks for your suggestion. I resolved the conflict with the latest main branch. But, due to the changes in the helper, in CI the conflict was coming from one of my own commits in that PR. Then, I tried to do cherry pick for that commit hash, but I did the reverse of what I wanted to do. And it became messy. I will recreate this scenario locally to learn how to handle this.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 6, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 6, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.17%. Comparing base (1671921) to head (81955c8).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/node_file.cc 37.50% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56934      +/-   ##
==========================================
+ Coverage   89.15%   89.17%   +0.01%     
==========================================
  Files         665      665              
  Lines      192798   192800       +2     
  Branches    37130    37121       -9     
==========================================
+ Hits       171886   171921      +35     
+ Misses      13673    13670       -3     
+ Partials     7239     7209      -30     
Files with missing lines Coverage Δ
src/api/exceptions.cc 94.18% <100.00%> (ø)
src/node_file.cc 77.21% <37.50%> (-0.03%) ⬇️

... and 26 files with indirect coverage changes

@Yeaseen
Copy link
Author

Yeaseen commented Feb 6, 2025

@joyeecheung It looks like all checks passed except the first git commit message one, where I must explicitly put the GitHub link. Should I just amend the first commit message and push it here?

@joyeecheung
Copy link
Member

Yes, you'll need to update it to pull a full GitHub link

@Yeaseen Yeaseen force-pushed the fix-non-ascii-filepath-issue branch from 81955c8 to 100424e Compare February 6, 2025 20:17
@Yeaseen
Copy link
Author

Yeaseen commented Feb 6, 2025

@joyeecheung updated.

@joyeecheung
Copy link
Member

Hmm, I think you'll need to rebase against the latest main branch and drop the other commits that you've pulled in somehow from the main branch. You can use use something like git fetch origin main then git rebase origin/main -i and remove the unrelated commits.

Update fs.rmSync to properly handle file paths that include
non-ASCII characters. This change prevents crashes and errors
when attempting to delete files with international or special
characters in their names.

Add two tests in test/parallel to ensure that files with
non-ASCII characters can be deleted without issues. This
covers cases that previously caused unexpected behavior or
crashes on certain file systems.

Fixes: nodejs#56049
@Yeaseen Yeaseen force-pushed the fix-non-ascii-filepath-issue branch from 100424e to 50accca Compare February 7, 2025 16:34
@Yeaseen
Copy link
Author

Yeaseen commented Feb 7, 2025

@joyeecheung Thanks for the suggestion! It worked. Learned a lof things!

return env->ThrowErrnoException(ENOTDIR, "rm", message.c_str(), path_c_str);
} else if (error == std::errc::permission_denied) {
std::string message = "Permission denied: " + file_path_str;
std::string message = "Permission denied: ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the paths from the error messages?

@@ -41,8 +56,7 @@ Local<Value> ErrnoException(Isolate* isolate,

Local<String> path_string;
if (path != nullptr) {
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
path_string = String::NewFromUtf8(isolate, path).ToLocalChecked();
path_string = StringFromPath(isolate, path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This FIXME should not be removed, isn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs.rmSync('速') crash without throw
5 participants