source: gs2-extensions/parallel-building/trunk/src/bin/script/linkinator.pl@ 29106

Last change on this file since 29106 was 29106, checked in by jmt12, 10 years ago

Check-in of script to symlink lorem files to matching files in another directory...

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6if (!defined $ARGV[0] || !-d $ARGV[0])
7{
8 &printUsage('Missing source directory');
9}
10my $source_dir = $ARGV[0];
11if (!defined $ARGV[1] || !-d $ARGV[1])
12{
13 &printUsage('Missing target directory');
14}
15my $target_dir = $ARGV[1];
16
17print "====== Linkinator ======\n";
18print "Replaces files in <target dir> with links if they are also found in\n";
19print "<source dir>.\n\n";
20&recursivelyScan($source_dir, $target_dir);
21print "====== Complete! ======\n\n";
22exit;
23
24sub printUsage
25{
26 my ($msg) = @_;
27 if (defined $msg)
28 {
29 print "Error! $msg\n";
30 }
31 print "Usage: linkinator.pl <source dir> <target dir>\n\n";
32 exit;
33}
34
35sub recursivelyScan
36{
37 my ($sdir, $tdir) = @_;
38
39 print " * Comparing: " . $tdir . " => " . $sdir . "\n";
40
41 opendir(DH, $tdir);
42 my @files = readdir(DH);
43 closedir(DH);
44
45 foreach my $file (@files)
46 {
47 if ($file !~ /^\./)
48 {
49 my $spath = $sdir . '/' . $file;
50 my $tpath = $tdir . '/' . $file;
51 if (-d $tpath && -d $spath)
52 {
53 &recursivelyScan($spath, $tpath);
54 }
55 elsif (-f $tpath && -f $spath)
56 {
57 print " - symlinking: " . $file . "\n";
58 unlink($tpath);
59 link($spath, $tpath);
60 }
61 elsif (-f $tpath)
62 {
63 print " - only in target: " . $file . "\n";
64 }
65 }
66 }
67}
Note: See TracBrowser for help on using the repository browser.