its mechanism is somewhat crude and not always great for human consumption).
However, POSIX shells are willing to forgive control characters in quoted
strings while humans and terminals are more likely to make a mess of things.
-The ``--extended-escapes`` flag will cause ``ingest`` to be more aggressive
-about quoting such characters, making them overtly visible.
+The ``--escape {posix,extended,human}`` option will change how ``ingest`` quotes
+such characters.
.. _injest_reflex:
:description("Record new files in the digest log as they are")
c:flag("--verbose")
:description("Be chatty on stderr about the generated comand stream")
- c:flag("--extended-escapes")
- :description("Write control characters in file names with $'...' escapes")
+ c:option("--escape")
+ -- TODO: :choices("posix", "extended", "human")
+ :default("posix")
+ :description("Control how special characters in paths are escaped")
c:flag("--no-human-escape")
:description("Avoid trying to be kind to humans with paths in the logs")
argparse_flag_inul(c)
end
end
- local shell_escape =
- args.extended_escapes and cdblib.extended_shell_escape
- or cdblib.posix_shell_escape
+ local human_escape = cdblib.extended_shell_escape
+ if not args.no_human_escape then
+ local ok, rexlib = pcall(require, "rex_posix")
+ if not ok then
+ io.stderr:write("Unable to load locale-aware regex library")
+ else
+ os.setlocale("")
+ human_escape = cdblib.mk_human_shell_escape(rexlib)
+ end
+ end
+
+ local shell_escape
+ do
+ local h = args.escape
+ if h == "posix" then shell_escape = cdblib.posix_shell_escape
+ elseif h == "extended" then shell_escape = cdblib.extended_shell_escape
+ elseif h == "human" then shell_escape = human_escape
+ else error("Bad escape function selector " .. h)
+ end
+ end
local function log_prune() end
if args.prune then
local sth_path_by_hash = assert(sql_mk_pathid_find_by_hash(dbh))
local sth_superseder_by_hash = assert(sql_mk_superseder_find_by_hash(dbh))
- local human_escape = cdblib.extended_shell_escape
- if not args.no_human_escape then
- local ok, rexlib = pcall(require, "rex_posix")
- if not ok then
- io.stderr:write("Unable to load locale-aware regex library")
- else
- os.setlocale("")
- human_escape = cdblib.mk_human_shell_escape(rexlib)
- end
- end
-
local path_crush =
args.relative and function(p) plpath.relpath(p, args.relative) end
or plpath.basename
# And with some rude characters in the path name
diff -u - <(${LUA} ./cdb --db ${DB1} ingest --target x <<<'5 rude'$'\r''new') \
<<<"cp -- 'rude"$'\r'"new' 'x/rude"$'\r'"new'"
-diff -u - <(${LUA} ./cdb --db ${DB1} ingest --target x --extended-escapes <<<'5 rude'$'\t''new') \
+diff -u - <(${LUA} ./cdb --db ${DB1} ingest --target x --escape extended <<<'5 rude'$'\t''new') \
<<<"cp -- 'rude'\$'\\x09''new' 'x/rude'\$'\\x09''new'"
diff -u - <(${LUA} ./cdb --db ${DB1} ingest --target x --verbose 2>&1 <<<'9 rude'$'\r''copy') \
<<<"Import hash 9 from path 'rude'$'\\x0d''copy' already in database at 'twinned'"