File Coverage

blib/lib/P4/C4/Path.pm
Criterion Covered Total %
statement 40 43 93.0
branch 9 12 75.0
condition n/a
subroutine 6 7 85.7
pod 3 3 100.0
total 58 65 89.2


line stmt bran cond sub pod time code
1             # $Revision: 709 $$Date: 2005-05-03 17:32:07 -0400 (Tue, 03 May 2005) $$Author: wsnyder $
2             # Author: Wilson Snyder
3             ######################################################################
4             #
5             # Copyright 2002-2005 by Wilson Snyder. This program is free software;
6             # you can redistribute it and/or modify it under the terms of either the GNU
7             # General Public License or the Perl Artistic License.
8             #
9             # This program is distributed in the hope that it will be useful,
10             # but WITHOUT ANY WARRANTY; without even the implied warranty of
11             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12             # GNU General Public License for more details.
13             #
14             ######################################################################
15              
16             package P4::C4::Path;
17 1     1   23970 use File::Spec;
  1         3  
  1         26  
18 1     1   5 use File::Spec::Functions;
  1         1  
  1         90  
19 1     1   4 use Cwd qw(getcwd);
  1         2  
  1         36  
20 1     1   4 use strict;
  1         2  
  1         501  
21              
22             require Exporter;
23             our @ISA = ('Exporter');
24             our @EXPORT = qw( fileNoLinks );
25             our $VERSION = '2.041';
26              
27             ######################################################################
28              
29             sub isDepotFilename {
30 0     0 1 0 my $filename = shift;
31 0         0 return ($filename =~ m%^//%);
32             }
33              
34             sub fileDePerforce {
35 1     1 1 3 my $filename = shift;
36             # Strip perforce specifics
37 1         3 $filename =~ s/\.\.\.$//;
38 1         3 $filename =~ s![/\\]$!!;
39             # On Windows, Repositories always use / but filenames want backslashes
40             # We'll take either, then make them native
41 1         20 my @dirs = split /[\\\/]/, $filename;
42 1         7 return fileNoLinks(catfile(@dirs));
43             }
44              
45             sub fileNoLinks {
46 4     4 1 139 my $filename = shift;
47             # Remove any symlinks in the filename
48             # Perforce doesn't allow "cd ~/sim/project" where project is a symlink!
49             # Modified example from the web
50            
51             #print "FNLinp: $filename\n";
52 4         88 $filename = File::Spec->rel2abs($filename);
53 4         30 my @right = File::Spec->splitdir($filename);
54 4         5 my @left;
55              
56 4         10 while (@right) {
57             #print "PARSE: ",catfile(@left)," --- ",catfile(@right),"\n";
58 37         59 my $item = shift @right;
59 37 50       65 next if $item eq ".";
60 37 100       88 if ($item eq "") {
    100          
61 5         9 push @left, $item;
62 5         10 next;
63             }
64             elsif ($item eq "..") {
65 3 50       8 pop @left if @left > 1;
66 3         6 next;
67             }
68            
69 29         414 my $link = readlink (catfile(@left, $item));
70            
71 29 100       64 if (defined $link) {
72 1 50       6 if (file_name_is_absolute($link)) {
73 0         0 @left = File::Spec->splitdir($link);
74             } else {
75 1         14 unshift @right, File::Spec->splitdir($link);
76             }
77             # Start search over, as we might have more links to resolve
78 1         3 unshift @right, @left;
79 1         4 @left = ();
80 1         3 next;
81             } else {
82 28         42 push @left, $item;
83 28         64 next;
84             }
85             }
86 4         17 my $out = catfile(@left);
87             #print "FNLabs: $out\n";
88 4         48 return $out;
89             }
90              
91             ######################################################################
92             ### Package return
93             1;
94             __END__