From 298fed28e523c8cf5f01a34cb1e87bd2eed0bcb1 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 5 Jun 2023 18:45:21 +0200 Subject: [PATCH] undo remote path public --- cmd/workspace/workspace/import_dir.go | 3 +- cmd/workspace/workspace/import_events.go | 11 +++---- libs/sync/repofiles/repofiles.go | 4 +-- libs/sync/repofiles/repofiles_test.go | 38 ++++++++++++------------ libs/sync/sync.go | 8 ----- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/cmd/workspace/workspace/import_dir.go b/cmd/workspace/workspace/import_dir.go index 266a6a524..c2c08bc39 100644 --- a/cmd/workspace/workspace/import_dir.go +++ b/cmd/workspace/workspace/import_dir.go @@ -54,9 +54,10 @@ var importDirCmd = &cobra.Command{ // Initialize error wait group, and spawn the progress event emitter inside // the error wait group group, ctx := errgroup.WithContext(ctx) + eventsChannel := s.Events() group.Go( func() error { - return renderSyncEvents(ctx, s.Events(), s) + return renderSyncEvents(ctx, eventsChannel, s) }) // Start Uploading local files diff --git a/cmd/workspace/workspace/import_events.go b/cmd/workspace/workspace/import_events.go index 7627691c8..74aebee22 100644 --- a/cmd/workspace/workspace/import_events.go +++ b/cmd/workspace/workspace/import_events.go @@ -53,11 +53,12 @@ func renderSyncEvents(ctx context.Context, eventChannel <-chan sync.Event, synce return nil } // TODO: test this works with windows paths - remotePath, err := syncer.RemotePath(progressEvent.Path) - if err != nil { - return err - } - err = cmdio.Render(ctx, newUploadCompleteEvent(progressEvent.Path, remotePath)) + // remotePath, err := syncer.RemotePath(progressEvent.Path) + // if err != nil { + // return err + // } + remotePath := "TODO" + err := cmdio.Render(ctx, newUploadCompleteEvent(progressEvent.Path, remotePath)) if err != nil { return err } diff --git a/libs/sync/repofiles/repofiles.go b/libs/sync/repofiles/repofiles.go index 9a6428a16..6ea9f6bd7 100644 --- a/libs/sync/repofiles/repofiles.go +++ b/libs/sync/repofiles/repofiles.go @@ -49,7 +49,7 @@ func Create(repoRoot, localRoot string, w *databricks.WorkspaceClient, opts *Rep }, nil } -func (r *RepoFiles) RemotePath(relativePath string) (string, error) { +func (r *RepoFiles) remotePath(relativePath string) (string, error) { fullPath := path.Join(r.repoRoot, relativePath) cleanFullPath := path.Clean(fullPath) if !strings.HasPrefix(cleanFullPath, r.repoRoot) { @@ -82,7 +82,7 @@ func (r *RepoFiles) writeRemote(ctx context.Context, relativePath string, conten // files, folders and notebooks might not have been cleaned up and they // can't overwrite each other. If a folder `foo` exists, then attempts to // PUT a file `foo` will fail - remotePath, err := r.RemotePath(relativePath) + remotePath, err := r.remotePath(relativePath) if err != nil { return err } diff --git a/libs/sync/repofiles/repofiles_test.go b/libs/sync/repofiles/repofiles_test.go index ce2a14c2c..dc9abbcdd 100644 --- a/libs/sync/repofiles/repofiles_test.go +++ b/libs/sync/repofiles/repofiles_test.go @@ -14,66 +14,66 @@ func TestRepoFilesRemotePath(t *testing.T) { repoFiles, err := Create(repoRoot, "/doraemon/foo/bar", nil, nil) require.NoError(t, err) - remotePath, err := repoFiles.RemotePath("a/b/c") + remotePath, err := repoFiles.remotePath("a/b/c") assert.NoError(t, err) assert.Equal(t, repoRoot+"/a/b/c", remotePath) - remotePath, err = repoFiles.RemotePath("a/b/../d") + remotePath, err = repoFiles.remotePath("a/b/../d") assert.NoError(t, err) assert.Equal(t, repoRoot+"/a/d", remotePath) - remotePath, err = repoFiles.RemotePath("a/../c") + remotePath, err = repoFiles.remotePath("a/../c") assert.NoError(t, err) assert.Equal(t, repoRoot+"/c", remotePath) - remotePath, err = repoFiles.RemotePath("a/b/c/.") + remotePath, err = repoFiles.remotePath("a/b/c/.") assert.NoError(t, err) assert.Equal(t, repoRoot+"/a/b/c", remotePath) - remotePath, err = repoFiles.RemotePath("a/b/c/d/./../../f/g") + remotePath, err = repoFiles.remotePath("a/b/c/d/./../../f/g") assert.NoError(t, err) assert.Equal(t, repoRoot+"/a/b/f/g", remotePath) - _, err = repoFiles.RemotePath("..") + _, err = repoFiles.remotePath("..") assert.ErrorContains(t, err, `relative file path is not inside repo root: ..`) - _, err = repoFiles.RemotePath("a/../..") + _, err = repoFiles.remotePath("a/../..") assert.ErrorContains(t, err, `relative file path is not inside repo root: a/../..`) - _, err = repoFiles.RemotePath("./../.") + _, err = repoFiles.remotePath("./../.") assert.ErrorContains(t, err, `relative file path is not inside repo root: ./../.`) - _, err = repoFiles.RemotePath("/./.././..") + _, err = repoFiles.remotePath("/./.././..") assert.ErrorContains(t, err, `relative file path is not inside repo root: /./.././..`) - _, err = repoFiles.RemotePath("./../.") + _, err = repoFiles.remotePath("./../.") assert.ErrorContains(t, err, `relative file path is not inside repo root: ./../.`) - _, err = repoFiles.RemotePath("./..") + _, err = repoFiles.remotePath("./..") assert.ErrorContains(t, err, `relative file path is not inside repo root: ./..`) - _, err = repoFiles.RemotePath("./../../..") + _, err = repoFiles.remotePath("./../../..") assert.ErrorContains(t, err, `relative file path is not inside repo root: ./../../..`) - _, err = repoFiles.RemotePath("./../a/./b../../..") + _, err = repoFiles.remotePath("./../a/./b../../..") assert.ErrorContains(t, err, `relative file path is not inside repo root: ./../a/./b../../..`) - _, err = repoFiles.RemotePath("../..") + _, err = repoFiles.remotePath("../..") assert.ErrorContains(t, err, `relative file path is not inside repo root: ../..`) - _, err = repoFiles.RemotePath(".//a/..//./b/..") + _, err = repoFiles.remotePath(".//a/..//./b/..") assert.ErrorContains(t, err, `file path relative to repo root cannot be empty`) - _, err = repoFiles.RemotePath("a/b/../..") + _, err = repoFiles.remotePath("a/b/../..") assert.ErrorContains(t, err, "file path relative to repo root cannot be empty") - _, err = repoFiles.RemotePath("") + _, err = repoFiles.remotePath("") assert.ErrorContains(t, err, "file path relative to repo root cannot be empty") - _, err = repoFiles.RemotePath(".") + _, err = repoFiles.remotePath(".") assert.ErrorContains(t, err, "file path relative to repo root cannot be empty") - _, err = repoFiles.RemotePath("/") + _, err = repoFiles.remotePath("/") assert.ErrorContains(t, err, "file path relative to repo root cannot be empty") } diff --git a/libs/sync/sync.go b/libs/sync/sync.go index de8cea65e..505c9d3f7 100644 --- a/libs/sync/sync.go +++ b/libs/sync/sync.go @@ -135,14 +135,6 @@ func (s *Sync) notifyComplete(ctx context.Context, d diff) { s.seq++ } -func (s *Sync) RemotePath(localPath string) (string, error) { - relativePath, ok := s.snapshot.LocalToRemoteNames[localPath] - if !ok { - return "", fmt.Errorf("could not find remote path for %s", localPath) - } - return s.repoFiles.RemotePath(relativePath) -} - func (s *Sync) RunOnce(ctx context.Context) error { // tradeoff: doing portable monitoring only due to macOS max descriptor manual ulimit setting requirement // https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/observers/kqueue.py#L394-L418