1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2024-12-17 10:50:12 +01:00

changed some variable types from gchar buf[SMALL] to GString *buf.

A bug causes bygfoot to crash in file_compress_files. 

Bug message:
In file.c/file_compress_files, we used gchar buf[SMALL];
SMALL is defined to 10000. after a lot of seasons (19 within the test),
the number of files grows too big.
This commit is contained in:
mrsmola 2007-03-12 20:24:09 +00:00
parent 7d38072a4a
commit f633ade130
2 changed files with 28 additions and 21 deletions

View File

@ -121,11 +121,11 @@ file_find_support_file (const gchar *filename, gboolea
/** Execute command with 'system' and give a warning if return value is -1. /** Execute command with 'system' and give a warning if return value is -1.
@return TRUE on success, FALSE, otherwise. */ @return TRUE on success, FALSE, otherwise. */
gboolean gboolean
file_my_system(const gchar *command) file_my_system(const GString *command)
{ {
if(system(command) != 0) if(system(command->str) != 0)
{ {
g_warning("file_my_system: system returned -1 when executing '%s'.", command); g_warning("file_my_system: system returned -1 when executing '%s'.", command->str);
if(!os_is_unix) if(!os_is_unix)
{ {
@ -660,7 +660,7 @@ void
file_compress_files(const gchar *destfile, const gchar *prefix) file_compress_files(const gchar *destfile, const gchar *prefix)
{ {
gint i; gint i;
gchar buf[SMALL]; GString *buf = g_string_new("");
gchar *basename = g_path_get_basename(prefix), gchar *basename = g_path_get_basename(prefix),
*dirname = g_path_get_dirname(prefix), *dirname = g_path_get_dirname(prefix),
*zipbasename = g_path_get_basename(destfile), *zipbasename = g_path_get_basename(destfile),
@ -670,29 +670,30 @@ file_compress_files(const gchar *destfile, const gchar *prefix)
chdir(dirname); chdir(dirname);
if (os_is_unix) if (os_is_unix)
sprintf(buf, "%s %s %s", g_string_sprintf(buf, "%s %s %s",
const_str("string_fs_compress_command"), const_str("string_fs_compress_command"),
const_str("string_fs_compress_switches"), const_str("string_fs_compress_switches"),
zipbasename); zipbasename);
else else
sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S, g_string_sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S,
const_str("string_fs_compress_command"), const_str("string_fs_compress_command"),
const_str("string_fs_compress_switches"), const_str("string_fs_compress_switches"),
zipbasename); zipbasename);
for(i=0;i<files->len;i++) for(i=0;i<files->len;i++)
{ {
strcat(buf, " "); g_string_append(buf, " ");
strcat(buf, (gchar*)g_ptr_array_index(files, i)); g_string_append(buf, (gchar*)g_ptr_array_index(files, i));
} }
file_my_system(buf); file_my_system(buf);
chdir(pwd); chdir(pwd);
sprintf(buf, "%s%s%s*", dirname, G_DIR_SEPARATOR_S, basename); g_string_sprintf(buf, "%s%s%s*", dirname, G_DIR_SEPARATOR_S, basename);
file_remove_files(buf); file_remove_files(buf);
g_string_free(buf, TRUE);
free_gchar_array(&files); free_gchar_array(&files);
g_free(basename); g_free(basename);
@ -705,7 +706,7 @@ file_compress_files(const gchar *destfile, const gchar *prefix)
void void
file_decompress(const gchar *filename) file_decompress(const gchar *filename)
{ {
gchar buf[SMALL]; GString *buf = g_string_new("");
gchar *dirname = g_path_get_dirname(filename), gchar *dirname = g_path_get_dirname(filename),
*basename = g_path_get_basename(filename), *basename = g_path_get_basename(filename),
*pwd = g_get_current_dir(); *pwd = g_get_current_dir();
@ -713,18 +714,20 @@ file_decompress(const gchar *filename)
chdir(dirname); chdir(dirname);
if (os_is_unix) if (os_is_unix)
sprintf(buf, "%s %s %s", g_string_sprintf(buf, "%s %s %s",
const_str("string_fs_uncompress_command"), const_str("string_fs_uncompress_command"),
const_str("string_fs_uncompress_switches"), const_str("string_fs_uncompress_switches"),
basename); basename);
else else
sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S, g_string_sprintf(buf, "\"%s%s%s\" %s %s", pwd, G_DIR_SEPARATOR_S,
const_str("string_fs_uncompress_command"), const_str("string_fs_uncompress_command"),
const_str("string_fs_uncompress_switches"), const_str("string_fs_uncompress_switches"),
basename); basename);
file_my_system(buf); file_my_system(buf);
g_string_free(buf, TRUE);
g_free(dirname); g_free(dirname);
g_free(basename); g_free(basename);
@ -735,32 +738,36 @@ file_decompress(const gchar *filename)
/** Execute the appropriate remove command with 'files' /** Execute the appropriate remove command with 'files'
as argument (can be directories or a regexp, too). */ as argument (can be directories or a regexp, too). */
void void
file_remove_files(const gchar *files) file_remove_files(const GString *files)
{ {
gchar buf[SMALL]; GString *buf = g_string_new("");
if(os_is_unix) if(os_is_unix)
sprintf(buf, "%s %s", const_str("string_fs_remove_file_command"), files); g_string_sprintf(buf, "%s %s", const_str("string_fs_remove_file_command"), files->str);
else else
sprintf(buf, "%s \"%s\"", const_str("string_fs_remove_file_command"), files); g_string_sprintf(buf, "%s \"%s\"", const_str("string_fs_remove_file_command"), files->str);
file_my_system(buf); file_my_system(buf);
g_string_free(buf, TRUE);
} }
/** Execute the appropriate copy command. */ /** Execute the appropriate copy command. */
void void
file_copy_file(const gchar *source_file, const gchar *dest_file) file_copy_file(const gchar *source_file, const gchar *dest_file)
{ {
gchar buf[SMALL]; GString *buf = g_string_new("");
if(os_is_unix) if(os_is_unix)
sprintf(buf, "%s %s %s", const_str("string_fs_copy_file_command"), g_string_sprintf(buf, "%s %s %s", const_str("string_fs_copy_file_command"),
source_file, dest_file); source_file, dest_file);
else else
sprintf(buf, "%s \"%s\" \"%s\"", const_str("string_fs_copy_file_command"), g_string_sprintf(buf, "%s \"%s\" \"%s\"", const_str("string_fs_copy_file_command"),
source_file, dest_file); source_file, dest_file);
file_my_system(buf); file_my_system(buf);
g_string_free(buf, TRUE);
} }
/** Find out where the Bygfoot directory we can write to resides /** Find out where the Bygfoot directory we can write to resides

View File

@ -83,7 +83,7 @@ void
file_check_home_dir_copy_files(GPtrArray **files_to_copy); file_check_home_dir_copy_files(GPtrArray **files_to_copy);
gboolean gboolean
file_my_system(const gchar *command); file_my_system(const GString *command);
const gchar* const gchar*
file_get_first_support_dir(void); file_get_first_support_dir(void);
@ -98,7 +98,7 @@ void
file_decompress(const gchar *filename); file_decompress(const gchar *filename);
void void
file_remove_files(const gchar *files); file_remove_files(const GString *files);
void void
file_copy_file(const gchar *source_file, const gchar *dest_file); file_copy_file(const gchar *source_file, const gchar *dest_file);