Ejemplo n.º 1
0
 def testCopyPathToFileGzip(self):
   request = rdf_client_action.CopyPathToFileRequest(
       offset=0, length=0, src_path=self.pathspec, gzip_output=True)
   result = self.RunAction(standard.CopyPathToFile, request)[0]
   self.assertEqual(
       hashlib.sha1(gzip.open(result.dest_path.path).read()).hexdigest(),
       self.hash_in)
Ejemplo n.º 2
0
 def testCopyPathToFile(self):
   request = rdf_client_action.CopyPathToFileRequest(
       offset=0, length=0, src_path=self.pathspec, gzip_output=False)
   result = self.RunAction(standard.CopyPathToFile, request)[0]
   hash_out = hashlib.sha1(open(result.dest_path.path,
                                "rb").read()).hexdigest()
   self.assertEqual(self.hash_in, hash_out)
Ejemplo n.º 3
0
 def testCopyPathToFileLifetimeLimit(self):
   request = rdf_client_action.CopyPathToFileRequest(
       offset=0,
       length=23,
       src_path=self.pathspec,
       gzip_output=False,
       lifetime=0.1)
   result = self.RunAction(standard.CopyPathToFile, request)[0]
   self.assertTrue(os.path.exists(result.dest_path.path))
   time.sleep(1)
   self.assertFalse(os.path.exists(result.dest_path.path))
Ejemplo n.º 4
0
  def testCopyPathToFileOffsetandLimit(self):

    with open(self.path_in, "rb") as f:
      f.seek(38)
      out = f.read(25)
      hash_in = hashlib.sha1(out).hexdigest()

    request = rdf_client_action.CopyPathToFileRequest(
        offset=38, length=25, src_path=self.pathspec, gzip_output=False)
    result = self.RunAction(standard.CopyPathToFile, request)[0]
    output = open(result.dest_path.path, "rb").read()
    self.assertEqual(len(output), 25)
    hash_out = hashlib.sha1(output).hexdigest()
    self.assertEqual(hash_in, hash_out)
Ejemplo n.º 5
0
    def Run(self, args):
        """Read from a VFS file and write to a GRRTempFile on disk.

    If file writing doesn't complete files won't be cleaned up.

    Args:
      args: see CopyPathToFile in jobs.proto
    """
        src_fd = vfs.VFSOpen(args.src_path, progress_callback=self.Progress)
        src_fd.Seek(args.offset)
        offset = src_fd.Tell()

        length = args.length or (1024**4)  # 1 TB

        suffix = ".gz" if args.gzip_output else ""

        dest_fd, dest_pathspec = tempfiles.CreateGRRTempFileVFS(
            lifetime=args.lifetime, suffix=suffix)

        dest_file = dest_fd.name
        with dest_fd:

            if args.gzip_output:
                gzip_fd = gzip.GzipFile(dest_file, "wb", 9, dest_fd)

                # Gzip filehandle needs its own close method called
                with gzip_fd:
                    written = self._Copy(src_fd, gzip_fd, length)
            else:
                written = self._Copy(src_fd, dest_fd, length)

        self.SendReply(
            rdf_client_action.CopyPathToFileRequest(
                offset=offset,
                length=written,
                src_path=args.src_path,
                dest_path=dest_pathspec,
                gzip_output=args.gzip_output))
Ejemplo n.º 6
0
 def testCopyPathToFileLimitLength(self):
   request = rdf_client_action.CopyPathToFileRequest(
       offset=0, length=23, src_path=self.pathspec, gzip_output=False)
   result = self.RunAction(standard.CopyPathToFile, request)[0]
   output = open(result.dest_path.path, "rb").read()
   self.assertEqual(len(output), 23)