diff --git a/stow.in b/stow.in index 837f2b5..dee5d8a 100755 --- a/stow.in +++ b/stow.in @@ -113,13 +113,13 @@ if (not caller()) { if ($Option{'compat'}) { unstow_contents_orig( join_paths($Stow_Path, $package), # path to package - '', # target is current_dir + '.', # target is current_dir ); } else { unstow_contents( join_paths($Stow_Path, $package), # path to package - '', # target is current_dir + '.', # target is current_dir ); } debug(2, "Unstowing package $package... done"); @@ -132,7 +132,7 @@ if (not caller()) { debug(2, "Stowing package $package..."); stow_contents( join_paths($Stow_Path, $package), # path package - '', # target is current dir + '.', # target is current dir join_paths($Stow_Path, $package), # source from target ); debug(2, "Stowing package $package... done"); @@ -407,9 +407,10 @@ sub stow_contents { debug(2, "Stowing contents of $path (cwd is $cwd)"); debug(3, "--- $target => $source"); - if (not -d $path) { - error("stow_contents() called on a non-directory: $path"); - } + error("stow_contents() called with non-directory path: $path") + unless -d $path; + error("stow_contents() called with non-directory target: $target") + unless is_a_node($target); opendir my $DIR, $path or error("cannot read directory: $path"); @@ -552,9 +553,11 @@ sub unstow_contents_orig { my $cwd = getcwd(); debug(2, "Unstowing from $target (compat mode, cwd is $cwd)"); debug(3, "--- source path is $path"); - if (not -d $target) { - error("unstow_contents() called on a non-directory: $target"); - } + # In compat mode we traverse the target tree not the source tree, + # so we're unstowing the contents of /target/foo, there's no + # guarantee that the corresponding /stow/mypkg/foo exists. + error("unstow_contents_orig() called with non-directory target: $target") + unless -d $target; opendir my $DIR, $target or error("cannot read directory: $target"); @@ -653,9 +656,11 @@ sub unstow_contents { my $cwd = getcwd(); debug(2, "Unstowing from $target (cwd is $cwd)"); debug(3, "--- source path is $path"); - if (not -d $path) { - error("unstow_contents() called on a non-directory: $path"); - } + # We traverse the source tree not the target tree, + error("unstow_contents() called with non-directory path: $path") + unless -d $path; + error("unstow_contents() called with non-directory target: $target") + unless is_a_node($target); opendir my $DIR, $path or error("cannot read directory: $path"); diff --git a/t/stow_contents.t b/t/stow_contents.t index e27d17b..97645c2 100755 --- a/t/stow_contents.t +++ b/t/stow_contents.t @@ -57,7 +57,7 @@ $Option{'verbose'} = 0; make_dir('../stow/pkg2/lib2'); make_file('../stow/pkg2/lib2/file2'); make_dir('lib2'); -stow_contents('../stow/pkg2', './', '../stow/pkg2'); +stow_contents('../stow/pkg2', '.', '../stow/pkg2'); process_tasks(); is( readlink('lib2/file2'), diff --git a/t/unstow_contents.t b/t/unstow_contents.t index 7dd3d6b..817f544 100755 --- a/t/unstow_contents.t +++ b/t/unstow_contents.t @@ -43,7 +43,7 @@ make_dir('../stow/pkg1/bin1'); make_file('../stow/pkg1/bin1/file1'); make_link('bin1','../stow/pkg1/bin1'); -unstow_contents('../stow/pkg1','./'); +unstow_contents('../stow/pkg1','.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -61,7 +61,7 @@ make_dir('lib2'); make_dir('../stow/pkg2/lib2'); make_file('../stow/pkg2/lib2/file2'); make_link('lib2/file2', '../../stow/pkg2/lib2/file2'); -unstow_contents('../stow/pkg2','./'); +unstow_contents('../stow/pkg2','.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -84,7 +84,7 @@ make_link('bin3/file3a' => '../../stow/pkg3a/bin3/file3a'); # emulate stow make_dir('../stow/pkg3b/bin3'); make_file('../stow/pkg3b/bin3/file3b'); make_link('bin3/file3b' => '../../stow/pkg3b/bin3/file3b'); # emulate stow -unstow_contents('../stow/pkg3b', './'); +unstow_contents('../stow/pkg3b', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -104,7 +104,7 @@ make_dir('../stow/pkg4/bin4'); make_file('../stow/pkg4/bin4/file4'); make_link('bin4/file4', '../../stow/pkg4/bin4/does-not-exist'); -unstow_contents('../stow/pkg4', './'); +unstow_contents('../stow/pkg4', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -121,7 +121,7 @@ $Option{'verbose'} = 0; make_dir('../stow/pkg5/bin5'); make_link('bin5', '../not-stow'); -unstow_contents('../stow/pkg5', './'); +unstow_contents('../stow/pkg5', '.'); like( $Conflicts[-1], qr(CONFLICT:.*existing target is not owned by stow) => q(existing link not owned by stow) @@ -140,7 +140,7 @@ make_link('bin6/file6', '../../stow/pkg6a/bin6/file6'); make_dir('../stow/pkg6b/bin6'); make_file('../stow/pkg6b/bin6/file6'); -unstow_contents('../stow/pkg6b', './'); +unstow_contents('../stow/pkg6b', '.'); ok( scalar(@Conflicts) == 0 && -l 'bin6/file6' && @@ -162,7 +162,7 @@ make_dir('stow/pkg7a/stow/pkg7b'); make_file('stow/pkg7a/stow/pkg7b/file7b'); make_link('stow/pkg7b', '../stow/pkg7a/stow/pkg7b'); -unstow_contents('stow/pkg7b', './'); +unstow_contents('stow/pkg7b', '.'); stderr_like( sub { process_tasks(); }, qr/There are no outstanding operations to perform/, @@ -192,7 +192,7 @@ make_dir('stow/pkg8a/stow2/pkg8b'); make_file('stow/pkg8a/stow2/pkg8b/file8b'); make_link('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b'); -unstow_contents('stow/pkg8a', './'); +unstow_contents('stow/pkg8a', '.'); stderr_like( sub { process_tasks(); }, qr/There are no outstanding operations to perform/, @@ -220,7 +220,7 @@ make_link('man9/man1/file9.1' => '../../../stow/pkg9a/man9/man1/file9.1'); # emu make_dir('../stow/pkg9b/man9/man1'); make_file('../stow/pkg9b/man9/man1/file9.1'); -unstow_contents('../stow/pkg9b', './'); +unstow_contents('../stow/pkg9b', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -248,7 +248,7 @@ make_link('man10/man1/file10b.1' => '../../../stow/pkg10b/man10/man1/file10b.1' make_dir('../stow/pkg10c/man10/man1'); make_file('../stow/pkg10c/man10/man1/file10a.1'); -unstow_contents('../stow/pkg10c', './'); +unstow_contents('../stow/pkg10c', '.'); stderr_like( sub { process_tasks(); }, qr/There are no outstanding operations to perform/, @@ -274,7 +274,7 @@ make_file('../stow/pkg12/man12/man1/.#file12.1'); make_dir('man12/man1'); make_link('man12/man1/file12.1' => '../../../stow/pkg12/man12/man1/file12.1'); -unstow_contents('../stow/pkg12', './'); +unstow_contents('../stow/pkg12', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 && diff --git a/t/unstow_contents_orig.t b/t/unstow_contents_orig.t index 90575f6..ebed239 100755 --- a/t/unstow_contents_orig.t +++ b/t/unstow_contents_orig.t @@ -43,7 +43,7 @@ make_dir('../stow/pkg1/bin1'); make_file('../stow/pkg1/bin1/file1'); make_link('bin1','../stow/pkg1/bin1'); -unstow_contents_orig('../stow/pkg1','./'); +unstow_contents_orig('../stow/pkg1','.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -61,7 +61,7 @@ make_dir('lib2'); make_dir('../stow/pkg2/lib2'); make_file('../stow/pkg2/lib2/file2'); make_link('lib2/file2', '../../stow/pkg2/lib2/file2'); -unstow_contents_orig('../stow/pkg2','./'); +unstow_contents_orig('../stow/pkg2','.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -84,7 +84,7 @@ make_link('bin3/file3a' => '../../stow/pkg3a/bin3/file3a'); # emulate stow make_dir('../stow/pkg3b/bin3'); make_file('../stow/pkg3b/bin3/file3b'); make_link('bin3/file3b' => '../../stow/pkg3b/bin3/file3b'); # emulate stow -unstow_contents_orig('../stow/pkg3b', './'); +unstow_contents_orig('../stow/pkg3b', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -104,7 +104,7 @@ make_dir('../stow/pkg4/bin4'); make_file('../stow/pkg4/bin4/file4'); make_link('bin4/file4', '../../stow/pkg4/bin4/does-not-exist'); -unstow_contents_orig('../stow/pkg4', './'); +unstow_contents_orig('../stow/pkg4', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -121,7 +121,7 @@ $Option{'verbose'} = 0; make_dir('../stow/pkg5/bin5'); make_link('bin5', '../not-stow'); -unstow_contents_orig('../stow/pkg5', './'); +unstow_contents_orig('../stow/pkg5', '.'); #like( # $Conflicts[-1], qr(CONFLICT:.*can't unlink.*not owned by stow) # => q(existing link not owned by stow) @@ -144,7 +144,7 @@ make_link('bin6/file6', '../../stow/pkg6a/bin6/file6'); make_dir('../stow/pkg6b/bin6'); make_file('../stow/pkg6b/bin6/file6'); -unstow_contents_orig('../stow/pkg6b', './'); +unstow_contents_orig('../stow/pkg6b', '.'); ok( -l 'bin6/file6' && readlink('bin6/file6') eq '../../stow/pkg6a/bin6/file6' => q(existing link owned by stow but points to a different package) @@ -164,7 +164,7 @@ make_dir('stow/pkg7a/stow/pkg7b'); make_file('stow/pkg7a/stow/pkg7b/file7b'); make_link('stow/pkg7b', '../stow/pkg7a/stow/pkg7b'); -unstow_contents_orig('stow/pkg7b', './'); +unstow_contents_orig('stow/pkg7b', '.'); stderr_like( sub { process_tasks(); }, qr/There are no outstanding operations to perform/, @@ -194,7 +194,7 @@ make_dir('stow/pkg8a/stow2/pkg8b'); make_file('stow/pkg8a/stow2/pkg8b/file8b'); make_link('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b'); -unstow_contents_orig('stow/pkg8a', './'); +unstow_contents_orig('stow/pkg8a', '.'); stderr_like( sub { process_tasks(); }, qr/There are no outstanding operations to perform/, @@ -222,7 +222,7 @@ make_link('man9/man1/file9.1' => '../../../stow/pkg9a/man9/man1/file9.1'); # emu make_dir('../stow/pkg9b/man9/man1'); make_file('../stow/pkg9b/man9/man1/file9.1'); -unstow_contents_orig('../stow/pkg9b', './'); +unstow_contents_orig('../stow/pkg9b', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 && @@ -250,7 +250,7 @@ make_link('man10/man1/file10b.1' => '../../../stow/pkg10b/man10/man1/file10b.1' make_dir('../stow/pkg10c/man10/man1'); make_file('../stow/pkg10c/man10/man1/file10a.1'); -unstow_contents_orig('../stow/pkg10c', './'); +unstow_contents_orig('../stow/pkg10c', '.'); stderr_like( sub { process_tasks(); }, qr/There are no outstanding operations to perform/, @@ -276,7 +276,7 @@ make_file('../stow/pkg12/man12/man1/.#file12.1'); make_dir('man12/man1'); make_link('man12/man1/file12.1' => '../../../stow/pkg12/man12/man1/file12.1'); -unstow_contents_orig('../stow/pkg12', './'); +unstow_contents_orig('../stow/pkg12', '.'); process_tasks(); ok( scalar(@Conflicts) == 0 &&