11 my $root = shift @ARGV;
 
  15 if (my $file = IO::File->new("${root}/tmp/manifest.json", "r"))
 
  17     my $manifest = decode_json(join("\n", $file->getlines));
 
  21     expire_assets($manifest, "${root}/public/assets", "");
 
  25     die "Can't open ${root}/tmp/manifest.json: $!" unless $!{ENOENT};
 
  33     my $assetroot = shift;
 
  36     if (my $dir = IO::Dir->new("${assetroot}/${prefix}"))
 
  38         $prefix = "${prefix}/" unless $prefix eq "";
 
  40         while (my $name = $dir->read)
 
  42             next if $name eq "." || $name eq "..";
 
  44             my $path = $name = "${prefix}${name}";
 
  48             if (-d "${assetroot}/${path}")
 
  50                 expire_assets($manifest, $assetroot, $path);
 
  52             elsif (exists($manifest->{files}->{$name}))
 
  54                 # Still a live asset (with checksum)
 
  56             elsif (exists($manifest->{assets}->{$name}))
 
  58                 # Still a live asset (without checksum)
 
  60             elsif (-A "${assetroot}/${path}" > 28)
 
  62                 unlink("${assetroot}/${path}") || die "Can't remove ${assetroot}/${path}: $!";
 
  70         die "Can't read ${assetroot}/${prefix}: $!";