소스 검색

Extract install.rdf from Firefox extensions manually

With approximately zero knowledge of how zip files work, our issue was
that the `install.rdf` that we needed from the XPI file was not listed
in the manifest that IO::Uncompress::Unzip::unzip was reading. This
prohibits us from using the lovely `Name => 'install.rdf'` shortcut that
was so handy. As a result, we must traverse the zip manually, but in the
end the results are the same: the `em:id` is extracted from the xpi.
Daniel Gempesaw 10 년 전
부모
커밋
0ba6187fbe
1개의 변경된 파일24개의 추가작업 그리고 7개의 파일을 삭제
  1. 24 7
      lib/Selenium/Firefox/Profile.pm

+ 24 - 7
lib/Selenium/Firefox/Profile.pm

@@ -12,8 +12,8 @@ use Cwd qw(abs_path);
 use File::Copy qw(copy);
 use File::Temp;
 use File::Basename qw(dirname);
-use IO::Uncompress::Unzip qw(unzip $UnzipError);
-use JSON qw/decode_json/;
+use IO::Uncompress::Unzip qw($UnzipError);
+use JSON qw(decode_json);
 use MIME::Base64;
 use Scalar::Util qw(blessed looks_like_number);
 use XML::Simple;
@@ -265,11 +265,8 @@ sub _install_extensions {
         # its id, which is found in the install.rdf in the root of the
         # zip.
 
-        my $fh;
-        unzip $xpi => \$fh, Name => "install.rdf"
-          or die "unzip failed: $UnzipError\n";
-
-        my $rdf = XMLin($fh);
+        my $rdf_string = $self->_extract_install_rdf($xpi);
+        my $rdf = XMLin($rdf_string);
         my $name = $rdf->{Description}->{'em:id'};
 
         my $xpi_dest = $extension_dir . $name . ".xpi";
@@ -278,6 +275,26 @@ sub _install_extensions {
     }
 }
 
+sub _extract_install_rdf {
+    my ($self, $xpi) = @_;
+
+    my $unzipped = IO::Uncompress::Unzip->new($xpi)
+      or die "Cannot unzip $xpi: $UnzipError";
+
+    my $install_rdf = '';
+    while ($unzipped->nextStream) {
+        my $filename = $unzipped->getHeaderInfo->{Name};
+        if ($filename eq 'install.rdf') {
+            my $buffer;
+            while ((my $status = $unzipped->read($buffer)) > 0) {
+                $install_rdf .= $buffer;
+            }
+        }
+    }
+
+    return $install_rdf;
+}
+
 1;
 
 __END__