|
Packit |
8ea169 |
/*
|
|
Packit |
8ea169 |
Copyright (C) 2012 RedHat inc.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
8ea169 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
8ea169 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
8ea169 |
(at your option) any later version.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
8ea169 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8ea169 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8ea169 |
GNU General Public License for more details.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
You should have received a copy of the GNU General Public License along
|
|
Packit |
8ea169 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
8ea169 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
#if HAVE_LOCALE_H
|
|
Packit |
8ea169 |
# include <locale.h>
|
|
Packit |
8ea169 |
#endif
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
static void try_to_move(const char *old, const char *new)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
/* We don't bother checking whether old exists.
|
|
Packit |
8ea169 |
* Such check would be racy anyway...
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
if (access(new, F_OK) != 0 && (errno == ENOENT || errno == ENOTDIR))
|
|
Packit |
8ea169 |
rename(old, new);
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
void migrate_to_xdg_dirs(void)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
char *old = concat_path_file(g_get_home_dir(), ".abrt/applet_dirlist");
|
|
Packit |
8ea169 |
char *new = concat_path_file(g_get_user_cache_dir(), "abrt/applet_dirlist");
|
|
Packit |
8ea169 |
char *oslash = strrchr(old, '/');
|
|
Packit |
8ea169 |
char *nslash = strrchr(new, '/');
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* we don't check success: it may already exists */
|
|
Packit |
8ea169 |
*nslash = '\0';
|
|
Packit |
8ea169 |
g_mkdir_with_parents(new, 0777);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
*nslash = '/';
|
|
Packit |
8ea169 |
try_to_move(old, new);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
strcpy(oslash + 1, "spool");
|
|
Packit |
8ea169 |
strcpy(nslash + 1, "spool");
|
|
Packit |
8ea169 |
try_to_move(old, new);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
strcpy(oslash + 1, "settings");
|
|
Packit |
8ea169 |
free(new);
|
|
Packit |
8ea169 |
new = concat_path_file(g_get_user_config_dir(), "abrt/settings");
|
|
Packit |
8ea169 |
nslash = strrchr(new, '/');
|
|
Packit |
8ea169 |
*nslash = '\0';
|
|
Packit |
8ea169 |
g_mkdir_with_parents(new, 0777);
|
|
Packit |
8ea169 |
*nslash = '/';
|
|
Packit |
8ea169 |
try_to_move(old, new);
|
|
Packit |
8ea169 |
free(new);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* Delete $HOME/.abrt if it is empty */
|
|
Packit |
8ea169 |
*oslash = '\0';
|
|
Packit |
8ea169 |
rmdir(old);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
free(old);
|
|
Packit |
8ea169 |
}
|