use strict;
use warnings;
# grab the list of depotNames from perforce
open(P4, "p4 files //...#have |") || die "could not open pipe p4 files\n";
# map of the directories we've attempted to make
my %made;
while (<P4>)
{
# clean up the depotName
chomp;
# remove the file revision
s/#.*//;
# break the depotName up into components
my @dirs = split /\//;
# grab the fileName off the end of the depotName component list
my $fileName = pop @dirs;
# step through the component list
my $path = "";
foreach my $dir (@dirs)
{
# skip empty components (which should only happen at the start)
next if ($dir eq "");
# append the new directory to the current path
$path .= "/" if ($path ne "");
$path .= $dir;
# only try to make directories once.
# this optimization assumes that checking the map is faster than going to the OS.
if (!defined $made{$path})
{
# check if the directory already exists
if (!-d $path)
{
# try to make the directory
mkdir($path) || die "mkdir failed $path\n";
}
$made{$path} = 1;
}
}
# create the file and put the depotName into the file
open(F, ">" . $path . "/" . $fileName) || die "could not open $fileName for writing\n";
print F $_, "\n";
close(F);
}
close(P4);