~veger/ubuntu/precise/mc/fix-for-905610-v2

« back to all changes in this revision

Viewing changes to lib/mcconfig/paths.c

  • Committer: Maarten Bezemer
  • Date: 2012-03-10 15:19:01 UTC
  • mfrom: (4.2.12 sid)
  • Revision ID: maarten.bezemer@gmail.com-20120310151901-9t8ykl229qc02qqc
* New upstream release (LP: #905610, LP: #314614, LP: #410031, 
    LP: #562361, LP: #632816, LP: #713630, LP: #770673, LP: #837163)
* Added Pre-Depends for dpkg-maintscript-helper availability
* Build-Depends are updated: 'bison' moved to build-deps;
  architecture wildcard replaced silly "type-handling | not+linux-gnu"
  (Closes: #587875 N:"Please remove type-handling dependency")
* new patch to increase maximum file size for mcedit to 128 MiB
  (Closes: #369565 W:"mcedit: wishing a bigger file size limit")
  Thanks to Daniele Giacomini.
* new patch to disable "Return does autoindent" by default in mcedit
  (Closes: #570502 N:"mcedit: adding extra spaces when pasting a text
   preceded by spaces")
  (Closes: #575711 N:"pasting extra tabs, AGAIN")
* added mc.NEWS file with notes about important changes in this release
  (Closes: #661435 W:"lynx-like motion is lost during upgrade to 4.8.1")
* added symlinks to all scripts in /usr/lib/mc for backward compatibility
* new patch to correct path to scripts in man page
  (Closes: #661481 N:"Acknowledgement mc: /usr/share/mc/bin/mc.sh missing")
* 'unzip' added to build-deps to set proper zip mode at build-time;
  'unzip' moved to Recommends from Suggests.
  (Closes: #661467 N:"mc: zip file browsing broken")
* Recommends 'perl' and 'unzip' instead of Suggests
* dropped old 20_wrong_path_to_wrappers.patch, which was breaking
  correct path to wrappers (note the precisely chosen file name ;)
* corrected and properly annotated 09_uzip_broken_528239.patch
* New upstream release [December 2011]
  (Closes: #618542 N:"please follow upstream progress")
  (Closes: #528331 N:"[VFS] utar is unable to open .tar files")
  (Closes: #626287 N:"SHIFT+F6 should open rename dialog")
  (Closes: #609489 I:"If <F4> is pressed ~/.mc/cedit/Syntax is missing")
  (Closes: #606331 I:"regression: panel configuration on startup;
   view search configuration")
  (Closes: #567119 I:"mcedit ignores editnormal in MC_COLOR_TABLE")
  (Closes: #587372 N:"fish does not preserve modification time when
   copying files to remote host")
  (Closes: #592396 N:"file rename (F6) with non-usual characters failed")
  (Closes: #525146 N:"mc hangs when copying multiple files from ftp")
  (Closes: #574761 N:" [VFS] internal tar considers files containig
   '@' as directories.")
  (Closes: #584687 N:"mc/fish segfaults when remote copy/move appends
   to existing file")
  (Closes: #619092 W:"Wishlist: mc to open ISO files")
  (Closes: #602857 M:"use 7zr for generic .7z archives if available")
  (Closes: #61987 W:"total ETA wanted")
* debian/watch
  • fixed and updated to fetch latest .tar.xz
* dropped CDBS, now using debhelper only
* debhelper & compat to version 9
* dh-autoreconf to update toolchain
* intltoolize to refresh Makefile.in.in
* debian/control
  • standards to 3.9.3 (thanks to Andreas Tille)
  • added to build-deps:
    + 'type-handling' as alternative to 'libgpm-dev'
    + 'libpam0g-dev' optional, used by build system
    + 'check' to enable post-build unit tests
    + 'autopoint' (used by autoreconf)
  • 'bison' added to Build-Depends-Indep
     if available, it is used by upstream build system
     to regenerate some files
  • added myself to Uploaders
* debian/copyright:
  • updated and converted to DEP-5
  • added copyrights of debian contributors
  • audit of upstream licenses/copyrights - all information is included
* configure options
  + --disable-static
  + --enable-tests
  - --without-samba (obsolete)
* patchworks:
  • relocated to debian/patches from subdir
  • new patches:
    + new man_spelling.patch (lintianisation)
    + new ext_libreoffice.patch to replace 'ooffice' command
      with 'libreoffice' - thanks to Osamu Aoki
      (Closes: #641926 N:"mc.ext updates (xz, libreoffice)")
    + new ext_cpio-xz.patch to improve .xz support,
      (thanks to Osamu Aoki)
  • updated:
    * 04_add_gem_extension.patch
    * 05_disable_internal_editor.patch
    * 08_use_sensible-editor.patch
    * 99_detect_alt_editor.patch
  • disabled, to drop later:
    * 09_uzip_broken_528239.patch
  • dropped (obsolete)
    - 03_use_awk.patch
    - pending/99_enable_reading_debs.patch (applied upstream)
    - debian/patches/README
* updated lintian overrides
  + added lintian-overrides for executable-not-elf-or-script
    for files in /usr/lib/mc/fish
* install correct ChangeLog
* install scripts to /usr/lib/mc
  (previously was installed to /usr/share/mc)
* added symlink to missing mcdiff.1 man page
* added symlink to relocated mc-wrapper.sh for backward compatibility
* dropped man page for mcmfmt (binary is no longer shipped by upstream)
* handle configuration files upgrades/removes with
  dpkg-maintscript-helper in preinst/postinst/postrm
* architecture-independent files are separated to 'mc-data' package
  + added upgrade path with Breaks/Replaces
  + added symbolic links to link files from /usr/share/doc/mc-data/
    to /usr/share/doc/mc/
* removed 'exit 0' from preinst/postinst/prerm/postrm files
* VCS links updated to point at new collab-maint repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   paths to configuration files
 
3
 
 
4
   Copyright (C) 2010, 2011
 
5
   The Free Software Foundation, Inc.
 
6
 
 
7
   Written by:
 
8
   Slava Zanko <slavazanko@gmail.com>, 2010.
 
9
 
 
10
   This file is part of the Midnight Commander.
 
11
 
 
12
   The Midnight Commander is free software: you can redistribute it
 
13
   and/or modify it under the terms of the GNU General Public License as
 
14
   published by the Free Software Foundation, either version 3 of the License,
 
15
   or (at your option) any later version.
 
16
 
 
17
   The Midnight Commander is distributed in the hope that it will be useful,
 
18
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
   GNU General Public License for more details.
 
21
 
 
22
   You should have received a copy of the GNU General Public License
 
23
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
 */
 
25
 
 
26
#include <config.h>
 
27
 
 
28
#include <stdio.h>
 
29
#include <stdlib.h>
 
30
#include <errno.h>
 
31
 
 
32
#include "lib/global.h"
 
33
#include "lib/fileloc.h"
 
34
#include "lib/vfs/vfs.h"
 
35
#include "lib/util.h"           /* unix_error_string() */
 
36
 
 
37
#include "lib/mcconfig.h"
 
38
 
 
39
/*** global variables ****************************************************************************/
 
40
 
 
41
/*** file scope macro definitions ****************************************************************/
 
42
 
 
43
#define MC_OLD_USERCONF_DIR ".mc"
 
44
 
 
45
/*** file scope type declarations ****************************************************************/
 
46
 
 
47
/*** file scope variables ************************************************************************/
 
48
 
 
49
static gboolean xdg_vars_initialized = FALSE;
 
50
static char *mc_config_str = NULL;
 
51
static char *mc_cache_str = NULL;
 
52
static char *mc_data_str = NULL;
 
53
 
 
54
static const char *homedir = NULL;
 
55
 
 
56
static gboolean config_dir_present = FALSE;
 
57
 
 
58
static const struct
 
59
{
 
60
    const char *old_filename;
 
61
 
 
62
    char **new_basedir;
 
63
    const char *new_filename;
 
64
} mc_config_files_reference[] =
 
65
{
 
66
    /* *INDENT-OFF* */
 
67
    /* config */
 
68
    { "ini",                                   &mc_config_str, MC_CONFIG_FILE},
 
69
    { "filehighlight.ini",                     &mc_config_str, MC_FHL_INI_FILE},
 
70
    { "hotlist",                               &mc_config_str, MC_HOTLIST_FILE},
 
71
    { "mc.keymap",                             &mc_config_str, GLOBAL_KEYMAP_FILE},
 
72
    { "menu",                                  &mc_config_str, MC_USERMENU_FILE},
 
73
    { "cedit" PATH_SEP_STR "Syntax",           &mc_config_str, EDIT_SYNTAX_FILE},
 
74
    { "cedit" PATH_SEP_STR "menu",             &mc_config_str, EDIT_HOME_MENU},
 
75
    { "cedit" PATH_SEP_STR "edit.indent.rc",   &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.indent.rc"},
 
76
    { "cedit" PATH_SEP_STR "edit.spell.rc",    &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.spell.rc"},
 
77
    { "panels.ini",                            &mc_config_str, MC_PANELS_FILE},
 
78
 
 
79
    /* User should move this file with applying some changes in file */
 
80
    { "",                                      &mc_config_str, MC_FILEBIND_FILE},
 
81
 
 
82
    /* data */
 
83
    { "skins",                                 &mc_data_str, MC_SKINS_SUBDIR},
 
84
    { "fish",                                  &mc_data_str, FISH_PREFIX},
 
85
    { "bashrc",                                &mc_data_str, "bashrc"},
 
86
    { "inputrc",                               &mc_data_str, "inputrc"},
 
87
    { "extfs.d",                               &mc_data_str, MC_EXTFS_DIR},
 
88
    { "history",                               &mc_data_str, MC_HISTORY_FILE},
 
89
    { "filepos",                               &mc_data_str, MC_FILEPOS_FILE},
 
90
    { "cedit" PATH_SEP_STR "cooledit.clip",    &mc_data_str, EDIT_CLIP_FILE},
 
91
    { "",                                      &mc_data_str, MC_MACRO_FILE},
 
92
 
 
93
    /* cache */
 
94
    { "log",                                   &mc_cache_str, "mc.log"},
 
95
    { "Tree",                                  &mc_cache_str, MC_TREESTORE_FILE},
 
96
    { "cedit" PATH_SEP_STR "cooledit.temp",    &mc_cache_str, EDIT_TEMP_FILE},
 
97
    { "cedit" PATH_SEP_STR "cooledit.block",   &mc_cache_str, EDIT_BLOCK_FILE},
 
98
 
 
99
    {NULL, NULL, NULL}
 
100
    /* *INDENT-ON* */
 
101
};
 
102
 
 
103
#ifdef MC_HOMEDIR_XDG
 
104
static const struct
 
105
{
 
106
    char **old_basedir;
 
107
    const char *filename;
 
108
 
 
109
    char **new_basedir;
 
110
} mc_config_migrate_rules_fix[] =
 
111
{
 
112
    /* *INDENT-OFF* */
 
113
    { &mc_data_str, MC_USERMENU_FILE,                       &mc_config_str},
 
114
    { &mc_data_str, EDIT_SYNTAX_FILE,                       &mc_config_str},
 
115
    { &mc_data_str, EDIT_HOME_MENU,                         &mc_config_str},
 
116
    { &mc_data_str, EDIT_DIR PATH_SEP_STR "edit.indent.rc", &mc_config_str},
 
117
    { &mc_data_str, EDIT_DIR PATH_SEP_STR "edit.spell.rc",  &mc_config_str},
 
118
    { &mc_data_str, MC_FILEBIND_FILE,                       &mc_config_str},
 
119
 
 
120
    { &mc_cache_str, MC_HISTORY_FILE,                       &mc_data_str},
 
121
    { &mc_cache_str, MC_FILEPOS_FILE,                       &mc_data_str},
 
122
    { &mc_cache_str, EDIT_CLIP_FILE,                        &mc_data_str},
 
123
 
 
124
    { &mc_cache_str, MC_PANELS_FILE,                        &mc_config_str},
 
125
 
 
126
    {NULL, NULL, NULL}
 
127
    /* *INDENT-ON* */
 
128
};
 
129
#endif /* MC_HOMEDIR_XDG */
 
130
 
 
131
/*** file scope functions *********************************************************************** */
 
132
/* --------------------------------------------------------------------------------------------- */
 
133
 
 
134
static void
 
135
mc_config_mkdir (const char *directory_name, GError ** error)
 
136
{
 
137
    if ((!g_file_test (directory_name, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) &&
 
138
        (g_mkdir_with_parents (directory_name, 0700) != 0))
 
139
    {
 
140
        g_propagate_error (error,
 
141
                           g_error_new (MC_ERROR, 0, _("Cannot create %s directory"),
 
142
                                        directory_name));
 
143
    }
 
144
}
 
145
 
 
146
/* --------------------------------------------------------------------------------------------- */
 
147
 
 
148
static char *
 
149
mc_config_init_one_config_path (const char *path_base, const char *subdir, GError ** error)
 
150
{
 
151
    char *full_path;
 
152
 
 
153
    full_path = g_build_filename (path_base, subdir, NULL);
 
154
 
 
155
    if (g_file_test (full_path, G_FILE_TEST_EXISTS))
 
156
    {
 
157
        if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
 
158
        {
 
159
            config_dir_present = TRUE;
 
160
        }
 
161
        else
 
162
        {
 
163
            fprintf (stderr, "%s %s\n", _("FATAL: not a directory:"), full_path);
 
164
            exit (EXIT_FAILURE);
 
165
        }
 
166
    }
 
167
 
 
168
    mc_config_mkdir (full_path, error);
 
169
    if (error != NULL && *error != NULL)
 
170
    {
 
171
        g_free (full_path);
 
172
        full_path = NULL;
 
173
    }
 
174
    return full_path;
 
175
}
 
176
 
 
177
/* --------------------------------------------------------------------------------------------- */
 
178
 
 
179
static char *
 
180
mc_config_get_deprecated_path (void)
 
181
{
 
182
    return g_build_filename (mc_config_get_home_dir (), MC_OLD_USERCONF_DIR, NULL);
 
183
}
 
184
 
 
185
/* --------------------------------------------------------------------------------------------- */
 
186
 
 
187
static void
 
188
mc_config_copy (const char *old_name, const char *new_name, GError ** error)
 
189
{
 
190
    if (g_file_test (old_name, G_FILE_TEST_IS_REGULAR))
 
191
    {
 
192
        char *contents = NULL;
 
193
        size_t length;
 
194
 
 
195
        if (g_file_get_contents (old_name, &contents, &length, error))
 
196
            g_file_set_contents (new_name, contents, length, error);
 
197
 
 
198
        g_free (contents);
 
199
        return;
 
200
    }
 
201
 
 
202
    if (g_file_test (old_name, G_FILE_TEST_IS_DIR))
 
203
    {
 
204
 
 
205
        GDir *dir;
 
206
        const char *dir_name;
 
207
 
 
208
        dir = g_dir_open (old_name, 0, error);
 
209
        if (dir == NULL)
 
210
            return;
 
211
 
 
212
        if (g_mkdir_with_parents (new_name, 0700) == -1)
 
213
        {
 
214
            g_dir_close (dir);
 
215
            g_propagate_error (error,
 
216
                               g_error_new (MC_ERROR, 0,
 
217
                                            _
 
218
                                            ("An error occured while migrating user settings: %s"),
 
219
                                            unix_error_string (errno)));
 
220
            return;
 
221
        }
 
222
 
 
223
        while ((dir_name = g_dir_read_name (dir)) != NULL)
 
224
        {
 
225
            char *old_name2, *new_name2;
 
226
 
 
227
            old_name2 = g_build_filename (old_name, dir_name, NULL);
 
228
            new_name2 = g_build_filename (new_name, dir_name, NULL);
 
229
            mc_config_copy (old_name2, new_name2, error);
 
230
            g_free (new_name2);
 
231
            g_free (old_name2);
 
232
        }
 
233
    }
 
234
}
 
235
 
 
236
/* --------------------------------------------------------------------------------------------- */
 
237
 
 
238
#if MC_HOMEDIR_XDG
 
239
static void
 
240
mc_config_fix_migrated_rules (void)
 
241
{
 
242
    size_t rule_index;
 
243
 
 
244
    for (rule_index = 0; mc_config_migrate_rules_fix[rule_index].old_basedir != NULL; rule_index++)
 
245
    {
 
246
        char *old_name;
 
247
 
 
248
        old_name =
 
249
            g_build_filename (*mc_config_migrate_rules_fix[rule_index].old_basedir,
 
250
                              mc_config_migrate_rules_fix[rule_index].filename, NULL);
 
251
 
 
252
        if (g_file_test (old_name, G_FILE_TEST_EXISTS))
 
253
        {
 
254
            char *new_name;
 
255
            const char *basedir = *mc_config_migrate_rules_fix[rule_index].new_basedir;
 
256
            const char *filename = mc_config_migrate_rules_fix[rule_index].filename;
 
257
 
 
258
            new_name = g_build_filename (basedir, filename, NULL);
 
259
            rename (old_name, new_name);
 
260
            g_free (new_name);
 
261
        }
 
262
        g_free (old_name);
 
263
    }
 
264
}
 
265
#endif /* MC_HOMEDIR_XDG */
 
266
 
 
267
/* --------------------------------------------------------------------------------------------- */
 
268
/*** public functions ****************************************************************************/
 
269
/* --------------------------------------------------------------------------------------------- */
 
270
 
 
271
void
 
272
mc_config_init_config_paths (GError ** error)
 
273
{
 
274
    const char *mc_datadir;
 
275
 
 
276
#ifdef MC_HOMEDIR_XDG
 
277
    char *u_config_dir = (char *) g_get_user_config_dir ();
 
278
    char *u_data_dir = (char *) g_get_user_data_dir ();
 
279
    char *u_cache_dir = (char *) g_get_user_cache_dir ();
 
280
 
 
281
    if (xdg_vars_initialized)
 
282
        return;
 
283
 
 
284
    u_config_dir = (u_config_dir == NULL)
 
285
        ? g_build_filename (mc_config_get_home_dir (), ".config", NULL) : g_strdup (u_config_dir);
 
286
 
 
287
    u_cache_dir = (u_cache_dir == NULL)
 
288
        ? g_build_filename (mc_config_get_home_dir (), ".cache", NULL) : g_strdup (u_cache_dir);
 
289
 
 
290
    u_data_dir = (u_data_dir == NULL)
 
291
        ? g_build_filename (mc_config_get_home_dir (), ".local", "share", NULL)
 
292
        : g_strdup (u_data_dir);
 
293
 
 
294
    mc_config_str = mc_config_init_one_config_path (u_config_dir, MC_USERCONF_DIR, error);
 
295
    mc_cache_str = mc_config_init_one_config_path (u_cache_dir, MC_USERCONF_DIR, error);
 
296
    mc_data_str = mc_config_init_one_config_path (u_data_dir, MC_USERCONF_DIR, error);
 
297
 
 
298
    g_free (u_data_dir);
 
299
    g_free (u_cache_dir);
 
300
    g_free (u_config_dir);
 
301
 
 
302
    mc_config_fix_migrated_rules ();
 
303
#else /* MC_HOMEDIR_XDG */
 
304
    char *defined_userconf_dir;
 
305
    char *u_config_dir;
 
306
 
 
307
    defined_userconf_dir = tilde_expand (MC_USERCONF_DIR);
 
308
    if (!g_path_is_absolute (defined_userconf_dir))
 
309
    {
 
310
        u_config_dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, NULL);
 
311
        g_free (defined_userconf_dir);
 
312
    }
 
313
    else
 
314
        u_config_dir = defined_userconf_dir;
 
315
 
 
316
    mc_data_str = mc_cache_str = mc_config_str =
 
317
        mc_config_init_one_config_path (u_config_dir, "", error);
 
318
 
 
319
    g_free (u_config_dir);
 
320
#endif /* MC_HOMEDIR_XDG */
 
321
 
 
322
    /* This is the directory, where MC was installed, on Unix this is DATADIR */
 
323
    /* and can be overriden by the MC_DATADIR environment variable */
 
324
    mc_datadir = g_getenv ("MC_DATADIR");
 
325
    if (mc_datadir != NULL)
 
326
        mc_global.sysconfig_dir = g_strdup (mc_datadir);
 
327
    else
 
328
        mc_global.sysconfig_dir = g_strdup (SYSCONFDIR);
 
329
 
 
330
    mc_global.share_data_dir = g_strdup (DATADIR);
 
331
 
 
332
    xdg_vars_initialized = TRUE;
 
333
}
 
334
 
 
335
/* --------------------------------------------------------------------------------------------- */
 
336
 
 
337
void
 
338
mc_config_deinit_config_paths (void)
 
339
{
 
340
    if (!xdg_vars_initialized)
 
341
        return;
 
342
 
 
343
    g_free (mc_config_str);
 
344
#ifdef MC_HOMEDIR_XDG
 
345
    g_free (mc_cache_str);
 
346
    g_free (mc_data_str);
 
347
#endif /* MC_HOMEDIR_XDG */
 
348
 
 
349
    g_free (mc_global.share_data_dir);
 
350
    g_free (mc_global.sysconfig_dir);
 
351
 
 
352
    xdg_vars_initialized = FALSE;
 
353
}
 
354
 
 
355
/* --------------------------------------------------------------------------------------------- */
 
356
 
 
357
const char *
 
358
mc_config_get_data_path (void)
 
359
{
 
360
    if (!xdg_vars_initialized)
 
361
        mc_config_init_config_paths (NULL);
 
362
 
 
363
    return (const char *) mc_data_str;
 
364
}
 
365
 
 
366
/* --------------------------------------------------------------------------------------------- */
 
367
 
 
368
const char *
 
369
mc_config_get_cache_path (void)
 
370
{
 
371
    if (!xdg_vars_initialized)
 
372
        mc_config_init_config_paths (NULL);
 
373
 
 
374
    return (const char *) mc_cache_str;
 
375
}
 
376
 
 
377
/* --------------------------------------------------------------------------------------------- */
 
378
 
 
379
const char *
 
380
mc_config_get_home_dir (void)
 
381
{
 
382
    if (homedir == NULL)
 
383
    {
 
384
        homedir = g_getenv ("HOME");
 
385
        if (homedir == NULL)
 
386
            homedir = g_get_home_dir ();
 
387
    }
 
388
    return homedir;
 
389
}
 
390
 
 
391
/* --------------------------------------------------------------------------------------------- */
 
392
 
 
393
const char *
 
394
mc_config_get_path (void)
 
395
{
 
396
    if (!xdg_vars_initialized)
 
397
        mc_config_init_config_paths (NULL);
 
398
 
 
399
    return (const char *) mc_config_str;
 
400
}
 
401
 
 
402
/* --------------------------------------------------------------------------------------------- */
 
403
 
 
404
void
 
405
mc_config_migrate_from_old_place (GError ** error)
 
406
{
 
407
    char *old_dir;
 
408
    size_t rule_index;
 
409
 
 
410
    old_dir = mc_config_get_deprecated_path ();
 
411
 
 
412
    g_free (mc_config_init_one_config_path (mc_config_str, EDIT_DIR, error));
 
413
#ifdef MC_HOMEDIR_XDG
 
414
    g_free (mc_config_init_one_config_path (mc_cache_str, EDIT_DIR, error));
 
415
    g_free (mc_config_init_one_config_path (mc_data_str, EDIT_DIR, error));
 
416
#endif /* MC_HOMEDIR_XDG */
 
417
 
 
418
    for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
 
419
    {
 
420
        char *old_name;
 
421
        if (*mc_config_files_reference[rule_index].old_filename == '\0')
 
422
            continue;
 
423
 
 
424
        old_name =
 
425
            g_build_filename (old_dir, mc_config_files_reference[rule_index].old_filename, NULL);
 
426
 
 
427
        if (g_file_test (old_name, G_FILE_TEST_EXISTS))
 
428
        {
 
429
            char *new_name;
 
430
            const char *basedir = *mc_config_files_reference[rule_index].new_basedir;
 
431
            const char *filename = mc_config_files_reference[rule_index].new_filename;
 
432
 
 
433
            new_name = g_build_filename (basedir, filename, NULL);
 
434
            mc_config_copy (old_name, new_name, error);
 
435
            g_free (new_name);
 
436
        }
 
437
        g_free (old_name);
 
438
    }
 
439
 
 
440
#ifdef MC_HOMEDIR_XDG
 
441
    g_propagate_error (error,
 
442
                       g_error_new (MC_ERROR, 0,
 
443
                                    _
 
444
                                    ("Your old settings were migrated from %s\n"
 
445
                                     "to Freedesktop recommended dirs.\n"
 
446
                                     "To get more info, please visit\n"
 
447
                                     "http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html"),
 
448
                                    old_dir));
 
449
#else /* MC_HOMEDIR_XDG */
 
450
    g_propagate_error (error,
 
451
                       g_error_new (MC_ERROR, 0,
 
452
                                    _
 
453
                                    ("Your old settings were migrated from %s\n"
 
454
                                     "to %s\n"), old_dir, mc_config_str));
 
455
#endif /* MC_HOMEDIR_XDG */
 
456
 
 
457
    g_free (old_dir);
 
458
}
 
459
 
 
460
/* --------------------------------------------------------------------------------------------- */
 
461
 
 
462
gboolean
 
463
mc_config_deprecated_dir_present (void)
 
464
{
 
465
    char *old_dir;
 
466
    gboolean is_present;
 
467
 
 
468
    old_dir = mc_config_get_deprecated_path ();
 
469
    is_present = g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR);
 
470
    g_free (old_dir);
 
471
 
 
472
    return is_present && !config_dir_present;
 
473
}
 
474
 
 
475
/* --------------------------------------------------------------------------------------------- */
 
476
/**
 
477
 * Get full path to config file by short name.
 
478
 *
 
479
 * @param config_name short name
 
480
 * @return full path to config file
 
481
 */
 
482
 
 
483
char *
 
484
mc_config_get_full_path (const char *config_name)
 
485
{
 
486
    size_t rule_index;
 
487
 
 
488
    if (config_name == NULL)
 
489
        return NULL;
 
490
 
 
491
    if (!xdg_vars_initialized)
 
492
        mc_config_init_config_paths (NULL);
 
493
 
 
494
    for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
 
495
    {
 
496
        if (strcmp (config_name, mc_config_files_reference[rule_index].new_filename) == 0)
 
497
        {
 
498
            return g_build_filename (*mc_config_files_reference[rule_index].new_basedir,
 
499
                                     mc_config_files_reference[rule_index].new_filename, NULL);
 
500
        }
 
501
    }
 
502
    return NULL;
 
503
}
 
504
 
 
505
/* --------------------------------------------------------------------------------------------- */