Flickr

Social Stuff
Site Info

Sponsored Links

Laurie's Entries

« Perl: Iterating and Assigning Hash of Hashes and the Enigmatic Search | Main | Averatec AV4155-EH1 Experiences with Fedora Core 5 (FC5) »

Installing Perforce on Linux

Installing Perforce on Linux is a strange one.  The first strange thing you'll notice is that when you download the server all you're downloading is a binary.  One binary.  No tar, no rpm, no readme, no configuration files.  Just the single p4d binary.

After that, you'll want to copy this binary into your typical binary server directory.  On my systems, that's /usr/sbin.  Then you'll want to make it executable.  (e.g. "chmod +x /usr/sbin/p4d")  Finally, you'll want to actually set it so it launches at startup and you'll probably want it to launch right away.

To do this you must ... (alright, I haven't done this yet).

Another important, but optional, item is to configure a cron task to backup the database regularly.

To do this, you can ... (yeah, this hasn't been done yet, either).

Migration from Windows to Linux is another problem.  Windows is case-insensitive but Perforce stores the names in it's database with case.  Under Linux, it'll try to find the names assuming the case it stored.  Unfortunately, it also stores the names on the Windows system in lower case.  When you run a p4 verify command, it'll list any file with uppercase in it's name or path as missing.  This output is ripe for a script...

The first thing you must do is finish the migration.  When you've run the "p4 verify //..." and you see some "MISSING!" files, the following script may serve as a good starting point for fixing up the naming of the files.  Of course, you've backed up and know what you are doing and understand perl and all the other disclaimers.  The output from the "p4 verify //..." needs to go in the text file that is being opened (e.g. "p4vout.txt" in this script).

#!/usr/bin/perl -w
use strict;

open (my $fh, "p4vout.txt") or die "No file.\n";

my @lines = <$fh>;

my $num = 0;
my $fatals = 0;
foreach my $line (@lines)
{

    # only the first instance of a file is needed
    # only ones that are MISSING! are needed
    if ($line =~ m/^\/\/(.*)\#1.*MISSING\!/)
    {
    print ++$num.": [". $line . "]\n";
    # $1 now contains the depot path withhout the leading "//"
    print "orig: $1\n";
    my $src = "./".lc($1);
    my $dst = "./".$1;

    my @fparts = split("/", $dst);
    my $name = pop @fparts;
    my $path = join("/", @fparts);
    print "name [$name] -- path [$path]\n";
    print "mkdir -p \"$path\"\n";
    system ("mkdir","-p", "$path") == 0  or die("Failed to mkdir!");
    if (-e "$src,v" || -e "$src,d")
    {
        print "mv: $src $dst\n";
        rename ("$src,v", "$dst,v" ) or rename("$src,d", "$dst,d") or die("Failed to rename!!");
        # undo
        #rename ("$dst,v", "$src,v") or rename("$dst,d", "$src,v") or die ("Didn't undo!!");
    }
    elsif (-e "$dst,v" || -e "$dst,d")
    {
       
        #print "[$src,v] or [$src,d] does not exist\n";
        print "File already moved.\n";
    }
    else
    {
        print "Oops\nline=[$line].\n";
        print "Possible fatal errors: ".++$fatals."\n";
    }
    }
}
print "Fatals: $fatals\n";


The formatting didn't carry through all that well. In any case, it should be explanatory with the comments.  The "fatals" are files that never appeared to exist in the source.  This is not meant to be super efficient, but it is meant to provide error checking and a parsable output.  In the end, it didn't take long to run over 10,000 files. 

This was used Perforce 2005.2.  Use at your own risk.  That said, I hope this will help someone out.

Posted by Shane on April 10, 2006 10:04 PM |

TrackBacks

TrackBack URL for this entry:
http://www.kf6nvr.net/mt/kf6nvr-tb.cgi/708