2023-04-11 14:57:01 +00:00
|
|
|
package files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/libs/sync"
|
2023-04-11 14:57:01 +00:00
|
|
|
)
|
|
|
|
|
2024-03-18 14:41:58 +00:00
|
|
|
func GetSync(ctx context.Context, b *bundle.Bundle) (*sync.Sync, error) {
|
|
|
|
opts, err := GetSyncOptions(ctx, b)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot get sync options: %w", err)
|
|
|
|
}
|
|
|
|
return sync.New(ctx, *opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetSyncOptions(ctx context.Context, b *bundle.Bundle) (*sync.SyncOptions, error) {
|
2023-09-11 08:18:43 +00:00
|
|
|
cacheDir, err := b.CacheDir(ctx)
|
2023-04-11 14:57:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-09-11 08:18:43 +00:00
|
|
|
includes, err := b.GetSyncIncludePatterns(ctx)
|
2023-08-18 08:07:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot get list of sync includes: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-03-18 14:41:58 +00:00
|
|
|
opts := &sync.SyncOptions{
|
2024-03-27 09:03:24 +00:00
|
|
|
LocalPath: b.RootPath,
|
2023-11-15 13:37:26 +00:00
|
|
|
RemotePath: b.Config.Workspace.FilePath,
|
2023-08-18 08:07:25 +00:00
|
|
|
Include: includes,
|
|
|
|
Exclude: b.Config.Sync.Exclude,
|
2024-03-18 14:41:58 +00:00
|
|
|
Host: b.WorkspaceClient().Config.Host,
|
2023-08-18 08:07:25 +00:00
|
|
|
|
2024-03-18 14:41:58 +00:00
|
|
|
Full: false,
|
2023-04-11 14:57:01 +00:00
|
|
|
|
|
|
|
SnapshotBasePath: cacheDir,
|
|
|
|
WorkspaceClient: b.WorkspaceClient(),
|
|
|
|
}
|
2024-03-18 14:41:58 +00:00
|
|
|
|
|
|
|
if b.Config.Workspace.CurrentUser != nil {
|
|
|
|
opts.CurrentUser = b.Config.Workspace.CurrentUser.User
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts, nil
|
2023-04-11 14:57:01 +00:00
|
|
|
}
|