~ubuntu-branches/ubuntu/lucid/enigmail/lucid-security

« back to all changes in this revision

Viewing changes to build/macosx/universal/unify

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-04-18 15:10:32 UTC
  • mfrom: (0.11.1) (19.1.1 lucid-proposed)
  • Revision ID: package-import@ubuntu.com-20120418151032-2u0e8yetqqpp5tam
Tags: 2:1.4.1-0ubuntu0.10.04.1
* New upstream release v1.4.1
  - LP: #987305
  - Fix LP: #968122 - localization messed up

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
sub complain($$@);
200
200
sub copyIfIdentical($$$);
201
201
sub slurp($);
 
202
sub get_sorted($);
202
203
sub compare_sorted($$);
203
 
sub copy_sorted($$);
204
204
sub copyIfIdenticalWhenSorted($$$);
205
205
sub createUniqueFile($$);
206
206
sub makeUniversal($$$);
507
507
  return @lines;
508
508
}
509
509
 
 
510
# get_sorted($file)
 
511
# Get the sorted lines of a file as a list, normalizing a newline on the last line if necessary.
 
512
sub get_sorted($) {
 
513
  my ($file) = @_;
 
514
  my @lines = slurp($file);
 
515
  my $lastline = $lines[-1];
 
516
  if (!($lastline =~ /\n/)) {
 
517
    $lines[-1] = $lastline . "\n";
 
518
  }
 
519
  return sort(@lines);
 
520
}
 
521
 
510
522
# compare_sorted($file1, $file2)
511
523
#
512
524
# Read the contents of both files into arrays, sort the arrays,
516
528
# Returns undef on error.
517
529
sub compare_sorted($$) {
518
530
  my ($file1, $file2) = @_;
519
 
  my @lines1 = sort(slurp($file1));
520
 
  my @lines2 = sort(slurp($file2));
 
531
  my @lines1 = get_sorted($file1);
 
532
  my @lines2 = get_sorted($file2);
521
533
 
522
534
  return undef if !@lines1 || !@lines2;
523
535
  return 1 unless scalar @lines1 == scalar @lines2;
528
540
  return 0;
529
541
}
530
542
 
531
 
# copy_sorted($source, $destination)
532
 
#
533
 
# $source and $destination are filenames. Read the contents of $source
534
 
# into an array, sort it, and then write the sorted contents to $destination.
535
 
# Returns 1 on success, and undef on failure.
536
 
sub copy_sorted($$) {
537
 
  my ($src, $dest) = @_;
538
 
  my @lines = sort(slurp($src));
539
 
  return undef unless @lines;
540
 
  open FILE, "> $dest" or return undef;
541
 
  print FILE @lines;
542
 
  close FILE;
543
 
  return 1;
544
 
}
545
 
 
546
543
# copyIfIdenticalWhenSorted($source1, $source2, $target)
547
544
#
548
545
# $source1 and $source2 are FileAttrCache objects that are compared, and if
592
589
      return 0;
593
590
    }
594
591
 
595
 
    if (!copy_sorted($source1->path(), $target)) {
596
 
      complain(1, 'copyIfIdenticalWhenSorted: copy_sorted: '.$!
 
592
    if (!copy($source1->path(), $target)) {
 
593
      complain(1, 'copyIfIdenticalWhenSorted: copy: '.$!
597
594
               .' while copying',
598
595
               $source1->path(),
599
596
               $target);
1063
1060
    return 1;
1064
1061
  }
1065
1062
  elsif($aSourceFile->lIsRegularFile()) {
1066
 
    my ($machPPC, $machX86);
 
1063
    my ($machPPC, $machX86, $fileName);
1067
1064
    if (!defined($filePPC) || !defined($fileX86)) {
1068
1065
      # One of the source files isn't present.  The right thing to do is
1069
1066
      # to just copy what does exist straight over, so skip Mach-O checks.
1070
1067
      $machPPC = 0;
1071
1068
      $machX86 = 0;
 
1069
      if (defined($filePPC)) {
 
1070
        $fileName = $filePPC;
 
1071
      } elsif (defined($fileX86)) {
 
1072
        $fileName = $fileX86;
 
1073
      } else {
 
1074
        complain(1, "The file must exist in at least one directory");
 
1075
        exit(1);
 
1076
      }
1072
1077
    }
1073
1078
    else {
 
1079
      # both files exist, pick the name of one.
 
1080
      $fileName = $fileX86;
1074
1081
      if (!defined($machPPC=$filePPC->isMachO())) {
1075
1082
        return complain(1, 'makeUniversal: isFileMachO ppc failed for:',
1076
1083
                        $filePPC->path());
1092
1099
      return makeUniversalFile($filePPC, $fileX86, $fileTargetPath);
1093
1100
    }
1094
1101
 
1095
 
    if (grep { $filePPC->path() =~ m/$_/; } @gSortMatches) {
 
1102
    if (grep { $fileName->path() =~ m/$_/; } @gSortMatches) {
1096
1103
      # Regular files, but should be compared with sorting first.
1097
1104
      # copyIfIdenticalWhenSorted will print an error if it fails.
1098
1105
      return copyIfIdenticalWhenSorted($filePPC, $fileX86, $fileTargetPath);
1165
1172
 
1166
1173
  package FileAttrCache;
1167
1174
 
 
1175
  # from /usr/include/mach-o/loader.h
 
1176
  use constant MH_MAGIC    => 0xfeedface;
 
1177
  use constant MH_CIGAM    => 0xcefaedfe;
 
1178
  use constant MH_MAGIC_64 => 0xfeedfacf;
 
1179
  use constant MH_CIGAM_64 => 0xcffaedfe;
 
1180
 
1168
1181
  use Fcntl(':DEFAULT', ':mode');
1169
1182
 
1170
1183
  # FileAttrCache->new($path)
1243
1256
    }
1244
1257
 
1245
1258
    # Accept Mach-O fat files or Mach-O thin files of either endianness.
1246
 
    if ($magic == 0xfeedface ||
1247
 
        $magic == 0xcefaedfe ||
 
1259
    if ($magic == MH_MAGIC ||
 
1260
        $magic == MH_CIGAM ||
 
1261
        $magic == MH_MAGIC_64 ||
 
1262
        $magic == MH_CIGAM_64 ||
1248
1263
        $this->isFat()) {
1249
1264
      return 1;
1250
1265
    }