From 6d097529405a7e7791b4daac1909bafd38445c5c Mon Sep 17 00:00:00 2001
From: Bart Visscher <bartv@thisnet.nl>
Date: Tue, 30 Oct 2012 20:57:19 +0100
Subject: [PATCH] DRY for creating htaccess to protect data-directory

---
 lib/base.php  | 4 +---
 lib/setup.php | 4 ++++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/base.php b/lib/base.php
index baa384d102e..de458cedb1e 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -225,9 +225,7 @@ class OC{
 				if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
 					if(!OC_Util::ishtaccessworking()) {
 						if(!file_exists(OC::$SERVERROOT.'/data/.htaccess')) {
-							$content = "deny from all\n";
-							$content.= "IndexIgnore *";
-							file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
+							OC_Setup::protectDataDirectory();
 						}
 					}
 				}		
diff --git a/lib/setup.php b/lib/setup.php
index 579a1b523ce..1d3fbd1c8ea 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -559,6 +559,10 @@ class OC_Setup {
 		$content.= "Options -Indexes\n";
 		@file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
 
+		self::protectDataDirectory();
+	}
+
+	public static function protectDataDirectory() {
 		$content = "deny from all\n";
 		$content.= "IndexIgnore *";
 		file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/.htaccess', $content);
-- 
GitLab