Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ef25191 authored by Kelvin Zhang's avatar Kelvin Zhang
Browse files

Fix picle error on ota_from_target_files

When trying to make a deep copy of PartitionBuildProps, execution fails
with picle error because PartitionBuildProps stores a ZipFile object,
which stores a lock object, which doesn't support pickling.

To fix it, pickle ZipFile object as a str to its path.

Test: generate ota with boot variable files
Bug: 253549364
Change-Id: I92c5d78ce65045495203c85862922d33d886e9ea
parent 434295ce
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import copy
import datetime
import errno
import fnmatch
from genericpath import isdir
import getopt
import getpass
import gzip
@@ -699,7 +700,13 @@ def ReadFromInputFile(input_file, fn):
  """Reads the contents of fn from input zipfile or directory."""
  if isinstance(input_file, zipfile.ZipFile):
    return input_file.read(fn).decode()
  elif zipfile.is_zipfile(input_file):
    with zipfile.ZipFile(input_file, "r", allowZip64=True) as zfp:
      return zfp.read(fn).decode()
  else:
    if not os.path.isdir(input_file):
      raise ValueError(
          "Invalid input_file, accepted inputs are ZipFile object, path to .zip file on disk, or path to extracted directory. Actual: " + input_file)
    path = os.path.join(input_file, *fn.split("/"))
    try:
      with open(path) as f:
@@ -1055,6 +1062,13 @@ class PartitionBuildProps(object):
    return {key: val for key, val in d.items()
            if key in self.props_allow_override}

  def __getstate__(self):
    state = self.__dict__.copy()
    # Don't pickle baz
    if "input_file" in state and isinstance(state["input_file"], zipfile.ZipFile):
      state["input_file"] = state["input_file"].filename
    return state

  def GetProp(self, prop):
    return self.build_props.get(prop)