# HG changeset patch # User František Kučera <franta-hg@frantovo.cz> # Date 1547768143 -3600 # Node ID 6383a44578333868b7c448492e67fa15c6e53c29 # Parent 2adb6465eaddcffbfb93bb4dceb4de95a235bf89 examples: relpipe-in-filesystem – extended attributes (xattr) diff -r 2adb6465eadd -r 6383a4457833 relpipe-data/examples.xml --- a/relpipe-data/examples.xml Fri Jan 18 00:00:58 2019 +0100 +++ b/relpipe-data/examples.xml Fri Jan 18 00:35:43 2019 +0100 @@ -803,6 +803,61 @@ <p> Tip: if we are looking for files in the current directory and want omit the „.“ we just call: <code>find -printf '%P\0'</code> instead of <code>find -print0</code>. </p> + + + <h2>Using relpipe-in-filesystem to read extended attributes</h2> + + <p> + Extended attributes (xattr) are additional <em>key=value</em> pairs that can be attached to our files. + They are not stored inside the files, but on the filesystem. + Thus they are independent of particular file format (which might not support metadata) + and we can use them e.g. for tagging, cataloguing or adding some notes to our files. + Some tools like GNU Wget use extended attributes to store metadata like the original URL from which the file was downloaded. + </p> + + <m:pre jazyk="bash"><![CDATA[wget --recursive --level=1 https://relational-pipes.globalcode.info/ +find -type f -printf '%P\0' \ + | relpipe-in-filesystem --file path --file size --xattr user.xdg.origin.url \ + | relpipe-out-tabular +]]></m:pre> + + <p>And now we know, where the files on our disk come from:</p> + + <pre><![CDATA[filesystem: + ╭───────────────────────────┬────────────────┬────────────────────────────────────────────────────────────────────╮ + │ path (string) │ size (integer) │ user.xdg.origin.url (string) │ + ├───────────────────────────┼────────────────┼────────────────────────────────────────────────────────────────────┤ + │ index.html │ 12159 │ https://relational-pipes.globalcode.info/v_0/ │ + │ v_0/atom.xml │ 4613 │ https://relational-pipes.globalcode.info/v_0/atom.xml │ + │ v_0/rss.xml │ 4926 │ https://relational-pipes.globalcode.info/v_0/rss.xml │ + │ v_0/js/skript.js │ 2126 │ https://relational-pipes.globalcode.info/v_0/js/skript.js │ + │ v_0/css/styl.css │ 2988 │ https://relational-pipes.globalcode.info/v_0/css/styl.css │ + │ v_0/css/relpipe.css │ 1095 │ https://relational-pipes.globalcode.info/v_0/css/relpipe.css │ + │ v_0/css/syntaxe.css │ 3584 │ https://relational-pipes.globalcode.info/v_0/css/syntaxe.css │ + │ v_0/index.xhtml │ 12159 │ https://relational-pipes.globalcode.info/v_0/index.xhtml │ + │ v_0/grafika/logo.png │ 3298 │ https://relational-pipes.globalcode.info/v_0/grafika/logo.png │ + │ v_0/principles.xhtml │ 17171 │ https://relational-pipes.globalcode.info/v_0/principles.xhtml │ + │ v_0/roadmap.xhtml │ 11097 │ https://relational-pipes.globalcode.info/v_0/roadmap.xhtml │ + │ v_0/faq.xhtml │ 11080 │ https://relational-pipes.globalcode.info/v_0/faq.xhtml │ + │ v_0/specification.xhtml │ 12983 │ https://relational-pipes.globalcode.info/v_0/specification.xhtml │ + │ v_0/implementation.xhtml │ 10810 │ https://relational-pipes.globalcode.info/v_0/implementation.xhtml │ + │ v_0/examples.xhtml │ 76958 │ https://relational-pipes.globalcode.info/v_0/examples.xhtml │ + │ v_0/license.xhtml │ 65580 │ https://relational-pipes.globalcode.info/v_0/license.xhtml │ + │ v_0/screenshots.xhtml │ 5708 │ https://relational-pipes.globalcode.info/v_0/screenshots.xhtml │ + │ v_0/download.xhtml │ 5204 │ https://relational-pipes.globalcode.info/v_0/download.xhtml │ + │ v_0/contact.xhtml │ 4940 │ https://relational-pipes.globalcode.info/v_0/contact.xhtml │ + │ v_0/classic-example.xhtml │ 9539 │ https://relational-pipes.globalcode.info/v_0/classic-example.xhtml │ + ╰───────────────────────────┴────────────────┴────────────────────────────────────────────────────────────────────╯ +Record count: 20]]></pre> + + <p> + If we like the BeOS/Haiku style, we can create empty files with some attributes attached and use our filesystem as a simple database + and query it using relational tools. + It will lack indexing, but for basic scenarios like <em>address book</em> it will be fast enough + and we can feel a bit of BeOS/Haiku atmosphere in our contemporary GNU/Linux systems. + But be careful with that because some editors delete and recreate files while saving them, which destroys the xattrs. + Tools like <code>rsync</code> or <code>tar</code> with <code>--xattrs</code> option will backup our attributes securely. + </p> </text>