| 1 |
Test behavior when a symlink chain goes through a file outside the target directory. |
| 2 |
e.g., link.txt -> $PWD/intermediate.txt -> real.txt (where intermediate is outside) |
| 3 |
|
| 4 |
The chain goes through an outside path, but the final target is inside target_dir. |
| 5 |
This case is pathological, but we want to exercise our symlink resolution code. |
| 6 |
|
| 7 |
$ export DUNE_CACHE=enabled |
| 8 |
$ export DUNE_CACHE_ROOT=$PWD/_cache |
| 9 |
|
| 10 |
$ make_lockdir |
| 11 |
|
| 12 |
Create a directory outside the build for the intermediate symlink: |
| 13 |
|
| 14 |
$ mkdir outside_dir |
| 15 |
|
| 16 |
$ make_lockpkg foo <<EOF |
| 17 |
> (version 0.0.1) |
| 18 |
> (build |
| 19 |
> (system "\ |
| 20 |
> mkdir -p %{lib}/%{pkg-self:name} \ |
| 21 |
> && printf 'real content\n' > %{lib}/%{pkg-self:name}/real.txt \ |
| 22 |
> && ln -sf \$(realpath %{lib}/%{pkg-self:name}/real.txt) $PWD/outside_dir/intermediate.txt \ |
| 23 |
> && ln -s $PWD/outside_dir/intermediate.txt %{lib}/%{pkg-self:name}/link.txt \ |
| 24 |
> && touch %{lib}/%{pkg-self:name}/META")) |
| 25 |
> EOF |
| 26 |
|
| 27 |
$ cat > dune-project <<EOF |
| 28 |
> (lang dune 3.22) |
| 29 |
> (package |
| 30 |
> (name x) |
| 31 |
> (allow_empty) |
| 32 |
> (depends foo)) |
| 33 |
> EOF |
| 34 |
|
| 35 |
Build the package: |
| 36 |
|
| 37 |
$ build_pkg foo |
| 38 |
|
| 39 |
The symlink should be resolved to a regular file: |
| 40 |
|
| 41 |
$ dune_cmd stat kind $(get_build_pkg_dir foo)/target/lib/foo/link.txt |
| 42 |
regular file |
| 43 |
|
| 44 |
link.txt and real.txt should be hardlinks to the same file (hardlink count > 1): |
| 45 |
|
| 46 |
$ dune_cmd stat hardlinks $(get_build_pkg_dir foo)/target/lib/foo/link.txt |
| 47 |
3 |
| 48 |
$ dune_cmd stat hardlinks $(get_build_pkg_dir foo)/target/lib/foo/real.txt |
| 49 |
3 |
| 50 |
|
| 51 |
The outside intermediate has only 1 hardlink (it's still just a symlink): |
| 52 |
|
| 53 |
$ dune_cmd stat hardlinks outside_dir/intermediate.txt |
| 54 |
1 |
| 55 |
|
| 56 |
$ cat $(get_build_pkg_dir foo)/target/lib/foo/link.txt |
| 57 |
real content |
| 58 |
|
| 59 |
Caching works - the symlink was resolved so it can be cached: |
| 60 |
|
| 61 |
$ rm -rf _build |
| 62 |
$ build_pkg foo |
| 63 |
$ dune_cmd stat hardlinks $(get_build_pkg_dir foo)/target/lib/foo/link.txt |
| 64 |
3 |