2011-11-16 09:04:03 -05:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
|
|
|
|
#
|
2012-01-09 16:32:31 -05:00
|
|
|
# Test unstowing packages
|
2011-11-16 09:04:03 -05:00
|
|
|
#
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-21 18:23:43 -05:00
|
|
|
use Test::More tests => 23;
|
2011-11-16 10:16:53 -05:00
|
|
|
use Test::Output;
|
2011-11-16 09:04:03 -05:00
|
|
|
use English qw(-no_match_vars);
|
|
|
|
|
2011-11-21 18:23:43 -05:00
|
|
|
use testutil;
|
|
|
|
use Stow::Util qw(canon_path);
|
|
|
|
|
2011-11-23 18:45:48 -05:00
|
|
|
init_test_dirs();
|
2011-11-24 11:32:01 -05:00
|
|
|
cd("$OUT_DIR/target");
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
# Note that each of the following tests use a distinct set of files
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
my $stow;
|
2011-11-24 17:49:22 -05:00
|
|
|
my %conflicts;
|
2011-11-24 11:28:09 -05:00
|
|
|
|
2011-11-16 09:04:03 -05:00
|
|
|
#
|
|
|
|
# unstow a simple tree minimally
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('../stow/pkg1/bin1');
|
|
|
|
make_file('../stow/pkg1/bin1/file1');
|
2011-11-24 11:28:09 -05:00
|
|
|
make_link('bin1', '../stow/pkg1/bin1');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg1');
|
|
|
|
$stow->process_tasks();
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
-f '../stow/pkg1/bin1/file1' && ! -e 'bin1'
|
|
|
|
=> 'unstow a simple tree'
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# unstow a simple tree from an existing directory
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('lib2');
|
|
|
|
make_dir('../stow/pkg2/lib2');
|
|
|
|
make_file('../stow/pkg2/lib2/file2');
|
|
|
|
make_link('lib2/file2', '../../stow/pkg2/lib2/file2');
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg2');
|
|
|
|
$stow->process_tasks();
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
-f '../stow/pkg2/lib2/file2' && -d 'lib2'
|
|
|
|
=> 'unstow simple tree from a pre-existing directory'
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# fold tree after unstowing
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('bin3');
|
|
|
|
|
|
|
|
make_dir('../stow/pkg3a/bin3');
|
|
|
|
make_file('../stow/pkg3a/bin3/file3a');
|
|
|
|
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
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg3b');
|
|
|
|
$stow->process_tasks();
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
-l 'bin3' &&
|
|
|
|
readlink('bin3') eq '../stow/pkg3a/bin3'
|
|
|
|
=> 'fold tree after unstowing'
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# existing link is owned by stow but is invalid so it gets removed anyway
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('bin4');
|
|
|
|
make_dir('../stow/pkg4/bin4');
|
|
|
|
make_file('../stow/pkg4/bin4/file4');
|
2012-02-18 15:19:05 -05:00
|
|
|
make_invalid_link('bin4/file4', '../../stow/pkg4/bin4/does-not-exist');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg4');
|
|
|
|
$stow->process_tasks();
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
! -e 'bin4/file4'
|
|
|
|
=> q(remove invalid link owned by stow)
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# Existing link is not owned by stow
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('../stow/pkg5/bin5');
|
2012-02-18 15:19:05 -05:00
|
|
|
make_invalid_link('bin5', '../not-stow');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg5');
|
2011-11-24 17:49:22 -05:00
|
|
|
%conflicts = $stow->get_conflicts;
|
2011-11-16 09:04:03 -05:00
|
|
|
like(
|
2011-11-24 17:49:22 -05:00
|
|
|
$conflicts{unstow}{pkg5}[-1],
|
|
|
|
qr(existing target is not owned by stow)
|
2011-11-16 09:04:03 -05:00
|
|
|
=> q(existing link not owned by stow)
|
|
|
|
);
|
2011-11-24 11:28:09 -05:00
|
|
|
|
2011-11-16 09:04:03 -05:00
|
|
|
#
|
|
|
|
# Target already exists, is owned by stow, but points to a different package
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('bin6');
|
|
|
|
make_dir('../stow/pkg6a/bin6');
|
|
|
|
make_file('../stow/pkg6a/bin6/file6');
|
|
|
|
make_link('bin6/file6', '../../stow/pkg6a/bin6/file6');
|
|
|
|
|
|
|
|
make_dir('../stow/pkg6b/bin6');
|
|
|
|
make_file('../stow/pkg6b/bin6/file6');
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg6b');
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-24 11:28:09 -05:00
|
|
|
-l 'bin6/file6' &&
|
2011-11-16 09:04:03 -05:00
|
|
|
readlink('bin6/file6') eq '../../stow/pkg6a/bin6/file6'
|
|
|
|
=> q(ignore existing link that points to a different package)
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# Don't unlink anything under the stow directory
|
|
|
|
#
|
|
|
|
make_dir('stow'); # make out stow dir a subdir of target
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow(dir => 'stow');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
2011-11-16 09:59:58 -05:00
|
|
|
# emulate stowing into ourself (bizarre corner case or accident)
|
2011-11-16 09:04:03 -05:00
|
|
|
make_dir('stow/pkg7a/stow/pkg7b');
|
|
|
|
make_file('stow/pkg7a/stow/pkg7b/file7b');
|
|
|
|
make_link('stow/pkg7b', '../stow/pkg7a/stow/pkg7b');
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg7b');
|
2012-01-11 09:01:40 -05:00
|
|
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg7b');
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
-l 'stow/pkg7b' &&
|
|
|
|
readlink('stow/pkg7b') eq '../stow/pkg7a/stow/pkg7b'
|
|
|
|
=> q(don't unlink any nodes under the stow directory)
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# Don't unlink any nodes under another stow directory
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow(dir => 'stow');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('stow2'); # make our alternate stow dir a subdir of target
|
|
|
|
make_file('stow2/.stow');
|
|
|
|
|
2011-11-16 09:59:58 -05:00
|
|
|
# emulate stowing into ourself (bizarre corner case or accident)
|
2011-11-16 09:04:03 -05:00
|
|
|
make_dir('stow/pkg8a/stow2/pkg8b');
|
|
|
|
make_file('stow/pkg8a/stow2/pkg8b/file8b');
|
|
|
|
make_link('stow2/pkg8b', '../stow/pkg8a/stow2/pkg8b');
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg8a');
|
2012-01-11 09:01:40 -05:00
|
|
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg8a');
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
-l 'stow2/pkg8b' &&
|
|
|
|
readlink('stow2/pkg8b') eq '../stow/pkg8a/stow2/pkg8b'
|
|
|
|
=> q(don't unlink any nodes under another stow directory)
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# overriding already stowed documentation
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow(override => ['man9', 'info9']);
|
2011-11-17 15:11:06 -05:00
|
|
|
make_file('stow/.stow');
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('../stow/pkg9a/man9/man1');
|
|
|
|
make_file('../stow/pkg9a/man9/man1/file9.1');
|
|
|
|
make_dir('man9/man1');
|
|
|
|
make_link('man9/man1/file9.1' => '../../../stow/pkg9a/man9/man1/file9.1'); # emulate stow
|
|
|
|
|
|
|
|
make_dir('../stow/pkg9b/man9/man1');
|
|
|
|
make_file('../stow/pkg9b/man9/man1/file9.1');
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg9b');
|
|
|
|
$stow->process_tasks();
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
!-l 'man9/man1/file9.1'
|
|
|
|
=> 'overriding existing documentation files'
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# deferring to already stowed documentation
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow(defer => ['man10', 'info10']);
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('../stow/pkg10a/man10/man1');
|
|
|
|
make_file('../stow/pkg10a/man10/man1/file10a.1');
|
|
|
|
make_dir('man10/man1');
|
|
|
|
make_link('man10/man1/file10a.1' => '../../../stow/pkg10a/man10/man1/file10a.1');
|
|
|
|
|
|
|
|
# need this to block folding
|
|
|
|
make_dir('../stow/pkg10b/man10/man1');
|
|
|
|
make_file('../stow/pkg10b/man10/man1/file10b.1');
|
|
|
|
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');
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg10c');
|
2012-01-11 09:01:40 -05:00
|
|
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg10c');
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
readlink('man10/man1/file10a.1') eq '../../../stow/pkg10a/man10/man1/file10a.1'
|
|
|
|
=> 'defer to existing documentation files'
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# Ignore temp files
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow(ignore => ['~', '\.#.*']);
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
make_dir('../stow/pkg12/man12/man1');
|
|
|
|
make_file('../stow/pkg12/man12/man1/file12.1');
|
|
|
|
make_file('../stow/pkg12/man12/man1/file12.1~');
|
|
|
|
make_file('../stow/pkg12/man12/man1/.#file12.1');
|
|
|
|
make_dir('man12/man1');
|
|
|
|
make_link('man12/man1/file12.1' => '../../../stow/pkg12/man12/man1/file12.1');
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow->plan_unstow('pkg12');
|
|
|
|
$stow->process_tasks();
|
2011-11-16 09:04:03 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-16 09:04:03 -05:00
|
|
|
!-e 'man12/man1/file12.1'
|
|
|
|
=> 'ignore temp files'
|
|
|
|
);
|
|
|
|
|
2011-11-17 14:33:09 -05:00
|
|
|
#
|
|
|
|
# Unstow an already unstowed package
|
|
|
|
#
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
|
|
|
$stow->plan_unstow('pkg12');
|
2012-01-11 09:01:40 -05:00
|
|
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12');
|
2011-11-17 15:11:06 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0
|
2011-11-17 15:11:06 -05:00
|
|
|
=> 'unstow already unstowed package pkg12'
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# Unstow a never stowed package
|
|
|
|
#
|
2011-11-17 14:33:09 -05:00
|
|
|
|
2011-11-24 11:32:01 -05:00
|
|
|
eval { remove_dir("$OUT_DIR/target"); };
|
|
|
|
mkdir("$OUT_DIR/target");
|
2011-11-17 15:11:06 -05:00
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
|
|
|
$stow->plan_unstow('pkg12');
|
2012-01-11 09:01:40 -05:00
|
|
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12 which was never stowed');
|
2011-11-17 15:11:06 -05:00
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0
|
2011-11-17 15:11:06 -05:00
|
|
|
=> 'unstow never stowed package pkg12'
|
|
|
|
);
|
2011-11-17 14:33:09 -05:00
|
|
|
|
2011-11-18 06:24:36 -05:00
|
|
|
#
|
|
|
|
# Unstowing when target contains a real file shouldn't be an issue.
|
|
|
|
#
|
|
|
|
make_file('man12/man1/file12.1');
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
$stow = new_Stow();
|
|
|
|
$stow->plan_unstow('pkg12');
|
2012-01-11 09:01:40 -05:00
|
|
|
is($stow->get_tasks, 0, 'no tasks to process when unstowing pkg12 for third time');
|
2011-11-24 17:49:22 -05:00
|
|
|
%conflicts = $stow->get_conflicts;
|
2011-11-18 06:24:36 -05:00
|
|
|
ok(
|
2011-11-24 17:49:22 -05:00
|
|
|
$stow->get_conflict_count == 1 &&
|
|
|
|
$conflicts{unstow}{pkg12}[0]
|
|
|
|
=~ m!existing target is neither a link nor a directory: man12/man1/file12\.1!
|
2011-11-18 06:24:36 -05:00
|
|
|
=> 'unstow pkg12 for third time'
|
|
|
|
);
|
|
|
|
|
2011-11-24 11:28:09 -05:00
|
|
|
#
|
|
|
|
# unstow a simple tree minimally when cwd isn't target
|
|
|
|
#
|
|
|
|
cd('../..');
|
2011-11-24 11:32:01 -05:00
|
|
|
$stow = new_Stow(dir => "$OUT_DIR/stow", target => "$OUT_DIR/target");
|
2011-11-24 11:28:09 -05:00
|
|
|
|
2011-11-24 11:32:01 -05:00
|
|
|
make_dir("$OUT_DIR/stow/pkg13/bin13");
|
|
|
|
make_file("$OUT_DIR/stow/pkg13/bin13/file13");
|
|
|
|
make_link("$OUT_DIR/target/bin13", '../stow/pkg13/bin13');
|
2011-11-24 11:28:09 -05:00
|
|
|
|
|
|
|
$stow->plan_unstow('pkg13');
|
|
|
|
$stow->process_tasks();
|
|
|
|
ok(
|
2011-11-24 17:49:22 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-24 11:32:01 -05:00
|
|
|
-f "$OUT_DIR/stow/pkg13/bin13/file13" && ! -e "$OUT_DIR/target/bin13"
|
2011-11-24 11:28:09 -05:00
|
|
|
=> 'unstow a simple tree'
|
|
|
|
);
|
|
|
|
|
2011-11-21 18:23:43 -05:00
|
|
|
#
|
|
|
|
# unstow a simple tree minimally with absolute stow dir when cwd isn't
|
|
|
|
# target
|
|
|
|
#
|
2011-11-24 11:32:01 -05:00
|
|
|
$stow = new_Stow(dir => canon_path("$OUT_DIR/stow"),
|
|
|
|
target => "$OUT_DIR/target");
|
2011-11-21 18:23:43 -05:00
|
|
|
|
2011-11-24 11:32:01 -05:00
|
|
|
make_dir("$OUT_DIR/stow/pkg14/bin14");
|
|
|
|
make_file("$OUT_DIR/stow/pkg14/bin14/file14");
|
|
|
|
make_link("$OUT_DIR/target/bin14", '../stow/pkg14/bin14');
|
2011-11-21 18:23:43 -05:00
|
|
|
|
|
|
|
$stow->plan_unstow('pkg14');
|
|
|
|
$stow->process_tasks();
|
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-24 11:32:01 -05:00
|
|
|
-f "$OUT_DIR/stow/pkg14/bin14/file14" && ! -e "$OUT_DIR/target/bin14"
|
2011-11-21 18:23:43 -05:00
|
|
|
=> 'unstow a simple tree with absolute stow dir'
|
|
|
|
);
|
|
|
|
|
|
|
|
#
|
|
|
|
# unstow a simple tree minimally with absolute stow AND target dirs
|
|
|
|
# when cwd isn't target
|
|
|
|
#
|
2011-11-24 11:32:01 -05:00
|
|
|
$stow = new_Stow(dir => canon_path("$OUT_DIR/stow"),
|
|
|
|
target => canon_path("$OUT_DIR/target"));
|
2011-11-21 18:23:43 -05:00
|
|
|
|
2011-11-24 11:32:01 -05:00
|
|
|
make_dir("$OUT_DIR/stow/pkg15/bin15");
|
|
|
|
make_file("$OUT_DIR/stow/pkg15/bin15/file15");
|
|
|
|
make_link("$OUT_DIR/target/bin15", '../stow/pkg15/bin15');
|
2011-11-21 18:23:43 -05:00
|
|
|
|
|
|
|
$stow->plan_unstow('pkg15');
|
|
|
|
$stow->process_tasks();
|
|
|
|
ok(
|
2012-01-09 13:32:06 -05:00
|
|
|
$stow->get_conflict_count == 0 &&
|
2011-11-24 11:32:01 -05:00
|
|
|
-f "$OUT_DIR/stow/pkg15/bin15/file15" && ! -e "$OUT_DIR/target/bin15"
|
2011-11-21 18:23:43 -05:00
|
|
|
=> 'unstow a simple tree with absolute stow and target dirs'
|
|
|
|
);
|
|
|
|
|
2011-11-16 09:04:03 -05:00
|
|
|
|
|
|
|
# Todo
|
|
|
|
#
|
|
|
|
# Test cleaning up subdirs with --paranoid option
|
|
|
|
|