Skip to content

pamolloy/blog-pandoc-xattr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blog-pandoc-xattr

This masterly crafted computer science project sits proudly on the dull edge of technological innovation. A few short BASH scripts and HTML templates wrap pandoc, which generates static HTML files.

File attributes

The values of regular and extended file attributes are passed to pandoc using generate.bash.

The Linux kernel stores in-memory representations of inodes within struct inode, which are derived by the low-level filesystem from on-disk inodes.1 It appears that those representations persist in memory.2 This does not garantuee that extended file attributes are treated the same way, and it may be dependent upon the filesystem implementation. For example, see ext3/xattr.c, ext4/xattr.c, and reiserfs/xattr.c.

To set the title and creation date for a post use setfattr and then read them using getfattr:

$ setfattr -n "user.title" -v "Guessing German Noun Gender" gender.md
$ setfattr -n "user.birth" -v "$(date)" gender.md
$ getfattr -d gender.md
# file: gender.md
user.birth="Tue Aug 16 00:00:00 EDT 2011"
user.title="Guessing German Noun Gender "

Sometimes it is desirable to modify a file without changing the modification date and time. The following BASH function stores the modification date and time before modifying the file and then saves it back to the modified file. Simply add it to a bashrc file and call it from the command-line:

mod ()
{
    FILE=$1
    STAT=$(stat -c%y "$FILE")
    MTIME=$(date -d "$STAT")
    $EDITOR "$FILE"
    touch -d "$MTIME" "$FILE"
}

Extended file attributes

To get vim to preserve extended file attributes when editing a file the following needs to be set:

set backupcopy=yes

When copying a file with rsync preserve the extended attributes using --xattrs or -X. It is also recommended to use archive mode (i.e. --archive, -a).

Footnotes

  1. The Linux Virtual File System from notes by Andries Brouwer

  2. Is the file table in the filesystem or in memory?

About

Blog built using BASH, pandoc and xattr

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published