From 3e398b233b4ab56f17b27cb0ddfa72041b55b775 Mon Sep 17 00:00:00 2001
From: Daniel Heule <hda@sfs.biz>
Date: Wed, 8 Jan 2014 09:48:04 +0100
Subject: [PATCH] fix compare with leading 0 on directory mode

---
 cdist/conf/type/__directory/gencode-remote | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/cdist/conf/type/__directory/gencode-remote b/cdist/conf/type/__directory/gencode-remote
index 800fc6e4..e206ca63 100755
--- a/cdist/conf/type/__directory/gencode-remote
+++ b/cdist/conf/type/__directory/gencode-remote
@@ -85,7 +85,13 @@ DONE
          if [ -f "$__object/parameter/$attribute" ]; then
             value_should="$(cat "$__object/parameter/$attribute")"
             value_is="$(get_current_value "$attribute" "$value_should")"
-            if [ "$set_attributes" -o "$value_should" != "$value_is" ]; then
+            # the compare isn't correct when eg 0700 = 700 so we prefix the value_is to 4 chars
+            if [ "$attribute" = "mode" ] && [ ${#value_should} != ${#value_is} ]; then
+                if [ ${#value_is} = 3 ]; then
+                    value_is=0${value_is}
+                fi
+            fi
+            if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then
                "set_$attribute" "$value_should"
             fi
          fi