#! /bin/sh /usr/share/dpatch/dpatch-run ## 20_escape_filenames.dpatch by Goedson Teixeira Paixao ## ## DP: Espace the '\' and '=' characters in filenames so genisoimage ## DP: won't break when files have these characters in their name @DPATCH@ diff -urNad gnomebaker-0.6.0~/src/dataproject.c gnomebaker-0.6.0/src/dataproject.c --- gnomebaker-0.6.0~/src/dataproject.c 2007-08-27 11:31:02.000000000 -0300 +++ gnomebaker-0.6.0/src/dataproject.c 2007-08-27 11:31:28.000000000 -0300 @@ -1526,6 +1526,43 @@ } +/* + * Escapes file paths adding '\' before any '\' or '=' character + */ +static gchar * +escape_filepath(gchar *path) +{ + GB_LOG_FUNC + g_return_val_if_fail(path != NULL, NULL); + + int count = 0; + gchar *p = path; + gchar *pr = NULL; + gchar *result = NULL; + + while (*p != 0) { + if (*p == '\\' || *p == '=') { + ++count; + } + ++p; + } + + if (count) { + result = g_malloc0(strlen(path) + count + 1); + p = path; + pr = result; + while (*p != 0) { + if (*p == '\\' || *p == '=') { + *pr++ = '\\'; + } + *pr++ = *p++; + } + } else { + result = g_strdup(path); + } + return result; +} + /* Adds to the burning list all the contents recursively. This could be improved checking for depth, * as mkisofs only accepts a max depth o 6 directories */ static void @@ -1557,9 +1594,13 @@ else { gchar *full_path = g_build_filename(file_path, file_name, NULL); - fprintf(tmp_file->file_stream, "%s=%s\n", full_path, path_in_system); + gchar *escaped_full_path = escape_filepath(full_path); + gchar *escaped_path_in_system = escape_filepath(path_in_system); + fprintf(tmp_file->file_stream, "%s=%s\n", escaped_full_path, escaped_path_in_system); GB_TRACE("dataproject_build_paths_file_recursive - [%s]\n", full_path); g_free(full_path); + g_free(escaped_full_path); + g_free(escaped_path_in_system); } g_free(path_in_system);