summaryrefslogtreecommitdiffstats
path: root/tools/idevicecrashreport.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/idevicecrashreport.c')
-rw-r--r--tools/idevicecrashreport.c95
1 files changed, 46 insertions, 49 deletions
diff --git a/tools/idevicecrashreport.c b/tools/idevicecrashreport.c
index ced5be2..b9869ae 100644
--- a/tools/idevicecrashreport.c
+++ b/tools/idevicecrashreport.c
@@ -146,7 +146,7 @@ static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char
146 continue; 146 continue;
147 } 147 }
148 148
149 char **fileinfo = NULL; 149 plist_t fileinfo = NULL;
150 struct stat stbuf; 150 struct stat stbuf;
151 memset(&stbuf, '\0', sizeof(struct stat)); 151 memset(&stbuf, '\0', sizeof(struct stat));
152 152
@@ -173,70 +173,67 @@ static int afc_client_copy_and_remove_crash_reports(afc_client_t afc, const char
173 } 173 }
174 174
175 /* get file information */ 175 /* get file information */
176 afc_get_file_info(afc, source_filename, &fileinfo); 176 afc_get_file_info_plist(afc, source_filename, &fileinfo);
177 if (!fileinfo) { 177 if (!fileinfo) {
178 printf("Failed to read information for '%s'. Skipping...\n", source_filename); 178 printf("Failed to read information for '%s'. Skipping...\n", source_filename);
179 continue; 179 continue;
180 } 180 }
181 181
182 /* parse file information */ 182 /* parse file information */
183 int i; 183 stbuf.st_size = plist_dict_get_uint(fileinfo, "st_size");
184 for (i = 0; fileinfo[i]; i+=2) { 184 const char* s_ifmt = plist_get_string_ptr(plist_dict_get_item(fileinfo, "st_ifmt"), NULL);
185 if (!strcmp(fileinfo[i], "st_size")) { 185 if (s_ifmt) {
186 stbuf.st_size = atoll(fileinfo[i+1]); 186 if (!strcmp(s_ifmt, "S_IFREG")) {
187 } else if (!strcmp(fileinfo[i], "st_ifmt")) { 187 stbuf.st_mode = S_IFREG;
188 if (!strcmp(fileinfo[i+1], "S_IFREG")) { 188 } else if (!strcmp(s_ifmt, "S_IFDIR")) {
189 stbuf.st_mode = S_IFREG; 189 stbuf.st_mode = S_IFDIR;
190 } else if (!strcmp(fileinfo[i+1], "S_IFDIR")) { 190 } else if (!strcmp(s_ifmt, "S_IFLNK")) {
191 stbuf.st_mode = S_IFDIR; 191 stbuf.st_mode = S_IFLNK;
192 } else if (!strcmp(fileinfo[i+1], "S_IFLNK")) { 192 } else if (!strcmp(s_ifmt, "S_IFBLK")) {
193 stbuf.st_mode = S_IFLNK; 193 stbuf.st_mode = S_IFBLK;
194 } else if (!strcmp(fileinfo[i+1], "S_IFBLK")) { 194 } else if (!strcmp(s_ifmt, "S_IFCHR")) {
195 stbuf.st_mode = S_IFBLK; 195 stbuf.st_mode = S_IFCHR;
196 } else if (!strcmp(fileinfo[i+1], "S_IFCHR")) { 196 } else if (!strcmp(s_ifmt, "S_IFIFO")) {
197 stbuf.st_mode = S_IFCHR; 197 stbuf.st_mode = S_IFIFO;
198 } else if (!strcmp(fileinfo[i+1], "S_IFIFO")) { 198 } else if (!strcmp(s_ifmt, "S_IFSOCK")) {
199 stbuf.st_mode = S_IFIFO; 199 stbuf.st_mode = S_IFSOCK;
200 } else if (!strcmp(fileinfo[i+1], "S_IFSOCK")) { 200 }
201 stbuf.st_mode = S_IFSOCK; 201 }
202 } 202 stbuf.st_nlink = plist_dict_get_uint(fileinfo, "st_nlink");
203 } else if (!strcmp(fileinfo[i], "st_nlink")) { 203 stbuf.st_mtime = (time_t)(plist_dict_get_uint(fileinfo, "st_mtime") / 1000000000);
204 stbuf.st_nlink = atoi(fileinfo[i+1]); 204 const char* linktarget = plist_get_string_ptr(plist_dict_get_item(fileinfo, "LinkTarget"), NULL);
205 } else if (!strcmp(fileinfo[i], "st_mtime")) { 205 if (linktarget && !remove_all) {
206 stbuf.st_mtime = (time_t)(atoll(fileinfo[i+1]) / 1000000000); 206 /* report latest crash report filename */
207 } else if (!strcmp(fileinfo[i], "LinkTarget") && !remove_all) { 207 printf("Link: %s\n", (char*)target_filename + strlen(target_directory));
208 /* report latest crash report filename */ 208
209 printf("Link: %s\n", (char*)target_filename + strlen(target_directory)); 209 /* remove any previous symlink */
210 210 if (file_exists(target_filename)) {
211 /* remove any previous symlink */ 211 remove(target_filename);
212 if (file_exists(target_filename)) { 212 }
213 remove(target_filename);
214 }
215 213
216#ifndef _WIN32 214#ifndef _WIN32
217 /* use relative filename */ 215 /* use relative filename */
218 char* b = strrchr(fileinfo[i+1], '/'); 216 const char* b = strrchr(linktarget, '/');
219 if (b == NULL) { 217 if (b == NULL) {
220 b = fileinfo[i+1]; 218 b = linktarget;
221 } else { 219 } else {
222 b++; 220 b++;
223 } 221 }
224 222
225 /* create a symlink pointing to latest log */ 223 /* create a symlink pointing to latest log */
226 if (symlink(b, target_filename) < 0) { 224 if (symlink(b, target_filename) < 0) {
227 fprintf(stderr, "Can't create symlink to %s\n", b); 225 fprintf(stderr, "Can't create symlink to %s\n", b);
228 } 226 }
229#endif 227#endif
230 228
231 if (!keep_crash_reports) 229 if (!keep_crash_reports)
232 afc_remove_path(afc, source_filename); 230 afc_remove_path(afc, source_filename);
233 231
234 res = 0; 232 res = 0;
235 }
236 } 233 }
237 234
238 /* free file information */ 235 /* free file information */
239 afc_dictionary_free(fileinfo); 236 plist_free(fileinfo);
240 237
241 /* recurse into child directories */ 238 /* recurse into child directories */
242 if (S_ISDIR(stbuf.st_mode)) { 239 if (S_ISDIR(stbuf.st_mode)) {