6 use File::Path qw/ make_path /;
8 my $root_dir = '/mnt/Shared/Personal/My art';
9 my $link_dir = '/var/www/html/public';
10 my $http_uri = 'http://136.63.171.222/public';
15 $n = 10 unless $n > 0;
17 my @chars = ( 'a' .. 'z', 'A' .. 'Z', '0' .. '9' );
19 push @path, $chars[ rand @chars ] for 1 .. $n;
21 return join '', @path;
26 my $path = File::Spec->catdir($link_dir, $nonce);
27 make_path($path, { chmod => 0777 });
32 # get list of files matching name from root directory
34 or die "Need filename!\n";
36 opendir DIR, $root_dir;
37 my @files = grep /$name/i, readdir(DIR);
40 # exit if no files found
41 die "No match: $name\n" unless @files;
43 # create nonce dir and add symbolic links
44 my $nonce = nonce(20);
45 my $nonce_dir = makeNonceDir($nonce);
47 for my $file (@files) {
48 my $root_filepath = File::Spec->catfile($root_dir, $file);
49 my $link_filepath = File::Spec->catfile($nonce_dir, $file);
51 symlink $root_filepath, $link_filepath
52 or die "Unable to create symlink: $root_filepath -> $link_filepath";
54 my $uri_link = join '/', $http_uri, $nonce, $file;
60 opendir DIR, $link_dir;
61 my @nonces = readdir(DIR);
64 for my $nonce (@nonces) {
65 next if $nonce eq '.';
66 next if $nonce eq '..';
68 # ensure it's a directory
69 my $nonce_dir = File::Spec->catdir($link_dir, $nonce);
70 next unless -d $nonce_dir;
72 # make URIs for all the files in the nonce dirs
73 opendir DIR, $nonce_dir;
74 my @files = readdir(DIR);
77 for my $file (@files) {
79 next if $file eq '..';
81 my $uri_link = join '/', $http_uri, $nonce, $file;
90 addFiles($_) for @ARGV;