From e78a149ecb28182cf11f4954e945b1411b6f9207 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Tue, 31 Jul 2001 09:18:48 +0000 Subject: [PATCH] a bit safer now you can't move 2 files to the same target anymore --- mvwrap/mvwrap | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mvwrap/mvwrap b/mvwrap/mvwrap index aa76386..3de8061 100755 --- a/mvwrap/mvwrap +++ b/mvwrap/mvwrap @@ -46,7 +46,11 @@ close ($target); if ($DEBUG) { print @target; } unless ( scalar(@source) == scalar(@target) ) { - die "source and target don't have the same number of lines"; + die "Aborting. Source and target list don't have the same number of lines.\n"; +} + +if (&check_unique(@target)) { + die "Aborting. You're trying to move multiple files to the same name.\n"; } $i=0; @@ -62,3 +66,15 @@ while ( $i < scalar(@source) ) { } $i++; } + +# returns 0 if all entries in @target_list are unique. 1 if not. +sub check_unique (@target_list){ + my(@target_list, %seen, @uniqu); + @target_list = @_; + %seen = (); + @uniqu = grep { ! $seen{$_} ++ } @target_list; + unless (scalar(@uniqu) == scalar(@target) ) { + return 1; + } + return 0; +}