summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spiers <stow@adamspiers.org>2011-10-24 16:01:33 +0000
committerAdam Spiers <stow@adamspiers.org>2011-11-09 23:24:59 +0000
commit65d160e1142aead9c31500785f5223cf5d6e1259 (patch)
treea0257516c2cf329a46c258d0e36e8b168db14dd0
parentce7f0ee2d8dda9b82a001cf99a5b8de1b9d30378 (diff)
downloadstow-65d160e1142aead9c31500785f5223cf5d6e1259.tar.gz
give more helpful conflict messages
-rwxr-xr-xStow.pm50
1 files changed, 26 insertions, 24 deletions
diff --git a/Stow.pm b/Stow.pm
index f2534d0..629c7d6 100755
--- a/Stow.pm
+++ b/Stow.pm
@@ -382,11 +382,11 @@ sub StowDir {
warn "Stowing directory $dir\n" if ($opts{verbose} > 1);
- my $subdirPath = &JoinPaths($opts{target}, $subdir);
- if (-l $subdirPath) {
+ my $targetSubdirPath = &JoinPaths($opts{target}, $subdir);
+ if (-l $targetSubdirPath) {
# We found a link; now let's see if we should remove it.
- my $linktarget = readlink($subdirPath);
- $linktarget or die "$RealScript: Could not read link $subdirPath ($!)\n";
+ my $linktarget = readlink($targetSubdirPath);
+ $linktarget or die "$RealScript: Could not read link $targetSubdirPath ($!)\n";
# Does the link point to somewhere within the stow directory?
my $stowsubdir = &FindStowMember(
@@ -395,43 +395,43 @@ sub StowDir {
);
unless ($stowsubdir) {
# No, so we can't touch it.
- &Conflict($dir, $subdir, 1);
+ &Conflict($dir, $subdir, "link doesn't point within stow dir; cannot split open");
return;
}
# Yes it does.
- if (-e &JoinPaths($opts{stow}, $stowsubdir)) {
+ my $stowSubdirPath = &JoinPaths($opts{stow}, $stowsubdir);
+ if (-e $stowSubdirPath) {
if ($stowsubdir eq $dir) {
- warn sprintf("%s already points to %s\n",
- $subdirPath,
- &JoinPaths($opts{stow}, $dir))
- if ($opts{verbose} > 2);
+ warn "$targetSubdirPath already points to $stowSubdirPath\n"
+ if $opts{verbose} > 2;
return;
}
- if (-d &JoinPaths($opts{stow}, $stowsubdir)) {
+ if (-d $stowSubdirPath) {
# This is the splitting open of a folded tree which the stow
# manual refers to.
- &DoUnlink($subdirPath);
- &DoMkdir($subdirPath);
+ &DoUnlink($targetSubdirPath);
+ &DoMkdir($targetSubdirPath);
&StowContents($stowsubdir, &JoinPaths('..', $stow));
&StowContents($dir, &JoinPaths('..', $stow));
} else {
- (&Conflict($dir, $subdir, 2), return);
+ &Conflict($dir, $subdir, "$stowSubdirPath exists but not a directory");
+ return;
}
} else {
- &DoUnlink($subdirPath);
+ &DoUnlink($targetSubdirPath);
&DoLink(&JoinPaths($stow, $dir),
- $subdirPath);
+ $targetSubdirPath);
}
- } elsif (-e $subdirPath) {
- if (-d $subdirPath) {
+ } elsif (-e $targetSubdirPath) {
+ if (-d $targetSubdirPath) {
&StowContents($dir, &JoinPaths('..', $stow));
} else {
- &Conflict($dir, $subdir, 3);
+ &Conflict($dir, $subdir, "$targetSubdirPath exists but not a directory");
}
} else {
&DoLink(&JoinPaths($stow, $dir),
- $subdirPath);
+ $targetSubdirPath);
}
}
@@ -450,12 +450,14 @@ sub StowNondir {
$linktarget
);
if (! $stowsubfile) {
- &Conflict($file, $subfile, 4);
+ &Conflict($file, $subfile, "$subfilePath symlink did not point within stow dir");
return;
}
if (-e &JoinPaths($opts{stow}, $stowsubfile)) {
- (&Conflict($file, $subfile, 5), return)
- unless ($stowsubfile eq $file);
+ if ($stowsubfile ne $file) {
+ &Conflict($file, $subfile, "$subfilePath pointed to something else within stow dir");
+ return;
+ }
warn sprintf("%s already points to %s\n",
$subfilePath,
&JoinPaths($opts{stow}, $file))
@@ -465,7 +467,7 @@ sub StowNondir {
&DoLink(&JoinPaths($stow, $file), $subfilePath);
}
} elsif (-e $subfilePath) {
- &Conflict($file, $subfile, 6);
+ &Conflict($file, $subfile, "$subfilePath exists but is not a symlink");
} else {
&DoLink(&JoinPaths($stow, $file), $subfilePath);
}