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

Utilities/cp: Canonicalize path for existing destination directories #25435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Userland/Utilities/cp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool destination_is_existing_dir = FileSystem::is_directory(destination);

for (auto& source : sources) {
// FIXME: May be formatted wrong if destination is a directory with a trailing slash, e.g. if called as such:
// cp source dest/
// ... `destination_path` may be formatted as `dest//source`, which isn't strictly correct.
auto destination_path = destination_is_existing_dir
? ByteString::formatted("{}/{}", destination, LexicalPath::basename(source))
? LexicalPath::canonicalized_path(ByteString::formatted("{}/{}", destination, LexicalPath::basename(source)))
ninadsachania marked this conversation as resolved.
Show resolved Hide resolved
: destination;

if (interactive && FileSystem::exists(destination_path)) {
Expand Down
Loading