config/module2dir.pl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rwxr-xr-x

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 #!/usr/bin/perl -w
     2 # This Source Code Form is subject to the terms of the Mozilla Public
     3 # License, v. 2.0. If a copy of the MPL was not distributed with this
     4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7 #
     8 # Create a mapping from symbolic component name to directory name(s).
     9 #
    10 # Tue Oct 16 16:48:36 PDT 2001
    11 # <mcafee@netscape.com>
    13 use strict;
    15 # For --option1, --option2, ...
    16 use Getopt::Long;
    17 Getopt::Long::Configure("bundling_override");
    18 Getopt::Long::Configure("auto_abbrev");
    20 # Globals
    21 my $list_only_mode = 0;
    22 my $opt_list_only;
    23 my $mapfile = "";
    24 my %map;
    26 sub PrintUsage {
    27   die <<END_USAGE
    28   Prints out directories needed for a given list of components.
    29   usage: module2dir.pl [--list-only] [--mapfile mapfile] <component-name1> <component-name2> ...
    30 END_USAGE
    31 }
    33 sub parse_map_file($) {
    34     my ($mapfile) = @_;
    35     my (%mod_map, $tmp, $dir, $mod, @mod_list);
    37     undef %mod_map;
    38     open (MAPFILE, "$mapfile") || die ("$mapfile: $!\n");
    39     while ($tmp=<MAPFILE>) {
    40 	chomp ($tmp);
    41 	($dir, $mod, @mod_list) = split(/:/, $tmp, 3);
    42 	$mod =~ s/[\s]*(\S+)[\s]*/$1/;
    43 	$mod_map{$mod} .= "$dir ";
    44     }
    45     close(MAPFILE);
    46     foreach $mod (sort(keys %mod_map)) {
    47 	my (@dirlist, @trimlist, $found, $tdir);
    48 	@dirlist = split(/\s+/, $mod_map{$mod});
    49 	$mod_map{$mod} = "";
    50 	foreach $dir (@dirlist) {
    51 	    $found = 0; 
    52 	    foreach $tdir (@trimlist) {
    53 		$found++, last if ($dir =~ m/^$tdir\// || $dir eq $tdir);
    54 	    }
    55 	    push @trimlist, $dir if (!$found);
    56         }
    57 	$map{$mod} = join(" ", @trimlist);
    58 	#print "$mod: $map{$mod}\n";
    59     }
    60 }
    62 sub dir_for_required_component {
    63   my ($component) = @_;
    64   my $rv;
    65   my $dir;
    67   $dir = $map{$component};
    68   if($dir) {
    69 	# prepend "mozilla/" in front of directory names.
    70 	$rv = "mozilla/$dir";
    71 	$rv =~ s/\s+/ mozilla\//g;  # Hack for 2 or more directories.
    72   } else {
    73 	$rv = 0;
    74   }
    75   return $rv;
    76 }
    78 {
    80   # Add stdin to the commandline.  This makes commandline-only mode hang,
    81   # call it a bug.  Not sure how to get around this.
    82   push (@ARGV, split(' ',<STDIN>));
    84   PrintUsage() if !GetOptions('list-only' => \$opt_list_only,
    85 			      'mapfile=s' => \$mapfile);
    87   # Pick up arguments, if any.
    88   if($opt_list_only) {
    89   	$list_only_mode = 1;
    90   }
    92   &parse_map_file($mapfile);
    94   my $arg;
    95   my $dir;
    96   while ($arg = shift @ARGV) {
    97 	$dir = dir_for_required_component($arg);
    98 	if($dir) {
    99       if($list_only_mode) {
   100 		print $dir, " ";
   101 	  } else {
   102 		print "$arg: ", $dir, "\n";
   103 	  }
   104 	} else {
   105 	  # do nothing
   106 	}
   107   }
   108   if($dir && $list_only_mode) {
   109 	print "\n";
   110   }
   111 }

mercurial