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-04-18 15:13:16 +00:00
|
|
|
func GetSync(ctx context.Context, rb bundle.ReadOnlyBundle) (*sync.Sync, error) {
|
|
|
|
opts, err := GetSyncOptions(ctx, rb)
|
2024-03-18 14:41:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot get sync options: %w", err)
|
|
|
|
}
|
|
|
|
return sync.New(ctx, *opts)
|
|
|
|
}
|
|
|
|
|
2024-04-18 15:13:16 +00:00
|
|
|
func GetSyncOptions(ctx context.Context, rb bundle.ReadOnlyBundle) (*sync.SyncOptions, error) {
|
|
|
|
cacheDir, err := rb.CacheDir(ctx)
|
2023-04-11 14:57:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot get bundle cache directory: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-04-18 15:13:16 +00:00
|
|
|
includes, err := rb.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-08-21 15:33:25 +00:00
|
|
|
LocalRoot: rb.SyncRoot(),
|
|
|
|
Paths: rb.Config().Sync.Paths,
|
2024-08-19 15:41:02 +00:00
|
|
|
Include: includes,
|
|
|
|
Exclude: rb.Config().Sync.Exclude,
|
|
|
|
|
2024-04-18 15:13:16 +00:00
|
|
|
RemotePath: rb.Config().Workspace.FilePath,
|
|
|
|
Host: rb.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,
|
2024-04-18 15:13:16 +00:00
|
|
|
WorkspaceClient: rb.WorkspaceClient(),
|
2023-04-11 14:57:01 +00:00
|
|
|
}
|
2024-03-18 14:41:58 +00:00
|
|
|
|
2024-04-18 15:13:16 +00:00
|
|
|
if rb.Config().Workspace.CurrentUser != nil {
|
|
|
|
opts.CurrentUser = rb.Config().Workspace.CurrentUser.User
|
2024-03-18 14:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return opts, nil
|
2023-04-11 14:57:01 +00:00
|
|
|
}
|