+/* TODO make sure callers check the return value so we can bail on errors.
+ * For now we soldier on as best we can, skipping paths that are too long to
+ * resolve and using the original filenames on memory errors. */
/**
* @brief Resolves a symlink and its children.
*
* @attention Pre-condition: files must be sorted!
*
* @param files filelist to resolve
- * @param i index in files to start processing
+ * @param i pointer to the index in files to start processing, will point to
+ * the last file processed on return
* @param path absolute path for the symlink being resolved
* @param root_len length of the root portion of path
* @param resolving is file i in files a symlink that needs to be resolved
*
- * @return the index of the last file resolved
+ * @return 0 on success, -1 on error
*/
-size_t _alpm_filelist_resolve_link(
- alpm_filelist_t *files, size_t i, char *path, size_t root_len, int resolving)
+int _alpm_filelist_resolve_link(alpm_filelist_t *files, size_t *i,
+ char *path, size_t root_len, int resolving)
{
char *causal_dir; /* symlink being resolved */
char *filename_r = NULL; /* resolved filename */
@@ -54,29 +58,29 @@ size_t _alpm_filelist_resolve_link(
if(resolving) {
/* deal with the symlink being resolved */
MALLOC(filename_r, PATH_MAX, goto error);
- causal_dir = files->files[i].name;
+ causal_dir = files->files[*i].name;
causal_dir_len = strlen(causal_dir);
if(realpath(path, filename_r) == NULL) {
- files->resolved_path[i] = causal_dir;
+ files->resolved_path[*i] = causal_dir;
FREE(filename_r);
- return i;
+ return -1;
}
causal_dir_r_len = strlen(filename_r + root_len) + 1;
if(causal_dir_r_len >= PATH_MAX) {
- files->resolved_path[i] = causal_dir;
+ files->resolved_path[*i] = causal_dir;
FREE(filename_r);
- return i;
+ return -1;
}
/* remove root_r from filename_r */
memmove(filename_r, filename_r + root_len, causal_dir_r_len);
filename_r[causal_dir_r_len - 1] = '/';
filename_r[causal_dir_r_len] = ' ';
- STRDUP(files->resolved_path[i], filename_r, goto error);
- i++;
+ STRDUP(files->resolved_path[*i], filename_r, goto error);
+ (*i)++;
}