aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeebs <seebs@seebs.net>2018-03-30 12:25:25 -0500
committerSeebs <seebs@seebs.net>2018-03-30 12:25:25 -0500
commit3e7a4eaa97abbdbd5362486898f1ba1e96774333 (patch)
tree40754ddeb380fc813f655f36041a89ada3cc7498
parentcd842c2df2fc94fe0866c3fe5ab7d34e447ca5fc (diff)
downloadpseudo-3e7a4eaa97abbdbd5362486898f1ba1e96774333.tar.gz
pseudo-3e7a4eaa97abbdbd5362486898f1ba1e96774333.tar.bz2
pseudo-3e7a4eaa97abbdbd5362486898f1ba1e96774333.zip
refix path again
wasn't gracefully handling the empty-path case, such as the initial slash at the beginning of a path. this is just a staging point, i need to reeimplement these cleanly. Signed-off-by: Seebs <seebs@seebs.net>
-rw-r--r--pseudo_util.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index 06ad8fc..7859ad9 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -639,7 +639,7 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurre
if (!is_reg) {
/* sanity-check: ignore // or /./ */
if (elen == 0 || (elen == 1 && *element == '.')) {
- return 1;
+ return 0;
}
/* backtrack for .. */
if (elen == 2 && element[0] == '.' && element[1] == '.') {
@@ -734,8 +734,8 @@ pseudo_append_elements(char *newpath, char *root, size_t allocated, char **curre
pseudo_diag("pseudo_append_elements: invalid arguments.");
return -1;
}
- pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "paes: element list <%.*s>\n",
- (int) elen, element);
+ pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "paes: newpath %s, element list <%.*s>\n",
+ newpath, (int) elen, element);
/* coming into append_elements, we should always have a trailing slash on
* the path. append_element won't provide one, though.
*/
@@ -753,7 +753,7 @@ pseudo_append_elements(char *newpath, char *root, size_t allocated, char **curre
* regular files get it appended so they can fail properly
* later for being invalid paths.
*/
- pseudo_debug(PDBGF_FILE | PDBGF_VERBOSE, "element to add: '%.*s'\n",
+ pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "element to add: '%.*s'\n",
(int) this_elen, element);
/* we initially had a trailing slash. we don't
* want append_element to append slashes, so every time through
@@ -762,14 +762,16 @@ pseudo_append_elements(char *newpath, char *root, size_t allocated, char **curre
if (add_slash) {
*(*current)++ = '/';
*(*current) = '\0';
- } else {
- add_slash = 1;
}
if (is_reg || (this_elen > 1) || ((this_elen == 1) && (*element != '.'))) {
- if (pseudo_append_element(newpath, root, allocated, current, element, this_elen, &buf, leave_this) == -1) {
+ int appended = pseudo_append_element(newpath, root, allocated, current, element, this_elen, &buf, leave_this);
+ if (appended == -1) {
retval = -1;
break;
}
+ if (appended == 1) {
+ add_slash = 1;
+ }
pseudo_debug(PDBGF_FILE | PDBGF_VERBOSE, "paes: append_element gave us '%s', current '%s'\n",
newpath, *current);
/* if a path element was appended, we want to know whether the resulting