Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | # |
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 | sub recursive_copy { |
michael@0 | 6 | local($fromdir); |
michael@0 | 7 | local($todir); |
michael@0 | 8 | local(@dirlist); |
michael@0 | 9 | $fromdir = shift; |
michael@0 | 10 | $todir = shift; |
michael@0 | 11 | |
michael@0 | 12 | print STDERR "recursive copy called with $fromdir, $todir\n"; |
michael@0 | 13 | |
michael@0 | 14 | #remove any trailing slashes. |
michael@0 | 15 | $fromdir =~ s/\/$//; |
michael@0 | 16 | $todir =~ s/\/$//; |
michael@0 | 17 | |
michael@0 | 18 | opendir(DIR, $fromdir); |
michael@0 | 19 | @dirlist = readdir DIR; |
michael@0 | 20 | close DIR; |
michael@0 | 21 | |
michael@0 | 22 | |
michael@0 | 23 | foreach $file (@dirlist) { |
michael@0 | 24 | if (! (($file eq "." ) || ($file eq "..") )) { |
michael@0 | 25 | |
michael@0 | 26 | if (-d "$fromdir/$file") { |
michael@0 | 27 | print STDERR "handling directory $todir/$file\n"; |
michael@0 | 28 | &rec_mkdir("$todir/$file"); |
michael@0 | 29 | &recursive_copy("$fromdir/$file","$todir/$file"); |
michael@0 | 30 | } |
michael@0 | 31 | else { |
michael@0 | 32 | print STDERR "handling file $fromdir/$file\n"; |
michael@0 | 33 | &my_copy("$fromdir/$file","$todir/$file"); |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | sub parse_argv { |
michael@0 | 40 | |
michael@0 | 41 | # print STDERR "Parsing Variables\n"; |
michael@0 | 42 | |
michael@0 | 43 | foreach $q ( @ARGV ) { |
michael@0 | 44 | if (! ($q =~ /=/)) { |
michael@0 | 45 | $var{$lastassigned} .= " $q"; |
michael@0 | 46 | } |
michael@0 | 47 | else { |
michael@0 | 48 | $q =~ /^([^=]*)=(.*)/; |
michael@0 | 49 | $left = $1; |
michael@0 | 50 | $right = $2; |
michael@0 | 51 | |
michael@0 | 52 | $right =~ s/ *$//; |
michael@0 | 53 | $var{$left} = $right; |
michael@0 | 54 | |
michael@0 | 55 | $lastassigned = $left; |
michael@0 | 56 | |
michael@0 | 57 | } |
michael@0 | 58 | print STDERR "Assigned $lastassigned = $var{$lastassigned}\n"; |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | # usage: &my_copy("dir/fromfile","dir2/tofile"); |
michael@0 | 64 | # do a 'copy' - files only, 'to' MUST be a filename, not a directory. |
michael@0 | 65 | |
michael@0 | 66 | # fix this to be able to use copy on win nt. |
michael@0 | 67 | |
michael@0 | 68 | sub my_copy { |
michael@0 | 69 | local($from); |
michael@0 | 70 | local($to); |
michael@0 | 71 | local($cpcmd); |
michael@0 | 72 | |
michael@0 | 73 | $from = shift; |
michael@0 | 74 | $to = shift; |
michael@0 | 75 | |
michael@0 | 76 | if ( ! defined $var{OS_ARCH}) { |
michael@0 | 77 | die "OS_ARCH not defined!"; |
michael@0 | 78 | } |
michael@0 | 79 | else { |
michael@0 | 80 | if ($var{OS_ARCH} eq 'WINNT') { |
michael@0 | 81 | $cpcmd = 'cp'; |
michael@0 | 82 | } |
michael@0 | 83 | else { |
michael@0 | 84 | $cpcmd = 'cp'; |
michael@0 | 85 | } |
michael@0 | 86 | print STDERR "COPYING: $cpcmd $from $to\n"; |
michael@0 | 87 | system("$cpcmd $from $to"); |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | |
michael@0 | 92 | sub old_my_copy { |
michael@0 | 93 | local($from); |
michael@0 | 94 | local($to); |
michael@0 | 95 | |
michael@0 | 96 | $from = shift; |
michael@0 | 97 | $to = shift; |
michael@0 | 98 | open(FIN, "<$from") || die("Can't read from file $from\n"); |
michael@0 | 99 | if ( ! open(FOUT,">$to")) { |
michael@0 | 100 | close FIN; |
michael@0 | 101 | die "Can't write to file $to\n"; |
michael@0 | 102 | } |
michael@0 | 103 | while (read(FIN, $buf, 100000)) { |
michael@0 | 104 | print FOUT $buf; |
michael@0 | 105 | } |
michael@0 | 106 | close (FIN); |
michael@0 | 107 | close (FOUT); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | sub rec_mkdir { |
michael@0 | 111 | local($arg); |
michael@0 | 112 | local($t); |
michael@0 | 113 | local($q); |
michael@0 | 114 | |
michael@0 | 115 | $arg = shift; |
michael@0 | 116 | $t = ""; |
michael@0 | 117 | foreach $q (split(/\//,$arg)) { |
michael@0 | 118 | $t .= $q; |
michael@0 | 119 | if (! ($t =~ /\.\.$/)) { |
michael@0 | 120 | if ($t =~ /./) { |
michael@0 | 121 | mkdir($t,0775); |
michael@0 | 122 | } |
michael@0 | 123 | } |
michael@0 | 124 | $t.= '/'; |
michael@0 | 125 | } |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | 1; |