core: Use global random object
We were pointlessly creating a new rand (and thus opening /dev/random) on every temp file creation, but still using the global rand.
This commit is contained in:
parent
0018b6d75f
commit
9bcd4ff8aa
|
|
@ -822,8 +822,7 @@ create_tmp_string (const char *dirpath,
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
subst_xxxxxx (GRand *rand,
|
subst_xxxxxx (const char *string)
|
||||||
const char *string)
|
|
||||||
{
|
{
|
||||||
static const char table[] = "ABCEDEFGHIJKLMNOPQRSTUVWXYZabcedefghijklmnopqrstuvwxyz0123456789";
|
static const char table[] = "ABCEDEFGHIJKLMNOPQRSTUVWXYZabcedefghijklmnopqrstuvwxyz0123456789";
|
||||||
char *ret = g_strdup (string);
|
char *ret = g_strdup (string);
|
||||||
|
|
@ -856,15 +855,12 @@ ostree_create_temp_file_from_input (GFile *dir,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GChecksum *ret_checksum = NULL;
|
GChecksum *ret_checksum = NULL;
|
||||||
GRand *rand = NULL;
|
|
||||||
GString *tmp_name = NULL;
|
GString *tmp_name = NULL;
|
||||||
char *possible_name = NULL;
|
char *possible_name = NULL;
|
||||||
GFile *possible_file = NULL;
|
GFile *possible_file = NULL;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
rand = g_rand_new ();
|
|
||||||
|
|
||||||
tmp_name = create_tmp_string (ot_gfile_get_path_cached (dir),
|
tmp_name = create_tmp_string (ot_gfile_get_path_cached (dir),
|
||||||
prefix, suffix);
|
prefix, suffix);
|
||||||
|
|
||||||
|
|
@ -872,7 +868,7 @@ ostree_create_temp_file_from_input (GFile *dir,
|
||||||
for (i = 0; i < 128; i++)
|
for (i = 0; i < 128; i++)
|
||||||
{
|
{
|
||||||
g_free (possible_name);
|
g_free (possible_name);
|
||||||
possible_name = subst_xxxxxx (rand, tmp_name->str);
|
possible_name = subst_xxxxxx (tmp_name->str);
|
||||||
g_clear_object (&possible_file);
|
g_clear_object (&possible_file);
|
||||||
possible_file = ot_gfile_new_for_path (possible_name);
|
possible_file = ot_gfile_new_for_path (possible_name);
|
||||||
|
|
||||||
|
|
@ -908,8 +904,6 @@ ostree_create_temp_file_from_input (GFile *dir,
|
||||||
ot_transfer_out_value(out_checksum, &ret_checksum);
|
ot_transfer_out_value(out_checksum, &ret_checksum);
|
||||||
ot_transfer_out_value(out_file, &possible_file);
|
ot_transfer_out_value(out_file, &possible_file);
|
||||||
out:
|
out:
|
||||||
if (rand)
|
|
||||||
g_rand_free (rand);
|
|
||||||
if (tmp_name)
|
if (tmp_name)
|
||||||
g_string_free (tmp_name, TRUE);
|
g_string_free (tmp_name, TRUE);
|
||||||
g_free (possible_name);
|
g_free (possible_name);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue