// package_extract_dir(package_path, destination_path)
Value *
PackageExtractDirFn (const char *name, State * state, int argc, Expr * argv[])
{
  if (argc != 2)
	  {
	    return ErrorAbort (state, "%s() expects 2 args, got %d", name,
			       argc);
	  }
  char *zip_path;
  char *dest_path;

  if (ReadArgs (state, argv, 2, &zip_path, &dest_path) < 0)
    return NULL;

  ZipArchive *za = ((UpdaterInfo *) (state->cookie))->package_zip;

  // To create a consistent system image, never use the clock for timestamps.
  struct utimbuf timestamp = { 1217592000, 1217592000 };	// 8/1/2008 default

  bool success = mzExtractRecursive (za, zip_path, dest_path,
				     MZ_EXTRACT_FILES_ONLY, &timestamp,
				     NULL, NULL);

  free (zip_path);
  free (dest_path);
  return StringValue (strdup (success ? "t" : ""));
}
bool MROMInstaller::extractDir(const std::string& name, const std::string& dest)
{
	ZipArchive zip;

	MemMapping map;
	if (sysMapFile(m_file.c_str(), &map) != 0) {
		LOGERR("Failed to sysMapFile '%s'\n", m_file.c_str());
		return false;
	}

	if (mzOpenZipArchive(map.addr, map.length, &zip) != 0)
	{
		gui_print("Failed to open ZIP file %s\n", m_file.c_str());
		sysReleaseMap(&map);
		return false;
	}

	// To create a consistent system image, never use the clock for timestamps.
    struct utimbuf timestamp = { 1217592000, 1217592000 };  // 8/1/2008 default
	bool success = mzExtractRecursive(&zip, name.c_str(), dest.c_str(), MZ_EXTRACT_FILES_ONLY, &timestamp, NULL, NULL, NULL);

	mzCloseZipArchive(&zip);
	sysReleaseMap(&map);

	if(!success)
	{
		gui_print("Failed to extract dir %s from zip %s\n", name.c_str(), m_file.c_str());
		return false;
	}
	return true;
}
int flash_esp_update(void *data, unsigned sz)
{
	int ret;
	bool success;
	ZipArchive za;

	ret = ensure_esp_mounted();
	if (ret != 0) {
		error("%s: failed to ensure mount %s\n", __func__, ESP_MOUNT_POINT);
		return ret;
	}

	ret = mzOpenZipArchive(data, sz, &za);
	if (ret != 0) {
		error("%s: failed to Open zip archive\n", __func__);
		return ret;
	}

	success = mzExtractRecursive(&za, "", ESP_MOUNT_POINT, 0, NULL, NULL, NULL, NULL);
	if (success != true)  {
		error("%s: failed to Extract zip archive to %s\n", __func__, ESP_MOUNT_POINT);
		return EXIT_FAILURE;
	}

	return 0;
}
Exemple #4
0
static int
handle_or_update(const char *path, ZipArchive *zip)
{
	//first, extract everything
	ui_print("Extracting archive...\n");
	
	char cmd[512];
	
	//ensure the target directory on the sdcard exists and is clean
	sprintf(cmd, "rm -rf %s", OR_UPDATE_EXTRACT_DIR_NAME); 
  run_shell_script(cmd, 0, NULL);
	
	if (mkdir_recursive(OR_UPDATE_EXTRACT_DIR_NAME))
	{
		LOGE("Failed creating: "OR_UPDATE_EXTRACT_DIR_NAME"\n");
		return INSTALL_ERROR;
	}
	
	bool ok = mzExtractRecursive(zip, "", OR_UPDATE_EXTRACT_DIR_NAME, 0, NULL, NULL, NULL);

	if (!ok) 
	{
    LOGE("Failed extracting the archive.\n");
    
    //clear it
    sprintf(cmd, "rm -rf %s", OR_UPDATE_EXTRACT_DIR_NAME); 
    run_shell_script(cmd, 0, NULL);
    return 1;
	}
		
	
	sprintf(cmd, "%s \"%s/%s\" \"%s\"", OR_SCRIPT_UPDATER_NAME, 
			OR_UPDATE_EXTRACT_DIR_NAME, ASSUMED_OR_UPDATE_SCRIPT_NAME, OR_UPDATE_EXTRACT_DIR_NAME);

	run_shell_script(cmd, 1, NULL);
	
	//clear it
	sprintf(cmd, "rm -rf %s", OR_UPDATE_EXTRACT_DIR_NAME); 
  run_shell_script(cmd, 0, NULL);
	return INSTALL_SUCCESS;
}
/* copy_dir <src-dir> <dst-dir> [<timestamp>]
 *
 * The contents of <src-dir> will become the contents of <dst-dir>.
 * The original contents of <dst-dir> are preserved unless something
 * in <src-dir> overwrote them.
 *
 * e.g., for "copy_dir PKG:system SYSTEM:", the file "PKG:system/a"
 * would be copied to "SYSTEM:a".
 *
 * The specified timestamp (in decimal seconds since 1970) will be used,
 * or a fixed default timestamp will be supplied otherwise.
 */
