Skip to content

Instantly share code, notes, and snippets.

@arno01
Created October 19, 2015 14:33
Show Gist options
  • Save arno01/20b1c29d358892108eaa to your computer and use it in GitHub Desktop.
Save arno01/20b1c29d358892108eaa to your computer and use it in GitHub Desktop.
Simple file meta data caching and applying. Good alongside with git
#!/bin/sh -e
# git-cache-meta -- simple file meta data caching and applying.
# Simpler than etckeeper, metastore, setgitperms, etc.
# from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
# modified by n1k
# - save all files metadata not only from other users
# - save numeric uid and gid
# Changes by: Andrey Arapov <andrey.arapov@nixaid.com>
# 2015-10-16 - add '-h' flag to chown, chgrp and touch so that symlink is
# NOT followed
# - chmod cannot be applied to symlink
# - add "--" to stop processing arguments (e.g when file name has
# leading "-")
# 2015-10-14 - added quotes around path %p
# Initial release by andris9
# 2012-03-05 - added filetime, andris9
: ${GIT_CACHE_META_FILE=.git_cache_meta}
case $@ in
--store|--stdout)
case $1 in --store) exec > $GIT_CACHE_META_FILE; esac
find $(git ls-files)\
\( -printf 'chown -h %U -- "%p"\n' \) \
\( -printf 'chgrp -h %G -- "%p"\n' \) \
\( -printf 'touch -h -c -d "%AY-%Am-%Ad %AH:%AM:%AS" -- "%p"\n' \) \
! -type l \( -printf 'chmod %#m -- "%p"\n' \) ;;
--apply) sh -e $GIT_CACHE_META_FILE;;
*) 1>&2 echo "Usage: $0 --store|--stdout|--apply"; exit 1;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment