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 | use File::Spec; |
michael@0 | 2 | |
michael@0 | 3 | my(@chunks, @list, $entry, $main_cats, $spacing); |
michael@0 | 4 | @list = ('conf', 'perf'); |
michael@0 | 5 | foreach $entry (@list) { |
michael@0 | 6 | $main_cats .= " <rdf:li><rdf:Description about=\"urn:x-buster:$entry\" nc:dir=\"$entry\" /></rdf:li>\n"; |
michael@0 | 7 | go_in($entry, '', $entry); |
michael@0 | 8 | } |
michael@0 | 9 | if ($ARGV[0]) { |
michael@0 | 10 | open OUTPUT, ">$ARGV[0]"; |
michael@0 | 11 | } |
michael@0 | 12 | else { |
michael@0 | 13 | open OUTPUT, ">xalan.rdf"; |
michael@0 | 14 | }; |
michael@0 | 15 | select(OUTPUT); |
michael@0 | 16 | print '<?xml version="1.0"?> |
michael@0 | 17 | |
michael@0 | 18 | <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
michael@0 | 19 | xmlns:nc="http://home.netscape.com/NC-rdf#"> |
michael@0 | 20 | <rdf:Seq about="urn:root"> |
michael@0 | 21 | ' . $main_cats . ' </rdf:Seq> |
michael@0 | 22 | '; |
michael@0 | 23 | print join('',@chunks); |
michael@0 | 24 | print '</rdf:RDF> |
michael@0 | 25 | '; |
michael@0 | 26 | exit 0; |
michael@0 | 27 | |
michael@0 | 28 | sub go_in { |
michael@0 | 29 | my($current, $about, $cat) = @_; |
michael@0 | 30 | my (@list, $entry, @subdirs, @files, @purps, $rdf); |
michael@0 | 31 | chdir $current; |
michael@0 | 32 | @list = <*>; |
michael@0 | 33 | |
michael@0 | 34 | LOOP: foreach $entry (@list) { |
michael@0 | 35 | next LOOP if $entry=~/^CVS$/; |
michael@0 | 36 | if (! -d $entry) { |
michael@0 | 37 | if ($entry=~/^($current.*)\.xsl$/) { |
michael@0 | 38 | local $source = $entry; |
michael@0 | 39 | $source=~s/xsl$/xml/; |
michael@0 | 40 | next LOOP if ! -f $source; |
michael@0 | 41 | $entry=~/^($current.*)\.xsl$/; |
michael@0 | 42 | push(@files, $1); |
michael@0 | 43 | local ($purp, $purp_open); |
michael@0 | 44 | open STYLE, $entry; |
michael@0 | 45 | $purp_open = 0; |
michael@0 | 46 | while (<STYLE>) { |
michael@0 | 47 | if (/<!--\s+purpose: (.+)\s*-->/i) { |
michael@0 | 48 | $purp .= $1; |
michael@0 | 49 | } |
michael@0 | 50 | elsif (/<!--\s+purpose: (.+)\s*$/i) { |
michael@0 | 51 | $purp_open = 1; |
michael@0 | 52 | $purp .= $1; |
michael@0 | 53 | } |
michael@0 | 54 | elsif ($purp_open) { |
michael@0 | 55 | if (/\s*(\s.+)\s*-->/) { |
michael@0 | 56 | $purp_open = 0; |
michael@0 | 57 | $purp .= $1; |
michael@0 | 58 | } |
michael@0 | 59 | elsif (/\s*(\s.+)\s*$/) { |
michael@0 | 60 | $purp .= $1; |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | $purp=~s/"/'/g; $purp=~s/&/&/g; $purp=~s/</</g; |
michael@0 | 65 | $purp=~s/\r/ /g; $purp=~s/\s\s/ /g; $purp=~s/\s$//g; |
michael@0 | 66 | push(@purps, $purp); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | else { |
michael@0 | 70 | push(@subdirs, $entry); |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | if (@subdirs > 0 || @files > 0) { |
michael@0 | 75 | my $topic = $about.$current; $topic=~s/\///g; |
michael@0 | 76 | $rdf = ' <rdf:Seq about="urn:x-buster:'.$topic."\">\n"; |
michael@0 | 77 | foreach $entry (@subdirs) { |
michael@0 | 78 | if (go_in($entry, $about.$current.'/', $cat)) { |
michael@0 | 79 | my $id = 'urn:x-buster:'.$about.$current.$entry; $id=~s/\///g; |
michael@0 | 80 | $rdf .= " <rdf:li><rdf:Description about=\"$id\" nc:dir=\"$entry\" /></rdf:li>\n"; |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | for (my $i=0; $i < @files; $i++) { |
michael@0 | 84 | my $uri = $about.$current.'/'.$files[$i]; |
michael@0 | 85 | $uri=~s/[^\/]+\///; |
michael@0 | 86 | my $id = $uri; $id=~s/\///g; |
michael@0 | 87 | $rdf .= " <rdf:li><rdf:Description about=\"urn:x-buster:$files[$i]\" nc:name=\"$files[$i]\" nc:purp=\"$purps[$i]\" nc:path=\"$uri\" nc:category=\"$cat\" /></rdf:li>\n"; |
michael@0 | 88 | } |
michael@0 | 89 | $rdf .= " </rdf:Seq>\n"; |
michael@0 | 90 | push(@chunks, $rdf); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | chdir File::Spec->updir; |
michael@0 | 94 | return (@subdirs > 0 || @files > 0); |
michael@0 | 95 | } |