Skip to content

Conversation

@varundeepsaini
Copy link

Fixes: #2835

Changes

Fixed handling of trailing directory separators in the cp command. When a target path ends with / or \, the command now validates that the directory exists before copying. If the directory doesn't exist, it returns a clear error message instead of failing later.

Added a helper function hasTrailingDirSeparator to detect trailing directory separators for both Unix-style (/) and Windows-style (\) paths.

Why

Previously, the cp command didn't properly handle trailing directory separators. When users specified a target path like target/dir/ (expecting it to be treated as a directory), the command would not validate that the directory exists first, leading to confusing error messages later in the copy process. This change ensures that trailing directory separators are explicitly treated as indicating a directory target, and validates that the directory exists upfront.

Tests

Added unit tests in integration/cmd/fs/cp_test.go:

  • TestFsCpFileToNonExistentDir: Tests copying files to both existing and non-existent directories with trailing slashes
  • TestFsCpFileToNonExistentDirWindowsPaths: Windows-specific tests for trailing backslashes (\) and forward slashes (/) on Windows

The tests verify that:

  • Copying to an existing directory with a trailing separator succeeds
  • Copying to a non-existent directory with a trailing separator returns an appropriate error message
  • Both Unix-style (/) and Windows-style (\) separators are handled correctly

@varundeepsaini
Copy link
Author

Hey @shreyas-goenka

Can you review this pr

@andrewnester
Copy link
Contributor

Hi @varundeepsaini ! Thanks for the PR! Contributing to CLI requires a signed CLA If that's something you're willing to do, please reach out with a request to sign the CLA to [email protected], and we will take it from there.

Thank you!

@varundeepsaini
Copy link
Author

Hey @andrewnester

Have sent the email

@varundeepsaini
Copy link
Author

@andrewnester
Pushed changes

@github-actions
Copy link

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 3921
  • Commit SHA: 533bece4066fb926537261856ede6e3d9d50f2bc

Checks will be approved automatically on success.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

databricks fs cp does not detect trailing slashes for file copy

2 participants