File: imagemv.pl

package info (click to toggle)
eclipse 3.5.2-6squeeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 297,208 kB
  • ctags: 426,326
  • sloc: java: 2,527,099; ansic: 122,607; xml: 100,868; cpp: 33,545; jsp: 3,869; sh: 2,557; perl: 1,650; makefile: 272; csh: 151; python: 69; php: 24
file content (56 lines) | stat: -rwxr-xr-x 1,567 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl

use strict;
use warnings;

my $dryrun = defined($ARGV[0]) && $ARGV[0] eq '--dry-run';

while( my $image = <STDIN> ){
    my $des;
    my $desdir;
    my $relpath;
    my $linktarget;
    chomp($image);
    if( -l $image ){
	# already a link - not touching
	next;
    }
    if( ! -e $image ){
	choke("Cannot \"mv + ln\" $image: it does not exists.");
    }
    # Remove the leading ./ (from find output).
    $image =~ s@^./@@o;
    $des = $image;
    $des =~ s@lib/@share/@o;
    if($des =~ m@eclipse/features/@o){
	# They have some names that changes based on arch/build/something.
	# So we will just remove that so the link is always correct.
	# e.g. 
	#   org.eclipse.help_1.1.1.R35x_v20090811-7e7eFAnFEx2XZoYwvOe8duD
	# becomes
	#   org.eclipse.help_1.1.1.R35x_v20090811
	$des =~ s@(_v\d{8})-[^/]++@$1@o;
    }
    $desdir = $des;
    # Remove the last part (the name of the file)
    $desdir =~ s@[^/]++$@@o;
    $relpath = $desdir;
    # Replace path parts with ".."
    $relpath =~ s@[^/]++@..@go;
    # concat with the original target and we have
    # the relative link - There is no / in between
    # because $relpath already contains it.
    $linktarget = "$relpath$des";
    if($dryrun){
	print "mkdir -p \"$desdir\" && mv -f \"$image\" \"$des\" && ln -s \"$linktarget\" \"$image\"\n";
    } else {
	system("mkdir -p \"$desdir\" && mv -f \"$image\" \"$des\" && ln -s \"$linktarget\" \"$image\"") == 0
	    or choke("Could not complete link of $image.");
    }
}

sub choke{
    my $msg = shift;
    print STDERR "$msg\n";
    exit(1);
}