From 95f12ed964261b87f4e2a5cd4b533b8343795cce Mon Sep 17 00:00:00 2001
From: Someone <someone@somenet.org>
Date: Fri, 22 Jan 2016 19:19:33 +0100
Subject: [PATCH] Updated copyright and hopefully fixed filename escaping

---
 vmdiff.sh | 15 +++++++++++++--
 vmsnap.sh |  4 ++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/vmdiff.sh b/vmdiff.sh
index 76c0225..ddb3085 100755
--- a/vmdiff.sh
+++ b/vmdiff.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
-# Copyright 2015 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
+# Copyright 2015-2016 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -17,6 +17,11 @@
 # Script to create diff from two selected snapshots.
 #
 
+if [[ $2 == "" ]]; then
+  echo "parameters missing: $0 <from hash> <to hash>"
+  exit 1
+fi
+
 if [ ! -d "untracked" ]; then
   echo "cannot cd untracked. wtf? fail!"
   exit 1
@@ -44,6 +49,12 @@ echo "vmdiff.files.changed.txt" >> vmdiff.tar.files.txt
 echo "root" >> vmdiff.tar.files.txt
 cat vmdiff.files.changed.txt | egrep -v "^D" | sed -e 's/^.\s\+//' >> vmdiff.tar.files.txt
 
+# workaround for \n in filename
+sed -e's/^"//g' -e 's/"$//g' vmdiff.tar.files.txt | tr '\n' '\0' | sed -e 's/\\n/\n/g' > vmdiff.tar.files0.txt
+
 git checkout "$2"
-tar -cavf vmdiff.tar.gz -T vmdiff.tar.files.txt --no-recursion
+tar --null -caf vmdiff.tar.gz -T vmdiff.tar.files0.txt --no-recursion
+rm vmdiff.tar.files0.txt 
+
+# TODO: handle git "submodules" -.-
 
diff --git a/vmsnap.sh b/vmsnap.sh
index 6e80798..a29b766 100755
--- a/vmsnap.sh
+++ b/vmsnap.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
-# Copyright 2015 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
+# Copyright 2015-2016 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@ if [ ! -d ".git" ]; then
 fi
 
 echo "storing file owner + permissions..."
-find root -not -type l -exec stat {} -c "chmod %a \"%n\"; chown %u:%g \"%n\"" \; | sort -k 3 > setPerms.sh
+find root -not -type l -print0 | sort -z | xargs -0 -n1 stat -c "chmod %a \"%n\"; chown %u:%g \"%n\"" > setPerms.sh
 
 echo "storing filesystem into git..."
 git add setPerms.sh root
-- 
2.43.0