diff options
author | Wayne Davison <wayned@samba.org> | 2003-09-11 04:48:15 +0000 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2003-09-11 04:48:15 +0000 |
commit | eb61be192de5bb899bedb851f69981e191ba1853 (patch) | |
tree | ac5911248449d84dc66092ac9a10fdc0b0de1c2b /util.c | |
parent | 9b9114e8cd37a100087a939e9db2ccb125919ffe (diff) | |
download | rsync-eb61be192de5bb899bedb851f69981e191ba1853.tar.gz |
Added a new function, full_fname(), that makes a filename more complete
for error messages. If the path is in a module, we ensure that the
"path" setting (from the config file) is not revealed, while still
reminding the user that the path is relative to the module's root.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -774,6 +774,52 @@ int pop_dir(char *dir) return 0; } +/** + * Return a quoted string with the full pathname of the indicated filename. + * The string " (in MODNAME)" may also be appended. The returned pointer + * remains valid until the next time full_fname() is called. + **/ +char *full_fname(char *fn) +{ + extern int module_id; + static char *result = NULL; + char *m1, *m2, *m3; + char *p1, *p2; + + if (result) + free(result); + + if (*fn == '/') + p1 = p2 = ""; + else { + p1 = curr_dir; + p2 = "/"; + } + if (module_id >= 0) { + m1 = " (in "; + m2 = lp_name(module_id); + m3 = ")"; + if (*p1) { + if (!lp_use_chroot(module_id)) { + char *p = lp_path(module_id); + if (*p != '/' || p[1]) + p1 += strlen(p); + } + if (!*p1) + p2++; + else + p1++; + } + else + fn++; + } else + m1 = m2 = m3 = ""; + + asprintf(&result, "\"%s%s%s\"%s%s%s", p1, p2, fn, m1, m2, m3); + + return result; +} + /** We need to supply our own strcmp function for file list comparisons to ensure that signed/unsigned usage is consistent between machines. */ int u_strcmp(const char *cs1, const char *cs2) |