File: path2spool

package info (click to toggle)
fsvs 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,964 kB
  • ctags: 1,464
  • sloc: ansic: 16,650; sh: 5,885; perl: 783; makefile: 338; python: 90
file content (57 lines) | stat: -rwxr-xr-x 1,160 bytes parent folder | download | duplicates (3)
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
57
#!/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,/+$,,;

# The WC base; defaults to the current directory.
$wc_base=shift() || $ENV{"PWD"} || die $!;

unless (m#^/#)
{
	$p=$ENV{"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##;

die if $softroot && $wc_base !~ s#^$softroot##;
$wc_base =~ s# /+ $ # #gx;

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