Lines 27-33
Link Here
|
27 |
#include <dirent.h> |
27 |
#include <dirent.h> |
28 |
#include <scrollkeeper.h> |
28 |
#include <scrollkeeper.h> |
29 |
|
29 |
|
30 |
#define PATHLEN 256 |
|
|
31 |
|
30 |
|
32 |
|
31 |
|
33 |
/* |
32 |
/* |
Lines 55-61
Link Here
|
55 |
*/ |
54 |
*/ |
56 |
int sk_mkdir_with_parents(char *fullpath, mode_t options, char outputprefs) |
55 |
int sk_mkdir_with_parents(char *fullpath, mode_t options, char outputprefs) |
57 |
{ |
56 |
{ |
58 |
char path[1024]; |
57 |
char path[PATH_MAX]; |
59 |
char slash[]="/"; |
58 |
char slash[]="/"; |
60 |
char delim[]="/"; |
59 |
char delim[]="/"; |
61 |
char *token, *pathcopy; |
60 |
char *token, *pathcopy; |
Lines 63-77
Link Here
|
63 |
|
62 |
|
64 |
pathcopy = strdup(fullpath); /* Copy b/c strtok edits the string it operates on */ |
63 |
pathcopy = strdup(fullpath); /* Copy b/c strtok edits the string it operates on */ |
65 |
path[0] = '\0'; /* Initialize with end of string null character */ |
64 |
path[0] = '\0'; /* Initialize with end of string null character */ |
66 |
if (pathcopy[0] == slash[0]) sprintf(path, "/"); /* preserve any starting slash */ |
65 |
if (pathcopy[0] == slash[0]) strcpy(path, "/"); /* preserve any starting slash */ |
67 |
|
66 |
|
68 |
token = strtok (pathcopy, delim); |
67 |
token = strtok (pathcopy, delim); |
69 |
delim[0]=slash[0]; |
68 |
delim[0]=slash[0]; |
70 |
while(token != NULL) { |
69 |
while(token != NULL) { |
71 |
if (strlen(path) == 0 || ((strlen(path) == 1) && (path[0] == slash[0]))) { |
70 |
if (strlen(path) == 0 || ((strlen(path) == 1) && (path[0] == slash[0]))) { |
72 |
sprintf(path, "%s%s", path, token); |
71 |
strncat(path, token, PATH_MAX - strlen(path) - 1); |
73 |
} else { |
72 |
} else { |
74 |
sprintf(path, "%s/%s", path, token); |
73 |
strncat(path, "/", PATH_MAX - strlen(path) - 1); |
|
|
74 |
strncat(path, token, PATH_MAX - strlen(path) - 1); |
75 |
} |
75 |
} |
76 |
if (stat(path, &buf) == -1) { |
76 |
if (stat(path, &buf) == -1) { |
77 |
if (sk_mkdir(path, options, outputprefs) != 0) { |
77 |
if (sk_mkdir(path, options, outputprefs) != 0) { |
Lines 93-103
Link Here
|
93 |
int create_database_directory(char *scrollkeeper_dir, char *scrollkeeper_data_dir, char outputprefs) |
93 |
int create_database_directory(char *scrollkeeper_dir, char *scrollkeeper_data_dir, char outputprefs) |
94 |
{ |
94 |
{ |
95 |
DIR *dir; |
95 |
DIR *dir; |
96 |
char source_path[PATHLEN], target_path[PATHLEN]; |
96 |
char source_path[PATH_MAX], target_path[PATH_MAX]; |
97 |
struct dirent *dir_ent; |
97 |
struct dirent *dir_ent; |
98 |
struct stat buf; |
98 |
struct stat buf; |
99 |
int empty; |
99 |
int empty; |
100 |
char *data_dir, dirname[PATHLEN]; |
100 |
char *data_dir, dirname[PATH_MAX]; |
101 |
|
101 |
|
102 |
/* check if it's empty */ |
102 |
/* check if it's empty */ |
103 |
|
103 |
|
Lines 109-114
Link Here
|
109 |
return 1; |
109 |
return 1; |
110 |
} |
110 |
} |
111 |
dir = opendir(scrollkeeper_dir); |
111 |
dir = opendir(scrollkeeper_dir); |
|
|
112 |
if (dir == NULL) { |
113 |
return 1; |
114 |
} |
112 |
} |
115 |
} |
113 |
|
116 |
|
114 |
|
117 |
|
Lines 133-173
Link Here
|
133 |
|
136 |
|
134 |
dir = opendir(data_dir); |
137 |
dir = opendir(data_dir); |
135 |
|
138 |
|
|
|
139 |
if (dir == NULL) { |
140 |
free (data_dir); |
141 |
return 2; |
142 |
} |
143 |
|
136 |
while((dir_ent = readdir(dir)) != NULL) |
144 |
while((dir_ent = readdir(dir)) != NULL) |
137 |
{ |
145 |
{ |
138 |
if (dir_ent->d_name[0] == '.') |
146 |
if (dir_ent->d_name[0] == '.') |
139 |
continue; |
147 |
continue; |
140 |
|
148 |
|
141 |
snprintf(source_path, PATHLEN, "%s/%s", data_dir, dir_ent->d_name); |
149 |
snprintf(source_path, PATH_MAX, "%s/%s", data_dir, dir_ent->d_name); |
142 |
|
150 |
|
143 |
lstat(source_path, &buf); |
151 |
lstat(source_path, &buf); |
144 |
|
152 |
|
145 |
if (S_ISDIR(buf.st_mode)) /* copy the directory */ |
153 |
if (S_ISDIR(buf.st_mode)) /* copy the directory */ |
146 |
{ |
154 |
{ |
147 |
char source_file[PATHLEN], target_file[PATHLEN]; |
155 |
char source_file[PATH_MAX], target_file[PATH_MAX]; |
148 |
|
156 |
|
149 |
snprintf(dirname, PATHLEN, "%s/%s", scrollkeeper_dir, dir_ent->d_name); |
157 |
snprintf(dirname, PATH_MAX, "%s/%s", scrollkeeper_dir, dir_ent->d_name); |
150 |
mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); |
158 |
mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); |
151 |
|
159 |
|
152 |
snprintf(source_file, PATHLEN, "%s/scrollkeeper_cl.xml", source_path); |
160 |
snprintf(source_file, PATH_MAX, "%s/scrollkeeper_cl.xml", source_path); |
153 |
snprintf(target_file, PATHLEN, "%s/%s/scrollkeeper_cl.xml", |
161 |
snprintf(target_file, PATH_MAX, "%s/%s/scrollkeeper_cl.xml", |
154 |
scrollkeeper_dir, dir_ent->d_name); |
162 |
scrollkeeper_dir, dir_ent->d_name); |
155 |
copy_file(source_file, target_file); |
163 |
copy_file(source_file, target_file); |
156 |
snprintf(target_file, PATHLEN, "%s/%s/scrollkeeper_extended_cl.xml", |
164 |
snprintf(target_file, PATH_MAX, "%s/%s/scrollkeeper_extended_cl.xml", |
157 |
scrollkeeper_dir, dir_ent->d_name); |
165 |
scrollkeeper_dir, dir_ent->d_name); |
158 |
copy_file(source_file, target_file); |
166 |
copy_file(source_file, target_file); |
159 |
} |
167 |
} |
160 |
else /* link the directory */ |
168 |
else /* link the directory */ |
161 |
{ |
169 |
{ |
162 |
char *target_locale; |
170 |
char *target_locale; |
163 |
char aux_path[PATHLEN]; |
171 |
char aux_path[PATH_MAX]; |
164 |
|
172 |
|
165 |
realpath(source_path, aux_path); |
173 |
realpath(source_path, aux_path); |
166 |
target_locale = strrchr(aux_path, '/'); |
174 |
target_locale = strrchr(aux_path, '/'); |
167 |
target_locale++; |
175 |
target_locale++; |
168 |
|
176 |
|
169 |
snprintf(source_path, PATHLEN, "%s/%s", scrollkeeper_dir, dir_ent->d_name); |
177 |
snprintf(source_path, PATH_MAX, "%s/%s", scrollkeeper_dir, dir_ent->d_name); |
170 |
snprintf(target_path, PATHLEN, "%s", target_locale); |
178 |
snprintf(target_path, PATH_MAX, "%s", target_locale); |
171 |
|
179 |
|
172 |
symlink(target_path, source_path); |
180 |
symlink(target_path, source_path); |
173 |
} |
181 |
} |
Lines 178-187
Link Here
|
178 |
|
186 |
|
179 |
/* create TOC and index directory */ |
187 |
/* create TOC and index directory */ |
180 |
|
188 |
|
181 |
snprintf(dirname, PATHLEN, "%s/TOC", scrollkeeper_dir); |
189 |
snprintf(dirname, PATH_MAX, "%s/TOC", scrollkeeper_dir); |
182 |
mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); |
190 |
mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); |
183 |
|
191 |
|
184 |
snprintf(dirname, PATHLEN, "%s/index", scrollkeeper_dir); |
192 |
snprintf(dirname, PATH_MAX, "%s/index", scrollkeeper_dir); |
185 |
mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); |
193 |
mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); |
186 |
return 0; |
194 |
return 0; |
187 |
} |
195 |
} |