6 use File::Path qw/ make_path /;
8 my $root_dir = $ENV{PUBLIC_ROOT_DIR}
9 or die "Need PUBLIC_ROOT_DIR\n";
10 my $link_dir = $ENV{PUBLIC_LINK_DIR}
11 or die "Need PUBLIC_LINK_DIR\n";
12 my $http_uri = $ENV{PUBLIC_HTTP_URI}
13 or die "Need PUBLIC_HTTP_URI\n";
18 $n = 10 unless $n > 0;
20 my @chars = ( 'a' .. 'z', 'A' .. 'Z', '0' .. '9' );
22 push @path, $chars[ rand @chars ] for 1 .. $n;
24 return join '', @path;
29 my $path = File::Spec->catdir($link_dir, $nonce);
30 make_path($path, { chmod => 0777 });
35 # get list of files matching name from root directory
37 or die "Need filename!\n";
39 opendir DIR, $root_dir
41 my @files = grep /$name/i, readdir(DIR);
44 # exit if no files found
45 die "No match: $name\n" unless @files;
47 # create nonce dir and add symbolic links
48 my $nonce = nonce(20);
49 my $nonce_dir = makeNonceDir($nonce);
51 for my $file (@files) {
52 my $root_filepath = File::Spec->catfile($root_dir, $file);
53 my $link_filepath = File::Spec->catfile($nonce_dir, $file);
55 symlink $root_filepath, $link_filepath
56 or die "Unable to create symlink: $root_filepath -> $link_filepath";
58 my $uri_link = join '/', $http_uri, $nonce, $file;
64 opendir DIR, $link_dir;
65 my @nonces = readdir(DIR);
68 for my $nonce (@nonces) {
69 next if $nonce eq '.';
70 next if $nonce eq '..';
72 # ensure it's a directory
73 my $nonce_dir = File::Spec->catdir($link_dir, $nonce);
74 next unless -d $nonce_dir;
76 # make URIs for all the files in the nonce dirs
77 opendir DIR, $nonce_dir;
78 my @files = readdir(DIR);
81 for my $file (@files) {
83 next if $file eq '..';
85 my $uri_link = join '/', $http_uri, $nonce, $file;
94 addFiles($_) for @ARGV;