Skip to content

solution#377

Open
Nika-Andriy wants to merge 1 commit into
mate-academy:masterfrom
Nika-Andriy:develop
Open

solution#377
Nika-Andriy wants to merge 1 commit into
mate-academy:masterfrom
Nika-Andriy:develop

Conversation

@Nika-Andriy

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because the current implementation does not fully satisfy the required mv-like semantics for destination paths, which is a functional requirement rather than a style concern. The main blocking issue is that a destination ending with / is not explicitly treated as a directory that must exist; for example, node index file.txt dir/ should fail with a clear error when dir does not exist, instead of just passing the path into fs.rename. You should add logic near your destination handling (around where you currently use destStat) to: (1) detect dest.endsWith('/'), (2) resolve that to a directory path, and (3) stat it and throw/log an error if the directory is missing.

A second critical issue is that you do not verify that the parent directory exists when the destination is treated as a file path, e.g. ./existingDir/test. For a case like node index file.txt ./nonExistingDir/test, the requirement says the destination directory must exist, so before calling fs.rename you should compute const parent = path.dirname(dest) and ensure parent exists and is a directory; if not, surface a clear error instead of relying solely on the generic fs.rename failure. These two behaviors are needed to correctly implement the specified rules about destination directories and will likely be covered by tests. Aside from these directory-handling gaps, your handling of simple renames and moves into existing directories looks solid, so once you add these checks your solution should be in good shape.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/app.js
Comment on lines +21 to +34
let destination = dest;
const destStat = await fs.stat(dest).catch((error) => {
if (error.code === 'ENOENT') {
return null;
}

throw error;
});

if (destStat?.isDirectory()) {
destination = path.join(dest, path.basename(source));
}

await fs.rename(source, destination);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The current implementation only checks whether dest itself is an existing directory; it does not implement the special rule that a path ending with / must be treated as a directory (and must exist), nor does it verify that the parent directory exists for file-like destinations such as ./existingDir/test. Consider adding logic to (1) treat dest ending with / as a directory name and fail if that directory does not exist, and (2) ensure the parent directory of destination exists before calling fs.rename, to comply with the specification about destination directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants