From 7ae1a2bc524565a3e38d4d2ecb90ef4d7f2af17f Mon Sep 17 00:00:00 2001
From: Steven Armstrong <steven@icarus.ethz.ch>
Date: Mon, 4 Jun 2012 14:17:42 +0200
Subject: [PATCH] allow __file to read source file from stdin

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
---
 conf/type/__file/gencode-local | 3 +++
 conf/type/__file/man.text      | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/conf/type/__file/gencode-local b/conf/type/__file/gencode-local
index a55cfc2b..b74893fb 100755
--- a/conf/type/__file/gencode-local
+++ b/conf/type/__file/gencode-local
@@ -30,6 +30,9 @@ exists="$(cat "$__object/explorer/exists")"
 if [ "$state_should" = "present" ]; then
    if [ -f "$__object/parameter/source" ]; then
       source="$(cat "$__object/parameter/source")"
+      if [ "$source" = "-" ]; then
+         source="$__object/stdin"
+      fi
 
       if [ -f "$source" ]; then
          local_cksum="$(cksum < "$source")"
diff --git a/conf/type/__file/man.text b/conf/type/__file/man.text
index 0215027a..1c61fd51 100644
--- a/conf/type/__file/man.text
+++ b/conf/type/__file/man.text
@@ -39,6 +39,7 @@ owner::
 source::
    If supplied, copy this file from the host running cdist to the target.
    If not supplied, an empty file or directory will be created.
+   If source is '-' (dash), take what was written to stdin as the file content.
 
 
 EXAMPLES
@@ -64,6 +65,12 @@ __file /etc/shadow --source "$__type/files/shadow" \
 __file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \
    --state exists \
    --owner frodo --mode 0600
+
+# Take file content from stdin
+__file /tmp/whatever --owner root --group root --mode 644 --source - << DONE
+Here goes the content for /tmp/whatever
+DONE
+
 --------------------------------------------------------------------------------