]> git.p6c8.net - devedit.git/blobdiff - modules/Tool.pm
Small cleanup
[devedit.git] / modules / Tool.pm
index e3056c590ee39fa929eafaa62751e7ea522504e4..9ba39c2690a1138f6c965045a0b045c5f85e3493 100644 (file)
@@ -6,7 +6,7 @@ package Tool;
 # Some shared sub routines
 #
 # Author:        Patrick Canterino <patrick@patshaping.de>
-# Last modified: 2005-01-06
+# Last modified: 2005-01-07
 #
 
 use strict;
@@ -61,18 +61,39 @@ sub check_path($$)
  # We extract the last part of the path and create the absolute path
 
  my $first = upper_path($path);
+ $first    = abs_path($first);
+
  my $last  = file_name($path);
+ $last     = '' if($last eq '.');
+
+ if($last eq '..')
+ {
+  $first = upper_path($first);
+  $last  = '';
+ }
+ elsif($^O eq 'MSWin32' && $last =~ m!^\.\.\.+$!)
+ {
+  # Windows allows to go upwards in a path using things like
+  # "..." and "...." and so on
+
+  my $count = length($last)-1;
 
- $first = abs_path($first);
- $path  = $first.'/'.$last;
+  for(my $x=0;$x<$count;$x++)
+  {
+   unless($first =~ m!^[a-z]{1}:(/|\\)$!i)
+   {
+    $first = upper_path($first);
+   }
+  }
+
+  $last = '';
+ }
 
- $first = File::Spec->canonpath($first);
- $path  = File::Spec->canonpath($path);
+ $path = File::Spec->canonpath($first.'/'.$last);
 
  # Check if the path is above the root directory
 
  return if(index($path,$root) != 0);
- return if($first eq $root && $last =~ m!^(/|\\)?\.\.(/|\\)?$!);
 
  # Create short path name
 

patrick-canterino.de