mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 741810 - Compilation fails because of creating .gnucash
This commit is contained in:
parent
a5d77e4430
commit
69355c0548
@ -299,12 +299,13 @@ gnc_path_find_localized_html_file (const gchar *file_name)
|
|||||||
*
|
*
|
||||||
* @param dirname The path to check
|
* @param dirname The path to check
|
||||||
*/
|
*/
|
||||||
static void
|
static gboolean
|
||||||
gnc_validate_directory (const gchar *dirname)
|
gnc_validate_directory (const gchar *dirname, gchar **msg)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
gint rc;
|
gint rc;
|
||||||
|
|
||||||
|
*msg = NULL;
|
||||||
rc = g_stat (dirname, &statbuf);
|
rc = g_stat (dirname, &statbuf);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
@ -320,70 +321,72 @@ gnc_validate_directory (const gchar *dirname)
|
|||||||
);
|
);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
g_fprintf(stderr,
|
*msg = g_strdup_printf(
|
||||||
_("An error occurred while creating the directory:\n"
|
_("An error occurred while creating the directory:\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
"Please correct the problem and restart GnuCash.\n"
|
"Please correct the problem and restart GnuCash.\n"
|
||||||
"The reported error was '%s' (errno %d).\n"),
|
"The reported error was '%s' (errno %d).\n"),
|
||||||
dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
|
dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
|
||||||
exit(1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
g_stat (dirname, &statbuf);
|
g_stat (dirname, &statbuf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EACCES:
|
case EACCES:
|
||||||
g_fprintf(stderr,
|
*msg = g_strdup_printf(
|
||||||
_("The directory\n"
|
_("The directory\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
"exists but cannot be accessed. This program \n"
|
"exists but cannot be accessed. This program \n"
|
||||||
"must have full access (read/write/execute) to \n"
|
"must have full access (read/write/execute) to \n"
|
||||||
"the directory in order to function properly.\n"),
|
"the directory in order to function properly.\n"),
|
||||||
dirname);
|
dirname);
|
||||||
exit(1);
|
return FALSE;
|
||||||
|
|
||||||
case ENOTDIR:
|
case ENOTDIR:
|
||||||
g_fprintf(stderr,
|
*msg = g_strdup_printf(
|
||||||
_("The path\n"
|
_("The path\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
"exists but it is not a directory. Please delete\n"
|
"exists but it is not a directory. Please delete\n"
|
||||||
"the file and start GnuCash again.\n"),
|
"the file and start GnuCash again.\n"),
|
||||||
dirname);
|
dirname);
|
||||||
exit(1);
|
return FALSE;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
g_fprintf(stderr,
|
*msg = g_strdup_printf(
|
||||||
_("An unknown error occurred when validating that the\n"
|
_("An unknown error occurred when validating that the\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
"directory exists and is usable. Please correct the\n"
|
"directory exists and is usable. Please correct the\n"
|
||||||
"problem and restart GnuCash. The reported error \n"
|
"problem and restart GnuCash. The reported error \n"
|
||||||
"was '%s' (errno %d)."),
|
"was '%s' (errno %d)."),
|
||||||
dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
|
dirname, g_strerror(errno) ? g_strerror(errno) : "", errno);
|
||||||
exit(1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((statbuf.st_mode & S_IFDIR) != S_IFDIR)
|
if ((statbuf.st_mode & S_IFDIR) != S_IFDIR)
|
||||||
{
|
{
|
||||||
g_fprintf(stderr,
|
*msg = g_strdup_printf(
|
||||||
_("The path\n"
|
_("The path\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
"exists but it is not a directory. Please delete\n"
|
"exists but it is not a directory. Please delete\n"
|
||||||
"the file and start GnuCash again.\n"),
|
"the file and start GnuCash again.\n"),
|
||||||
dirname);
|
dirname);
|
||||||
exit(1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
/* The mode argument is ignored on windows anyway */
|
/* The mode argument is ignored on windows anyway */
|
||||||
if ((statbuf.st_mode & S_IRWXU) != S_IRWXU)
|
if ((statbuf.st_mode & S_IRWXU) != S_IRWXU)
|
||||||
{
|
{
|
||||||
g_fprintf(stderr,
|
*msg = g_strdup_printf(
|
||||||
_("The permissions are wrong on the directory\n"
|
_("The permissions are wrong on the directory\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
"They must be at least 'rwx' for the user.\n"),
|
"They must be at least 'rwx' for the user.\n"),
|
||||||
dirname);
|
dirname);
|
||||||
exit(1);
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @fn const gchar * gnc_dotgnucash_dir ()
|
/** @fn const gchar * gnc_dotgnucash_dir ()
|
||||||
@ -399,6 +402,7 @@ gnc_dotgnucash_dir (void)
|
|||||||
{
|
{
|
||||||
static gchar *dotgnucash = NULL;
|
static gchar *dotgnucash = NULL;
|
||||||
gchar *tmp_dir;
|
gchar *tmp_dir;
|
||||||
|
gchar *errmsg = NULL;
|
||||||
|
|
||||||
if (dotgnucash)
|
if (dotgnucash)
|
||||||
return dotgnucash;
|
return dotgnucash;
|
||||||
@ -408,26 +412,31 @@ gnc_dotgnucash_dir (void)
|
|||||||
if (!dotgnucash)
|
if (!dotgnucash)
|
||||||
{
|
{
|
||||||
const gchar *home = g_get_home_dir();
|
const gchar *home = g_get_home_dir();
|
||||||
if (!home)
|
if (!home || !gnc_validate_directory(home, &errmsg))
|
||||||
{
|
{
|
||||||
g_warning("Cannot find home directory. Using tmp directory instead.");
|
g_free(errmsg);
|
||||||
|
g_warning("Cannot find suitable home directory. Using tmp directory instead.");
|
||||||
home = g_get_tmp_dir();
|
home = g_get_tmp_dir();
|
||||||
}
|
}
|
||||||
g_assert(home);
|
g_assert(home);
|
||||||
|
|
||||||
dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
|
dotgnucash = g_build_filename(home, ".gnucash", (gchar *)NULL);
|
||||||
}
|
}
|
||||||
gnc_validate_directory(dotgnucash);
|
if (!gnc_validate_directory(dotgnucash, &errmsg))
|
||||||
|
exit(1);
|
||||||
|
|
||||||
/* Since we're in code that is only executed once.... */
|
/* Since we're in code that is only executed once.... */
|
||||||
tmp_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
|
tmp_dir = g_build_filename(dotgnucash, "books", (gchar *)NULL);
|
||||||
gnc_validate_directory(tmp_dir);
|
if (!gnc_validate_directory(tmp_dir, &errmsg))
|
||||||
|
exit(1);
|
||||||
g_free(tmp_dir);
|
g_free(tmp_dir);
|
||||||
tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
|
tmp_dir = g_build_filename(dotgnucash, "checks", (gchar *)NULL);
|
||||||
gnc_validate_directory(tmp_dir);
|
if (!gnc_validate_directory(tmp_dir, &errmsg))
|
||||||
|
exit(1);
|
||||||
g_free(tmp_dir);
|
g_free(tmp_dir);
|
||||||
tmp_dir = g_build_filename(dotgnucash, "translog", (gchar *)NULL);
|
tmp_dir = g_build_filename(tmp_dir, "translog", (gchar *)NULL);
|
||||||
gnc_validate_directory(tmp_dir);
|
if (!gnc_validate_directory(dotgnucash, &errmsg))
|
||||||
|
exit(1);
|
||||||
g_free(tmp_dir);
|
g_free(tmp_dir);
|
||||||
|
|
||||||
return dotgnucash;
|
return dotgnucash;
|
||||||
|
Loading…
Reference in New Issue
Block a user