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

mercurial