Skip to content

fix databricks fs cp command #2901

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mukundkumarjha
Copy link

@mukundkumarjha mukundkumarjha commented May 17, 2025

If the destination directory does't exists cp command throws and error similar to linux cp command.

Fixes
#2835

Copy link

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

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 2901
  • Commit SHA: 34c007982b6d736fe9424bda40ae683b1c533005

Checks will be approved automatically on success.

@pietern
Copy link
Contributor

pietern commented May 19, 2025

@shreyas-goenka Can you take a look?

Copy link
Contributor

@shreyas-goenka shreyas-goenka left a comment

Choose a reason for hiding this comment

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

Hi @mukundkumarjha! Thanks for looking into this issue. This issue is more complex than it appears at first glance. In order to acceptant this contribution we would need:

  1. To think about what this means for users on Windows. We should also have the fix work on Windows.
  2. To match linux cp semantics, the command should not try to create a directory and should just error if the directory does not exist.
  3. Once resolved, please also consider adding a unit test. For example you can search for: TestFsCpFileToDir


// Check if target directory exists
_, err := c.targetFiler.Stat(c.ctx, targetDir)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the path has a trailing / but does not exist, we should error instead to match the semantics of the linux cp command. Could you please update this PR to do so?

@@ -196,6 +214,11 @@ func newCpCommand() *cobra.Command {
return c.cpFileToDir(sourcePath, targetPath)
}

// Check if target path ends with a slash, indicating it should be treated as a directory
if strings.HasSuffix(fullTargetPath, "/") || strings.HasSuffix(targetPath, "/") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if strings.HasSuffix(fullTargetPath, "/") || strings.HasSuffix(targetPath, "/") {
if strings.HasSuffix(fullTargetPath, "/") {

Checking fullTargetPath for a trailing slash should be enough. However, this also needs to work on Windows. In that case I'm not sure whether having this change means a breaking change for customers.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect using filepath.ToSlash would probably do the trick.

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.

4 participants