mirror of https://github.com/databricks/cli.git
Fix windows style file paths in fs cp command (#1118)
## Changes Copying a local file in windows to remote directory in DBFS would fail if the path was specified as a windows style path (compared to a UNIX style path). This PR fixes that. Note, UNIX style paths will continue to work because `filepath.Base` respects both `/` and `\` as file separators. See: `IsPathSeparator` in https://go.dev/src/os/path_windows.go. Fixes issue: https://github.com/databricks/cli/issues/1109. ## Tests Integration test and manually ``` C:\Users\shreyas.goenka>Desktop\cli.exe fs cp .\Desktop\foo.txt dbfs:/Users/shreyas.goenka@databricks.com .\Desktop\foo.txt -> dbfs:/Users/shreyas.goenka@databricks.com/foo.txt C:\Users\shreyas.goenka>Desktop\cli.exe fs cat dbfs:/Users/shreyas.goenka@databricks.com/foo.txt hello, world ````
This commit is contained in:
parent
7dcdadde79
commit
2c0d06715c
|
@ -60,7 +60,7 @@ func (c *copy) cpDirToDir(sourceDir, targetDir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *copy) cpFileToDir(sourcePath, targetDir string) error {
|
func (c *copy) cpFileToDir(sourcePath, targetDir string) error {
|
||||||
fileName := path.Base(sourcePath)
|
fileName := filepath.Base(sourcePath)
|
||||||
targetPath := path.Join(targetDir, fileName)
|
targetPath := path.Join(targetDir, fileName)
|
||||||
|
|
||||||
return c.cpFileToFile(sourcePath, targetPath)
|
return c.cpFileToFile(sourcePath, targetPath)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -140,6 +141,22 @@ func TestAccFsCpFileToDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccFsCpFileToDirForWindowsPaths(t *testing.T) {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
t.Skip("Skipping test on non-windows OS")
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
sourceFiler, sourceDir := setupLocalFiler(t)
|
||||||
|
targetFiler, targetDir := setupDbfsFiler(t)
|
||||||
|
setupSourceFile(t, ctx, sourceFiler)
|
||||||
|
|
||||||
|
windowsPath := filepath.Join(filepath.FromSlash(sourceDir), "foo.txt")
|
||||||
|
|
||||||
|
RequireSuccessfulRun(t, "fs", "cp", windowsPath, targetDir)
|
||||||
|
assertTargetFile(t, ctx, targetFiler, "foo.txt")
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccFsCpDirToDirFileNotOverwritten(t *testing.T) {
|
func TestAccFsCpDirToDirFileNotOverwritten(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
table := setupTable()
|
table := setupTable()
|
||||||
|
|
Loading…
Reference in New Issue