View | Details | Raw Unified | Return to bug 31
Collapse All | Expand All

(-)src/completion.c (-16 / +61 lines)
Lines 10-34 Link Here
10
#define COMPLETION_MAX 4000
10
#define COMPLETION_MAX 4000
11
#define COMPLETION_NAME_KEY "completion_name"
11
#define COMPLETION_NAME_KEY "completion_name"
12
12
13
static char * completion_filename(const char * name, int create_dirs)
13
//
14
static gchar *
15
get_completion_filename_on_save(const char * name)
14
{
16
{
15
    char logStr[1024];
17
    char logStr[1024];
16
    const char * cache = g_getenv("XDG_CACHE_HOME");
18
    
17
    char * file;
19
    gchar *path = g_build_filename(g_get_user_cache_dir(), "asunder", NULL);
18
    if (cache == NULL) {
20
    
19
        file = g_strdup_printf("%s/.asunder_%s", g_getenv("HOME"), name);
21
    gchar *result_filename = g_build_filename(path, name, NULL);
22
    
23
    if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
24
        recursive_mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
20
    }
25
    }
21
    else {
26
    
22
        file = g_strdup_printf("%s/asunder/%s", cache, name);
27
    g_free(path);
23
        if (create_dirs) {
28
        
24
            char * dir = g_strdup_printf("%s/asunder", cache);
29
    snprintf(logStr, 1024, "using completion file name: %s\n", result_filename);
25
            recursive_mkdir(dir, S_IRWXU|S_IRWXG|S_IRWXO);
30
    debugLog(logStr);
26
            g_free(dir);
31
    return result_filename;
32
    
33
}
34
35
//
36
static gchar *
37
get_completion_filename_on_load(const char * name)
38
{
39
    char logStr[1024];
40
    const char * xdg_cache_home = g_getenv("XDG_CACHE_HOME");
41
    gchar *result_filename = NULL;
42
    gchar *filename;
43
    gchar *dot_filename;
44
    gchar *user_cache_filename;
45
    gchar *home_folder_filename;
46
    gchar *xdg_cache_home_filename;
47
    
48
    filename = g_strdup_printf("asunder_%s", name);
49
    dot_filename = g_strdup_printf(".%s", filename);
50
    user_cache_filename = g_build_filename(g_get_user_cache_dir(), "asunder", filename, NULL);
51
    home_folder_filename = g_build_filename(g_getenv("HOME"), dot_filename, NULL);
52
    g_free(dot_filename);
53
    
54
    xdg_cache_home_filename = g_build_filename(xdg_cache_home, "asunder", filename, NULL);
55
    
56
    if (g_file_test(user_cache_filename, G_FILE_TEST_EXISTS)) {
57
        result_filename = g_strdup(user_cache_filename);
58
        
59
    } else if (xdg_cache_home == NULL) {
60
        
61
        if (g_file_test(home_folder_filename, G_FILE_TEST_EXISTS)) {
62
            result_filename = g_strdup(home_folder_filename); 
27
        }
63
        }
28
    }
64
    }
29
    snprintf(logStr, 1024, "using completion file name: %s\n", file);
65
    else {
66
        result_filename = g_strdup(xdg_cache_home_filename);
67
    }
68
    
69
    g_free(filename);
70
    g_free(user_cache_filename);
71
    g_free(home_folder_filename);
72
    g_free(xdg_cache_home_filename);
73
    
74
    snprintf(logStr, 1024, "using completion file name: %s\n", result_filename);
30
    debugLog(logStr);
75
    debugLog(logStr);
31
    return file;
76
    return result_filename;
32
}
77
}
33
78
34
static void
79
static void
Lines 35-47 Link Here
35
read_completion_file(GtkListStore * list, const char * name)
80
read_completion_file(GtkListStore * list, const char * name)
36
{
81
{
37
    char buf[1024];
82
    char buf[1024];
38
    char * file;
83
    gchar * file;
39
    char * ptr;
84
    char * ptr;
40
    FILE * data;
85
    FILE * data;
41
    GtkTreeIter iter;
86
    GtkTreeIter iter;
42
    int i;
87
    int i;
43
88
44
    file = completion_filename(name, false);
89
    file = get_completion_filename_on_load(name);
45
    if (file == NULL)
90
    if (file == NULL)
46
      fatalError("g_strdup_printf() failed. Out of memory.");
91
      fatalError("g_strdup_printf() failed. Out of memory.");
47
92
Lines 146-152 Link Here
146
    if (name == NULL)
191
    if (name == NULL)
147
      return;
192
      return;
148
193
149
    file = completion_filename(name, 1);
194
    file = get_completion_filename_on_save(name);
150
    if (file == NULL)
195
    if (file == NULL)
151
      fatalError("g_strdup_printf() failed. Out of memory.");
196
      fatalError("g_strdup_printf() failed. Out of memory.");
152
197

Return to bug 31