示例#1
0
def main():
	(options, args) = parseArgs()
	setupLog(options)

	plfFilePath = args[1]

	# Load path map
	pathMap = []
	pathMapFile = open(args[0])
	for line in pathMapFile:
		line = line.rstrip("\n").strip()
		if line and not line.startswith("#"):
			entry = line.split()
			if len(entry) != 2 and len(entry) != 3:
				logging.warning("%s: bad line: %s", args[0], line)
			else:
				pathMap.append(entry)
	pathMapFile.close()

	# Load plf
	plf = libplf.PlfFileInfo()
	plf.load(plfFilePath)

	# Process U_UNIXFILE entries, prepare a batch operation
	batchData = StringIO()
	for section in plf.sections:
		if section.type == "U_UNIXFILE":
			reMappedPath = getReMappedPath(pathMap, section.path).lstrip("/")
			logging.debug("%s -> %s", section.path, reMappedPath)
			batchData.write("'-j U_UNIXFILE:%d -p %s'\n" % 
					(section.idxSection, reMappedPath))
	libplf.plfbatchExec(plfFilePath, "'&'", batchData.getvalue())

	# Add path map roots at the start
	# We create a temp list that we reverse sort (because we will append each
	# item at the start of the plf). This way at the end directories will be
	# created in order
	dirPaths = []
	for entry in pathMap:
		# Only keep non-trivial entries
		if len(entry) >= 3 and entry[2] != "/":
			dirPaths.append(entry[2].lstrip("/"))
	dirPaths.sort(reverse=True)
	for dirPath in dirPaths:
		# We can't directly add our path because plftool checks first for its
		# existence. So add a fake . entry and rename it.
		logging.debug("Insert %s", dirPath)
		libplf.plftoolExec(["-j", "U_UNIXFILE:0",
				"-b", "U_UNIXFILE=.;mode=040755;uid=0;gid=0",
				"-j", "U_UNIXFILE:0",
				"-p", dirPath,
				plfFilePath])
示例#2
0
def main():
    (options, args) = parseArgs()
    setupLog(options)

    plfFilePath = args[1]

    # Load path map
    pathMap = []
    pathMapFile = open(args[0])
    for line in pathMapFile:
        line = line.rstrip("\n").strip()
        if line and not line.startswith("#"):
            entry = line.split()
            if len(entry) != 2 and len(entry) != 3:
                logging.warning("%s: bad line: %s", args[0], line)
            else:
                pathMap.append(entry)
    pathMapFile.close()

    # Load plf
    plf = libplf.PlfFileInfo()
    plf.load(plfFilePath)

    # Process U_UNIXFILE entries, prepare a batch operation
    batchData = StringIO()
    for section in plf.sections:
        if section.type == "U_UNIXFILE":
            reMappedPath = getReMappedPath(pathMap, section.path).lstrip("/")
            logging.debug("%s -> %s", section.path, reMappedPath)
            batchData.write("'-j U_UNIXFILE:%d -p %s'\n" %
                            (section.idxSection, reMappedPath))
    libplf.plfbatchExec(plfFilePath, "'&'", batchData.getvalue())

    # Add path map roots at the start
    # We create a temp list that we reverse sort (because we will append each
    # item at the start of the plf). This way at the end directories will be
    # created in order
    dirPaths = []
    for entry in pathMap:
        # Only keep non-trivial entries
        if len(entry) >= 3 and entry[2] != "/":
            dirPaths.append(entry[2].lstrip("/"))
    dirPaths.sort(reverse=True)
    for dirPath in dirPaths:
        # We can't directly add our path because plftool checks first for its
        # existence. So add a fake . entry and rename it.
        logging.debug("Insert %s", dirPath)
        libplf.plftoolExec([
            "-j", "U_UNIXFILE:0", "-b", "U_UNIXFILE=.;mode=040755;uid=0;gid=0",
            "-j", "U_UNIXFILE:0", "-p", dirPath, plfFilePath
        ])
示例#3
0
def pushLink(ctx, section):
	# Ask plftool to extract the link so we can read its target
	# We need to provide a temp file name that does not exist...
	tmpFilePath = "/tmp/pushplf%d" % os.getpid()
	libplf.plftoolExec(["-j", "U_UNIXFILE:%d" % section.idxSection,
			"-x", tmpFilePath, ctx.plfFilePath])
	linkTarget = os.readlink(tmpFilePath)
	os.unlink(tmpFilePath)

	print("Link: %s -> %s" % (section.path, linkTarget))

	# Android 'ln' does not support '-f' option
	args = ["shell", "rm", "-f", section.path]
	execAdb(ctx, args)
	args = ["shell", "ln", "-s", linkTarget, section.path]
	execAdb(ctx, args)
示例#4
0
def pushFile(ctx, section):
	print("File: %s" % section.path)

	# Ask plftool to extract the file somewhere
	(tmpFileFd, tmpFilePath) = tempfile.mkstemp()
	libplf.plftoolExec(["-j", "U_UNIXFILE:%d" % section.idxSection,
			"-x", tmpFilePath, ctx.plfFilePath])
	os.close(tmpFileFd)

	# push file and update its mode
	args = ["push", tmpFilePath, section.path]
	execAdb(ctx, args)
	args = ["shell", "chmod", "0%o" % stat.S_IMODE(section.mode), section.path]
	execAdb(ctx, args)
	args = ["shell", "chown", "%d:%d" % (section.gid, section.uid), section.path]
	execAdb(ctx, args)

	# Cleanup
	os.unlink(tmpFilePath)