xref: /aoo42x/main/solenv/bin/diffmv.pl (revision 7e90fac2)
1:
2    eval 'exec perl -S $0 ${1+"$@"}'
3        if 0;
4#**************************************************************
5#
6#  Licensed to the Apache Software Foundation (ASF) under one
7#  or more contributor license agreements.  See the NOTICE file
8#  distributed with this work for additional information
9#  regarding copyright ownership.  The ASF licenses this file
10#  to you under the Apache License, Version 2.0 (the
11#  "License"); you may not use this file except in compliance
12#  with the License.  You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16#  Unless required by applicable law or agreed to in writing,
17#  software distributed under the License is distributed on an
18#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19#  KIND, either express or implied.  See the License for the
20#  specific language governing permissions and limitations
21#  under the License.
22#
23#**************************************************************
24
25
26
27
28my ( $srcfile, $destfile ) = @ARGV;
29my ( @srclines, @destlines );
30my $dest_existing = 0;
31@destlines = ();
32
33usage() if ( ! defined $srcfile || ! defined $destfile);
34
35open(SRCFILE, "$srcfile") or die "ERROR: Can't open $srcfile\n";
36@srclines = <SRCFILE>;
37close SRCFILE;
38
39if ( -f $destfile ) {
40    open(DESTFILE, "$destfile") or die "ERROR: Can't open $destfile\n";
41    @destlines = <DESTFILE>;
42    close DESTFILE;
43    $dest_existing = 1;
44}
45
46if ( ! check_if_lists_equal(\@srclines,  \@destlines) ) {
47    print STDERR "Updating \"$destfile\".\n";
48    unlink "$destfile" or die "ERROR: Can't remove old $destfile\n" if ( $dest_existing );
49    rename "$srcfile", "$destfile" or die "ERROR: Can't rename $srcfile to $destfile\n";
50} else {
51    print STDERR "\"$destfile\" unchanged.\n";
52}
53
54sub check_if_lists_equal
55{
56    my  ( $srclist_ref, $destlist_ref ) = @_;
57    my @srclist  = @{ $srclist_ref };
58    my @destlist  = @{ $destlist_ref };
59    return  0 if ( $#srclist != $#destlist );
60    for ( my $i = 0; $i  < $#srclist; $i++ ) {
61        return 0 if  ( $srclist[$i] ne $destlist[$i]);
62    }
63    return  1;
64}
65
66sub usage
67{
68    print STDERR "Usage: diffmv sourcefile destfile\n";
69    print STDERR "Do move diffing file only\n";
70    exit 1;
71}
72
73