Skip to content

Commit 212ec27

Browse files
committed
Ticket #4661: show full file name in the file error message box.
* (path_trunc): improve: constify and rename the 2nd argument. Add possibility to return non-truncated path by passing a negative value as truncation width. Update Doxygen comment. Signed-off-by: Andrew Borodin <[email protected]>
1 parent d6d0426 commit 212ec27

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/util.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,14 @@ fake_name_quote (const char *s, gboolean quote_percent)
299299

300300
/* --------------------------------------------------------------------------------------------- */
301301
/**
302-
* path_trunc() is the same as str_trunc() but
303-
* it deletes possible password from path for security
304-
* reasons.
302+
* path_trunc() is the same as str_trunc() but it deletes possible password from path
303+
* for security reasons.
304+
*
305+
* @param path file path to trancate
306+
* @param width width (in characters) of truncation result. If negative, full path will be kept.
307+
*
308+
* @returns pointer to trancated path. It points to the internal static buffer, do not call
309+
g_free() to free it.
305310
*/
306311

307312
const char *
@@ -311,7 +316,14 @@ path_trunc (const char *path, const ssize_t width)
311316
const char *ret;
312317

313318
vpath = vfs_path_from_str_flags (path, VPF_STRIP_PASSWORD);
314-
ret = str_trunc (vfs_path_as_str (vpath), width);
319+
320+
const char *p = vfs_path_as_str (vpath);
321+
322+
if (width < 0)
323+
ret = str_trunc (p, -1);
324+
else
325+
ret = str_trunc (p, (size_t) width);
326+
315327
vfs_path_free (vpath, TRUE);
316328

317329
return ret;

0 commit comments

Comments
 (0)