Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
trivial: Use zif_state_set_steps() setting some guessed values to mak…
Browse files Browse the repository at this point in the history
…e the progress bar more linear
  • Loading branch information
hughsie committed Nov 13, 2010
1 parent 1192b8f commit b2e3181
Show file tree
Hide file tree
Showing 12 changed files with 647 additions and 178 deletions.
26 changes: 24 additions & 2 deletions libzif/zif-md-filelists-sql.c
Expand Up @@ -292,7 +292,22 @@ zif_md_filelists_sql_search_file (ZifMd *md, gchar **search,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);

/* set steps */
zif_state_set_number_steps (state, 1 + !md_filelists_sql->priv->loaded + g_strv_length (search));
if (md_filelists_sql->priv->loaded) {
ret = zif_state_set_steps (state,
error,
50, /* search */
50, /* convert pkgkey */
-1);
} else {
ret = zif_state_set_steps (state,
error,
50, /* load */
25, /* search */
25, /* convert pkgkey */
-1);
}
if (!ret)
goto out;

/* if not already loaded, load */
if (!md_filelists_sql->priv->loaded) {
Expand All @@ -312,6 +327,8 @@ zif_md_filelists_sql_search_file (ZifMd *md, gchar **search,
}

/* search each part of the array */
state_local = zif_state_get_child (state);
zif_state_set_number_steps (state_local, g_strv_length (search));
pkgkey_array = g_ptr_array_new ();
for (j=0; search[j] != NULL; j++) {

Expand Down Expand Up @@ -341,11 +358,16 @@ zif_md_filelists_sql_search_file (ZifMd *md, gchar **search,
}

/* done */
ret = zif_state_done (state, error);
ret = zif_state_done (state_local, error);
if (!ret)
goto out;
}

/* done */
ret = zif_state_done (state, error);
if (!ret)
goto out;

/* convert each pkgKey */
array_tmp = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
for (i=0; i<pkgkey_array->len; i++) {
Expand Down
26 changes: 20 additions & 6 deletions libzif/zif-md-filelists-xml.c
Expand Up @@ -348,10 +348,17 @@ zif_md_filelists_xml_get_files (ZifMd *md, ZifPackage *package,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);

/* setup state */
if (md_filelists->priv->loaded)
if (md_filelists->priv->loaded) {
zif_state_set_number_steps (state, 1);
else
zif_state_set_number_steps (state, 2);
} else {
ret = zif_state_set_steps (state,
error,
80, /* load */
20, /* search */
-1);
if (!ret)
goto out;
}

/* if not already loaded, load */
if (!md_filelists->priv->loaded) {
Expand Down Expand Up @@ -425,10 +432,17 @@ zif_md_filelists_xml_search_file (ZifMd *md, gchar **search,
g_return_val_if_fail (error == NULL || *error == NULL, NULL);

/* setup state */
if (md_filelists->priv->loaded)
if (md_filelists->priv->loaded) {
zif_state_set_number_steps (state, 1);
else
zif_state_set_number_steps (state, 2);
} else {
ret = zif_state_set_steps (state,
error,
80, /* load */
20, /* search */
-1);
if (!ret)
goto out;
}

/* if not already loaded, load */
if (!md_filelists->priv->loaded) {
Expand Down
22 changes: 17 additions & 5 deletions libzif/zif-md-other-sql.c
Expand Up @@ -239,11 +239,23 @@ zif_md_other_sql_get_changelog (ZifMd *md, const gchar *pkgid,

g_return_val_if_fail (zif_state_valid (state), NULL);

/* setup state */
if (md_other_sql->priv->loaded)
zif_state_set_number_steps (state, 2);
else
zif_state_set_number_steps (state, 3);
/* setup steps */
if (md_other_sql->priv->loaded) {
ret = zif_state_set_steps (state,
error,
80, /* sql query */
20, /* search */
-1);
} else {
ret = zif_state_set_steps (state,
error,
60, /* load */
20, /* sql query */
20, /* search */
-1);
}
if (!ret)
goto out;

/* if not already loaded, load */
if (!md_other_sql->priv->loaded) {
Expand Down
22 changes: 17 additions & 5 deletions libzif/zif-md-primary-sql.c
Expand Up @@ -505,11 +505,23 @@ zif_md_primary_sql_what_depends (ZifMd *md, const gchar *table_name, ZifDepend *

g_return_val_if_fail (zif_state_valid (state), NULL);

/* setup state */
if (md_primary_sql->priv->loaded)
zif_state_set_number_steps (state, 2);
else
zif_state_set_number_steps (state, 3);
/* setup steps */
if (md_primary_sql->priv->loaded) {
ret = zif_state_set_steps (state,
error,
80, /* sql query */
20, /* search */
-1);
} else {
ret = zif_state_set_steps (state,
error,
60, /* load */
20, /* sql query */
20, /* search */
-1);
}
if (!ret)
goto out;

/* if not already loaded, load */
if (!md_primary_sql->priv->loaded) {
Expand Down
13 changes: 10 additions & 3 deletions libzif/zif-md-primary-xml.c
Expand Up @@ -501,10 +501,17 @@ zif_md_primary_xml_filter (ZifMd *md, ZifPackageFilterFunc filter_func, gpointer
g_return_val_if_fail (error == NULL || *error == NULL, NULL);

/* setup state */
if (md_primary->priv->loaded)
if (md_primary->priv->loaded) {
zif_state_set_number_steps (state, 1);
else
zif_state_set_number_steps (state, 2);
} else {
ret = zif_state_set_steps (state,
error,
80, /* load */
20, /* search */
-1);
if (!ret)
goto out;
}

/* if not already loaded, load */
if (!md_primary->priv->loaded) {
Expand Down
52 changes: 31 additions & 21 deletions libzif/zif-md.c
Expand Up @@ -449,17 +449,18 @@ zif_md_load (ZifMd *md, ZifState *state, GError **error)
return FALSE;
}

/* set steps:
*
* 1. check uncompressed
* 2. check compressed
* 3. get new compressed
* 3. nothing
* 4. decompress compressed
* 5. check compressed
* 6. klass->load
*/
zif_state_set_number_steps (state, 6);
/* set steps */
ret = zif_state_set_steps (state,
error,
10, /* check uncompressed */
10, /* check compressed */
30, /* get new compressed */
20, /* decompress compressed */
10, /* check compressed */
20, /* klass->load */
-1);
if (!ret)
goto out;

/* optimise: if uncompressed file is okay, then don't even check the compressed file */
state_local = zif_state_get_child (state);
Expand Down Expand Up @@ -514,15 +515,17 @@ zif_md_load (ZifMd *md, ZifState *state, GError **error)
if (!ret)
goto out;

/* set steps:
*
* 1. download new repomd
* 2. load the new repomd
* 3. download new compressed repo file
* 4. check compressed file against new repomd
*/
/* set steps */
state_local = zif_state_get_child (state);
zif_state_set_number_steps (state_local, 4);
ret = zif_state_set_steps (state_local,
error,
30, /* download new repomd */
20, /* load the new repomd */
20, /* download new compressed repo file */
30, /* check compressed file against new repomd */
-1);
if (!ret)
goto out;

/* if not online, then this is fatal */
ret = zif_config_get_boolean (md->priv->config, "network", NULL);
Expand Down Expand Up @@ -1515,12 +1518,19 @@ zif_md_file_check (ZifMd *md, gboolean use_uncompressed, ZifState *state, GError
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

/* setup state */
zif_state_set_number_steps (state, 2);
ret = zif_state_set_steps (state,
error,
20, /* load */
80, /* check checksum */
-1);
if (!ret)
goto out;

/* metalink has no checksum... */
if (md->priv->kind == ZIF_MD_KIND_METALINK ||
md->priv->kind == ZIF_MD_KIND_MIRRORLIST) {
g_debug ("skipping checksum check on %s", zif_md_kind_to_text (md->priv->kind));
g_debug ("skipping checksum check on %s",
zif_md_kind_to_text (md->priv->kind));
ret = zif_state_finished (state, error);
goto out;
}
Expand Down
10 changes: 8 additions & 2 deletions libzif/zif-package-remote.c
Expand Up @@ -288,8 +288,14 @@ zif_package_remote_download (ZifPackageRemote *pkg, const gchar *directory, ZifS
g_return_val_if_fail (zif_state_valid (state), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

/* two steps, TODO: the second will take longer than the first */
zif_state_set_number_steps (state, 2);
/* setup steps */
ret = zif_state_set_steps (state,
error,
5,
95,
-1);
if (!ret)
goto out;

/* directory is optional */
if (directory == NULL) {
Expand Down
68 changes: 48 additions & 20 deletions libzif/zif-release.c
Expand Up @@ -667,10 +667,14 @@ zif_release_get_treeinfo (ZifRelease *release, ZifReleaseUpgradeData *data, ZifS
ZifState *state_local;
ZifReleasePrivate *priv = release->priv;

/* 1. get treeinfo
* 2. parse it
*/
zif_state_set_number_steps (state, 2);
/* set steps */
ret = zif_state_set_steps (state,
error,
90, /* get treeinfo */
10, /* parse it */
-1);
if (!ret)
goto out;

/* get .treeinfo from a mirror in the installmirrorlist */
treeinfo_filename = g_build_filename (priv->cache_dir, ".treeinfo", NULL);
Expand Down Expand Up @@ -1233,22 +1237,46 @@ zif_release_upgrade_version (ZifRelease *release, guint version, ZifReleaseUpgra
}
}

/* 1. setup
* 2. get installmirrorlist
* 3. parse installmirrorlist
* 4. download treeinfo
* 5. download kernel
* 6. download initrd
* (6) download stage2
* (6) download packages
* 7. install kernel
*/
if (upgrade_kind == ZIF_RELEASE_UPGRADE_KIND_MINIMAL)
zif_state_set_number_steps (state, 7);
else if (upgrade_kind == ZIF_RELEASE_UPGRADE_KIND_DEFAULT)
zif_state_set_number_steps (state, 8);
else if (upgrade_kind == ZIF_RELEASE_UPGRADE_KIND_COMPLETE)
zif_state_set_number_steps (state, 9);
/* setup steps */
if (upgrade_kind == ZIF_RELEASE_UPGRADE_KIND_MINIMAL) {
ret = zif_state_set_steps (state,
error,
1, /* setup */
5, /* get installmirrorlist */
1, /* parse installmirrorlist */
3, /* download treeinfo */
15, /* download kernel */
70, /* download initrd */
5, /* install kernel */
-1);
} else if (upgrade_kind == ZIF_RELEASE_UPGRADE_KIND_DEFAULT) {
ret = zif_state_set_steps (state,
error,
1, /* setup */
5, /* get installmirrorlist */
1, /* parse installmirrorlist */
3, /* download treeinfo */
15, /* download kernel */
20, /* download initrd */
50, /* download stage2 */
5, /* install kernel */
-1);
} else if (upgrade_kind == ZIF_RELEASE_UPGRADE_KIND_COMPLETE) {
ret = zif_state_set_steps (state,
error,
1, /* setup */
5, /* get installmirrorlist */
1, /* parse installmirrorlist */
3, /* download treeinfo */
5, /* download kernel */
20, /* download initrd */
30, /* download stage2 */
30, /* download packages */
5, /* install kernel */
-1);
}
if (!ret)
goto out;

/* get the correct object */
state_local = zif_state_get_child (state);
Expand Down

0 comments on commit b2e3181

Please sign in to comment.