From 08e8fd7e38f2dae7c69c54eb22d508b6517e66e5 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Sun, 1 Nov 2015 18:53:26 +0000 Subject: all: avoid quoting file names when possible Quote file names using the "shell-escape" or "shell-escape-always" methods, which quote as appropriate for most shells, and better support copy and paste of presented names. The "always" variant is used when the file name is embedded in an error message with surrounding spaces. * cfg.mk (sc_error_shell_quotes): A new syntax check rule to suggest quotef() where appropriate. (sc_error_shell_always_quotes): Likewise for quoteaf(). * src/system.h (quotef): A new define to apply shell quoting when needed. I.E. when shell character or ':' is present. (quoteaf): Likewise, but always quote. * src/*.c: Use quotef() and quoteaf() rather than quote() where appropriate. * tests/: Adjust accordingly. --- src/stat.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/stat.c') diff --git a/src/stat.c b/src/stat.c index a8a8c9d64..0721457d9 100644 --- a/src/stat.c +++ b/src/stat.c @@ -733,7 +733,7 @@ out_file_context (char *pformat, size_t prefix_len, char const *filename) : lgetfilecon (filename, &scontext)) < 0) { error (0, errno, _("failed to get security context of %s"), - quote (filename)); + quoteaf (filename)); scontext = NULL; fail = true; } @@ -889,7 +889,7 @@ out_mount_point (char const *filename, char *pformat, size_t prefix_len, char *resolved = canonicalize_file_name (filename); if (!resolved) { - error (0, errno, _("failed to canonicalize %s"), quote (filename)); + error (0, errno, _("failed to canonicalize %s"), quoteaf (filename)); goto print_mount_point; } bp = find_bind_mount (resolved); @@ -979,18 +979,18 @@ print_stat (char *pformat, size_t prefix_len, unsigned int m, out_string (pformat, prefix_len, filename); break; case 'N': - out_string (pformat, prefix_len, quote (filename)); + out_string (pformat, prefix_len, quoteaf (filename)); if (S_ISLNK (statbuf->st_mode)) { char *linkname = areadlink_with_size (filename, statbuf->st_size); if (linkname == NULL) { error (0, errno, _("cannot read symbolic link %s"), - quote (filename)); + quoteaf (filename)); return true; } printf (" -> "); - out_string (pformat, prefix_len, quote (linkname)); + out_string (pformat, prefix_len, quoteaf (linkname)); free (linkname); } break; @@ -1265,14 +1265,14 @@ do_statfs (char const *filename, char const *format) if (STREQ (filename, "-")) { error (0, 0, _("using %s to denote standard input does not work" - " in file system mode"), quote (filename)); + " in file system mode"), quoteaf (filename)); return false; } if (STATFS (filename, &statfsbuf) != 0) { error (0, errno, _("cannot read file system information for %s"), - quote (filename)); + quoteaf (filename)); return false; } @@ -1303,7 +1303,7 @@ do_stat (char const *filename, char const *format, ? stat (filename, &statbuf) : lstat (filename, &statbuf)) != 0) { - error (0, errno, _("cannot stat %s"), quote (filename)); + error (0, errno, _("cannot stat %s"), quoteaf (filename)); return false; } -- cgit v1.2.3-54-g00ecf