Skip to content

Commit

Permalink
Copy dir if symlink fails (#7447)
Browse files Browse the repository at this point in the history
  • Loading branch information
anjutiwari authored Aug 9, 2023
1 parent 44d1e73 commit 8c98ef3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230424-210734.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Copy dir during `dbt deps` if symlink fails
time: 2023-04-24T21:07:34.336797+05:30
custom:
Author: anjutiwari
Issue: "7428 8223"
8 changes: 2 additions & 6 deletions core/dbt/deps/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,15 @@ def install(self, project, renderer):
src_path = self.resolve_path(project)
dest_path = self.get_installation_path(project, renderer)

can_create_symlink = system.supports_symlinks()

if system.path_exists(dest_path):
if not system.path_is_symlink(dest_path):
system.rmdir(dest_path)
else:
system.remove_file(dest_path)

if can_create_symlink:
try:
fire_event(DepsCreatingLocalSymlink())
system.make_symlink(src_path, dest_path)

else:
except OSError:
fire_event(DepsSymlinkNotAvailable())
shutil.copytree(src_path, dest_path)

Expand Down
17 changes: 16 additions & 1 deletion tests/unit/test_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import dbt.deps
import dbt.exceptions
from dbt.deps.git import GitUnpinnedPackage
from dbt.deps.local import LocalUnpinnedPackage
from dbt.deps.local import LocalUnpinnedPackage, LocalPinnedPackage
from dbt.deps.tarball import TarballUnpinnedPackage
from dbt.deps.registry import RegistryUnpinnedPackage
from dbt.clients.registry import is_compatible_version
Expand Down Expand Up @@ -92,6 +92,21 @@ def test_init(self):
self.assertEqual(a_pinned.source_type(), "git")
self.assertIs(a_pinned.warn_unpinned, True)

@mock.patch("shutil.copytree")
@mock.patch("dbt.deps.local.system.make_symlink")
@mock.patch("dbt.deps.local.LocalPinnedPackage.get_installation_path")
@mock.patch("dbt.deps.local.LocalPinnedPackage.resolve_path")
def test_deps_install(
self, mock_resolve_path, mock_get_installation_path, mock_symlink, mock_shutil
):
mock_resolve_path.return_value = "/tmp/source"
mock_get_installation_path.return_value = "/tmp/dest"
mock_symlink.side_effect = OSError("Install deps symlink error")

LocalPinnedPackage("local").install("dummy", "dummy")
self.assertEqual(mock_shutil.call_count, 1)
mock_shutil.assert_called_once_with("/tmp/source", "/tmp/dest")

def test_invalid(self):
with self.assertRaises(ValidationError):
GitPackage.validate(
Expand Down

0 comments on commit 8c98ef3

Please sign in to comment.