static int
cmd_copy_dir(const char *name, void *cookie, int argc, const char *argv[])
{
    UNUSED(name);
    UNUSED(cookie);
    CHECK_WORDS();

    // To create a consistent system image, never use the clock for timestamps.
    struct utimbuf timestamp = { 1217592000, 1217592000 };  // 8/1/2008 default
    if (argc == 3) {
        char *end;
        time_t value = strtoul(argv[2], &end, 0);
        if (value == 0 || end[0] != '\0') {
            LOGE("Command %s: invalid timestamp \"%s\"\n", name, argv[2]);
            return 1;
        } else if (value < timestamp.modtime) {
            LOGE("Command %s: timestamp \"%s\" too early\n", name, argv[2]);
            return 1;
        }
        timestamp.modtime = timestamp.actime = value;
    } else if (argc != 2) {
        LOGE("Command %s requires exactly two arguments\n", name);
        return 1;
    }

    // Use 40% of the progress bar (80% post-verification) by default
    ui_print("Copying files...\n");
    if (!gDidShowProgress) ui_show_progress(DEFAULT_FILES_PROGRESS_FRACTION, 0);

    /* Mount the destination volume if it isn't already.
     */
    const char *dst_root_path = argv[1];
    int ret = ensure_root_path_mounted(dst_root_path);
    if (ret < 0) {
        LOGE("Can't mount %s\n", dst_root_path);
        return 1;
    }

    /* Get the real target path.
     */
    char dstpathbuf[PATH_MAX];
    const char *dst_path;
    dst_path = translate_root_path(dst_root_path,
            dstpathbuf, sizeof(dstpathbuf));
    if (dst_path == NULL) {
        LOGE("Command %s: bad destination path \"%s\"\n", name, dst_root_path);
        return 1;
    }

    /* Try to copy the directory.  The source may be inside a package.
     */
    const char *src_root_path = argv[0];
    char srcpathbuf[PATH_MAX];
    const char *src_path;
    if (is_package_root_path(src_root_path)) {
        const ZipArchive *package;
        src_path = translate_package_root_path(src_root_path,
                srcpathbuf, sizeof(srcpathbuf), &package);
        if (src_path == NULL) {
            LOGE("Command %s: bad source path \"%s\"\n", name, src_root_path);
            return 1;
        }

        /* Extract the files.  Set MZ_EXTRACT_FILES_ONLY, because only files
         * are validated by the signature.  Do a dry run first to count how
         * many there are (and find some errors early).
         */
        ExtractContext ctx;
        ctx.num_done = 0;
        ctx.num_total = 0;

        if (!mzExtractRecursive(package, src_path, dst_path,
                    MZ_EXTRACT_FILES_ONLY | MZ_EXTRACT_DRY_RUN,
                    &timestamp, extract_count_cb, (void *) &ctx) ||
            !mzExtractRecursive(package, src_path, dst_path,
                    MZ_EXTRACT_FILES_ONLY,
                    &timestamp, extract_cb, (void *) &ctx)) {
            LOGW("Command %s: couldn't extract \"%s\" to \"%s\"\n",
                    name, src_root_path, dst_root_path);
            return 1;
        }
    } else {
        LOGE("Command %s: non-package source path \"%s\" not yet supported\n",
                name, src_root_path);
//xxx mount the src volume
//xxx
        return 255;
    }

    return 0;
}