stow/t
Adam Spiers afa50077c9 dotfiles: switch {un,}stow_{contents,node}() recursion parameters
Stow walks the package and target tree hierarchies by using mutually
recursive pairs of functions:

- `stow_contents()` and `stow_node()`
- `unstow_contents()` and `unstow_node()`

As Stow runs its planning from the target directory (`plan_*()` both
call `within_target_do()`), previously the parameters for these
included:

- `$target_subpath` (or `$target_subdir` in the `*_node()` functions):
  the relative path from the target top-level directory to the target
  subdirectory (initially `.` at the beginning of recursion).  For
  example, this could be `dir1/subdir1/file1`.

- `$source`: the relative path from the target _subdirectory_ (N.B. _not_
  top-level directory) to the package subdirectory.  For example, if
  the relative path to the Stow directory is `../stow`, this could be
  `../../../stow/pkg1/dir1/subdir1/file1`.  This is used when stowing
  to construct a new link, or when unstowing to detect whether the
  link can be unstowed.

Each time it descends into a further subdirectory of the target and
package, it appends the new path segment onto both of these, and also
prefixes `$source` with another `..`.  When the `--dotfiles` parameter
is enabled, it adjusts `$target_subdir`, performing the `dot-foo` =>
`.foo` adjustment on all segments of the path in one go.  In this
case, `$target_subpath` could be something like `.dir1/subdir1/file1`,
and the corresponding `$source` could be something like
`../../../stow/pkg1/dot-dir1/subdir1/file1`.

However this doesn't leave an easy way to obtain the relative path
from the target _top-level_ directory to the package subdirectory
(i.e. `../stow/pkg1/dot-dir1/subdir1/file1`), which is needed for
checking its existence and if necessary iterating over its contents.

The current implementation solves this by including an extra `$level`
parameter which tracks the recursion depth, and uses that to strip the
right number of leading path segments off the front of `$source`.
(In the above example, it would remove `../..`.)

This implementation isn't the most elegant because:

- It involves adding things to `$source` and then removing them again.

- It performs the `dot-` => `.` adjustment on every path segment
  at each level, which is overkill, since when recursing down a level,
  only adjustment on the final subdirectory is required since the higher
  segments have already had any required adjustment.

  This in turn requires `adjust_dotfile` to be more complex than it
  needs to be.

  It also prevents a potential future where we might want Stow to
  optionally start iterating from within a subdirectory of the whole
  package install image / target tree, avoiding adjustment at higher
  levels and only doing it at the levels below the starting point.

- It requires passing an extra `$level` parameter which can be
  automatically calculated simply by counting the number of slashes
  in `$target_subpath`.

So change the `$source` recursion parameter to instead track the
relative path from the top-level package directory to the package
subdirectory or file being considered for (un)stowing, and rename it
to avoid the ambiguity caused by the word "source".

Also automatically calculate the depth simply by counting the number
of slashes, and reconstruct `$source` when needed by combining the
relative path to the Stow directory with the package name and
`$target_subpath`.

Closes #33.
2024-04-07 17:21:07 +01:00
..
chkstow.t Replace testutil::make_dir with File::Path::make_path 2019-06-28 01:02:48 +01:00
cleanup_invalid_links.t cleanup_invalid_links: add test for non-cleanup of an unowned link 2024-03-31 12:24:02 +01:00
cli.t cli.t: test with the right Perl executable 2019-07-15 16:12:26 -04:00
cli_options.t Replace testutil::make_dir with File::Path::make_path 2019-06-28 01:02:48 +01:00
defer.t Rename $OUT_DIR to $TEST_DIR 2019-06-28 00:53:12 +01:00
dotfiles.t dotfiles: switch {un,}stow_{contents,node}() recursion parameters 2024-04-07 17:21:07 +01:00
examples.t Replace testutil::make_dir with File::Path::make_path 2019-06-28 01:02:48 +01:00
find_stowed_path.t Eliminate erroneous warning when unstowing (#65) 2024-03-31 14:03:47 +01:00
foldable.t Replace testutil::make_dir with File::Path::make_path 2019-06-28 01:02:48 +01:00
ignore.t Replace testutil::make_dir with File::Path::make_path 2019-06-28 01:02:48 +01:00
join_paths.t Make join_paths correctly handle absolute paths 2024-03-31 12:02:58 +01:00
link_dest_within_stow_dir.t Eliminate erroneous warning when unstowing (#65) 2024-03-31 14:03:47 +01:00
parent.t Change #!/usr/local/bin/perl to #!/usr/bin/perl in t/*.t 2019-06-27 20:37:50 +01:00
rc_options.t Remove dependencies on Hash::Merge and Clone::Choose 2019-06-29 13:42:19 +01:00
stow.t tests: use stderr_like() instead of home-grown STDERR capturing 2024-04-06 11:33:18 +01:00
testutil.pm merge unstow_orig.t into unstow.t and fix unstowing logic 2024-04-07 15:47:38 +01:00
unstow.t unstow_link_node(): don't register conflicts when unstowing unowned links 2024-04-07 15:47:38 +01:00