Subversion Repositories DevTools

Rev

Rev 255 | Rev 261 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 255 Rev 257
Line 14... Line 14...
14
#                    Realpath                   - Get real path
14
#                    Realpath                   - Get real path
15
#                    Realfile                   - Get real path ?
15
#                    Realfile                   - Get real path ?
16
#                    RelPath                    - Convert to relative path
16
#                    RelPath                    - Convert to relative path
17
#                    AbsPath                    - Convert to Abs path
17
#                    AbsPath                    - Convert to Abs path
18
#                    FullPath                   - Convert to Abs path with driver letter
18
#                    FullPath                   - Convert to Abs path with driver letter
-
 
19
#                    TruePath                   - Case Corrected pathname
19
#                    CleanPath                  - Clean up a path
20
#                    CleanPath                  - Clean up a path
20
#                    StripDrive                 - Remove drive letter
21
#                    StripDrive                 - Remove drive letter
21
#                    StripDir                   - Return file + extension
22
#                    StripDir                   - Return file + extension
22
#                    StripExt                   - Return dir + file
23
#                    StripExt                   - Return dir + file
23
#                    StripFile                  - Returns extension
24
#                    StripFile                  - Returns extension
Line 64... Line 65...
64
                StripDirExt
65
                StripDirExt
65
                CleanDirName
66
                CleanDirName
66
                TouchFile
67
                TouchFile
67
                FileIsNewer
68
                FileIsNewer
68
                DisplayPath
69
                DisplayPath
-
 
70
                TruePath
69
 
71
 
70
                $ScmPathSep
72
                $ScmPathSep
71
                $Cwd
73
                $Cwd
72
                $CwdDrive
74
                $CwdDrive
73
                $ScmHost
75
                $ScmHost
Line 418... Line 420...
418
    $path = $CwdDrive . $path unless ( $path =~ m~^\w:~  );
420
    $path = $CwdDrive . $path unless ( $path =~ m~^\w:~  );
419
    return $path;
421
    return $path;
420
}
422
}
421
 
423
 
422
#-------------------------------------------------------------------------------
424
#-------------------------------------------------------------------------------
-
 
425
# Function        : TruePath
-
 
426
#
-
 
427
# Description     : Returns a case correct pathname
-
 
428
#                   Really only applicable to windows, under unix it returns
-
 
429
#                   its input path.
-
 
430
#
-
 
431
#                   Maintains a cache to speed up processing
-
 
432
#
-
 
433
# Inputs          : Confused path (Absolute with a driver letter)
-
 
434
#
-
 
435
# Returns         : Case Correct Path : Windows
-
 
436
#                   Input Path : Non Windows
-
 
437
#
-
 
438
my %TruePathCache;
-
 
439
my %DirRead;
-
 
440
sub TruePath
-
 
441
{
-
 
442
    my ($path) = @_;
-
 
443
    $path =~ tr~\\/~/~s;
-
 
444
 
-
 
445
    #
-
 
446
    #   On Unix systems the path is case sensitive to start with
-
 
447
    #   Can't get it wrong - can't do anything.
-
 
448
    #
-
 
449
    return $path if ( $isUnix );
-
 
450
 
-
 
451
    #
-
 
452
    #   If the path does not exist at all then return the user input
-
 
453
    #   Assume that the user will handle this later
-
 
454
    #
-
 
455
    unless ( -e $path )
-
 
456
    {
-
 
457
        Warning ("TruePath given invalid path: $path");
-
 
458
        return $path;
-
 
459
    }
-
 
460
 
-
 
461
    #
-
 
462
    #   Look in the cache - have we seen this before
-
 
463
    #
-
 
464
    if ( exists $TruePathCache{lc($path)} )
-
 
465
    {
-
 
466
        Verbose( "TruePath Cache Hit: $path");
-
 
467
        return $TruePathCache{lc($path)};
-
 
468
    }
-
 
469
 
-
 
470
    #
-
 
471
    #   Split the directory into components
-
 
472
    #
-
 
473
    my $TrueComponent = '';
-
 
474
    my @components = split ('/', $path );
-
 
475
    foreach my $elem ( @components )
-
 
476
    {
-
 
477
        Debug ("Process: $elem in $TrueComponent");
-
 
478
        my $tag;
-
 
479
        #
-
 
480
        #   Handle driver letter
-
 
481
        #
-
 
482
        if ( $elem =~ m~^[a-zA-Z]:$~ )
-
 
483
        {
-
 
484
            $elem = uc($elem);
-
 
485
            $TrueComponent = $elem;
-
 
486
 
-
 
487
            $tag = lc($TrueComponent);
-
 
488
            $TruePathCache{$tag} = $elem;
-
 
489
            Debug ("     Add: $elem");
-
 
490
            next;
-
 
491
        }
-
 
492
 
-
 
493
        #
-
 
494
        #   Ensure that we have read in containing directory
-
 
495
        #   Note: Append / to ensure we read root directories correctly
-
 
496
        #
-
 
497
        $TrueComponent .= '/';
-
 
498
        unless ( $DirRead{ $TrueComponent }  )
-
 
499
        {
-
 
500
            Debug ("Reading: $TrueComponent");
-
 
501
            opendir (TP, $TrueComponent ) or Error ("Cannot open $TrueComponent");
-
 
502
            my @dirlist = readdir TP;
-
 
503
            close TP;
-
 
504
            $DirRead {$TrueComponent } = 1;
-
 
505
 
-
 
506
            #
-
 
507
            #   Add cache entries for each path in the directory
-
 
508
            #
-
 
509
            foreach my $dir ( @dirlist )
-
 
510
            {
-
 
511
                next if ( $dir eq '.' );
-
 
512
                next if ( $dir eq '..' );
-
 
513
                my $fullpath = $TrueComponent . $dir;
-
 
514
                Debug ("     Add: $fullpath");
-
 
515
                $TruePathCache{lc($fullpath)} = $fullpath;
-
 
516
            }
-
 
517
        }
-
 
518
 
-
 
519
        #
-
 
520
        #   Now that we have populated the cache with data from the directory
-
 
521
        #   we can expect to find our desired entry in the cache.
-
 
522
        #
-
 
523
        $tag = lc($TrueComponent . $elem );
-
 
524
        if ( exists $TruePathCache{ $tag } )
-
 
525
        {
-
 
526
            $TrueComponent = $TruePathCache{ $tag };
-
 
527
        }
-
 
528
        else
-
 
529
        {
-
 
530
            DebugDumpData ("Cache", \%TruePathCache);
-
 
531
            Error ("TruePath Internal error. File may have been deleted: $tag");
-
 
532
        }
-
 
533
        Debug ("Have: $TrueComponent");
-
 
534
    }
-
 
535
 
-
 
536
    Verbose ("TruePath: $TrueComponent");
-
 
537
    return $TrueComponent;
-
 
538
}
-
 
539
 
-
 
540
#-------------------------------------------------------------------------------
423
# Function        : CleanPath
541
# Function        : CleanPath
424
#
542
#
425
# Description     : Cleanup a path
543
# Description     : Cleanup a path
426
#                   Remove xxx/.. constructs
544
#                   Remove xxx/.. constructs
427
#
545
#