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