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/env perl |
michael@0 | 2 | |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | ##----------------------------## |
michael@0 | 8 | ##---] CORE/CPAN INCLUDES [---## |
michael@0 | 9 | ##----------------------------## |
michael@0 | 10 | use strict; |
michael@0 | 11 | use warnings; |
michael@0 | 12 | use Getopt::Long; |
michael@0 | 13 | |
michael@0 | 14 | ##-------------------## |
michael@0 | 15 | ##---] EXPORTS [---## |
michael@0 | 16 | ##-------------------## |
michael@0 | 17 | our $VERSION = qw(1.1); |
michael@0 | 18 | |
michael@0 | 19 | ##-------------------## |
michael@0 | 20 | ##---] GLOBALS [---## |
michael@0 | 21 | ##-------------------## |
michael@0 | 22 | my %argv; |
michael@0 | 23 | my $modver = $Getopt::Long::VERSION || 0; |
michael@0 | 24 | my $isOldGetopt = ($modver eq '2.25') ? 1 : 0; |
michael@0 | 25 | |
michael@0 | 26 | ########################################################################### |
michael@0 | 27 | ## Intent: Script init function |
michael@0 | 28 | ########################################################################### |
michael@0 | 29 | sub init |
michael@0 | 30 | { |
michael@0 | 31 | if ($isOldGetopt) |
michael@0 | 32 | { |
michael@0 | 33 | # mozilla.build/mingw perl in need of an upgrade |
michael@0 | 34 | # emulate Getopt::Long switch|short:init |
michael@0 | 35 | foreach (qw(debug regex sort)) |
michael@0 | 36 | { |
michael@0 | 37 | if (defined($argv{$_})) |
michael@0 | 38 | { |
michael@0 | 39 | $argv{$_} ||= 1; |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | } # init |
michael@0 | 44 | |
michael@0 | 45 | ##----------------## |
michael@0 | 46 | ##---] MAIN [---## |
michael@0 | 47 | ##----------------## |
michael@0 | 48 | my @args = ($isOldGetopt) |
michael@0 | 49 | ? qw(debug|d regex|r sort|s) |
michael@0 | 50 | : qw(debug|d:1 regex|r:1 sort|s:1) |
michael@0 | 51 | ; |
michael@0 | 52 | |
michael@0 | 53 | unless(GetOptions(\%argv, @args)) |
michael@0 | 54 | { |
michael@0 | 55 | print "Usage: $0\n"; |
michael@0 | 56 | print " --sort Sort list elements early\n"; |
michael@0 | 57 | print " --regex Exclude subdirs by pattern\n"; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | init(); |
michael@0 | 61 | my $debug = $argv{debug} || 0; |
michael@0 | 62 | |
michael@0 | 63 | my %seen; |
michael@0 | 64 | my @out; |
michael@0 | 65 | my @in = ($argv{sort}) ? sort @ARGV : @ARGV; |
michael@0 | 66 | |
michael@0 | 67 | foreach my $d (@in) |
michael@0 | 68 | { |
michael@0 | 69 | next if ($seen{$d}++); |
michael@0 | 70 | |
michael@0 | 71 | print " arg is $d\n" if ($debug); |
michael@0 | 72 | |
michael@0 | 73 | if ($argv{regex}) |
michael@0 | 74 | { |
michael@0 | 75 | my $found = 0; |
michael@0 | 76 | foreach my $dir (@out) |
michael@0 | 77 | { |
michael@0 | 78 | my $dirM = quotemeta($dir); |
michael@0 | 79 | $found++, last if ($d eq $dir || $d =~ m!^${dirM}\/!); |
michael@0 | 80 | } |
michael@0 | 81 | print "Adding $d\n" if ($debug && !$found); |
michael@0 | 82 | push @out, $d if (!$found); |
michael@0 | 83 | } else { |
michael@0 | 84 | print "Adding: $d\n" if ($debug); |
michael@0 | 85 | push(@out, $d); |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | print "@out\n" |
michael@0 | 90 | |
michael@0 | 91 | # EOF |