File: path2spool

package info (click to toggle)
fsvs 1.1.16-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,344 kB
  • ctags: 1,133
  • sloc: ansic: 14,472; sh: 6,793; perl: 631; makefile: 337
file content (47 lines) | stat: -rwxr-xr-x 885 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use Digest::MD5 qw(md5_hex);

$_=shift;
# Filename. If empty, just the path to the WAA is returned; if '^', the 
# path to the conf area is returned.
$file=shift; 
# The softroot - see the option "softroot".
( $softroot=shift ) =~ s,/+$,,;

unless (m#^/#)
{
	chomp($p=`pwd`);
	$_ = $p . "/" . $_;
}

$conf = ($file =~ /^[A-Z]/);
$conf=1, $file="" if ($file eq '^');

1 while 
# remove /./ and /.
	s#/\./#/#g ||
	s#/\.$#/#g ||
# remove / at end; at least a single character (/) must be kept
	s#(.)/+$#\1#g ||
# change // to /
	s#//+#/#g;
# remove the softroot
die if $softroot && !s#^$softroot##;


$m=md5_hex($_);
if ($conf)
{
	print +($ENV{"FSVS_CONF"} || "/etc/fsvs"),
				"/" . $m . "/" . $file . "\n";
}
else
{
	print +($ENV{"FSVS_WAA"} || "/var/spool/fsvs"),
				"/" . substr($m,0,2), 
				"/" . substr($m,2,2),
				"/" . substr($m,4),
				"/" . $file . "\n";
}