From 6da2c6c83e48fc3c7f8dd0814fe815d2b772f6eb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 16 Feb 2013 01:50:40 +0100 Subject: [PATCH] Create new mountconfig files in json --- apps/files_external/lib/config.php | 45 ++++++++++-------------------- lib/files/filesystem.php | 16 ++++++++--- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 6ef7f37f58..36ef48462a 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -281,12 +281,19 @@ class OC_Mount_Config { private static function readData($isPersonal) { $parser = new \OC\ArrayParser(); if ($isPersonal) { - $file = OC_User::getHome(OCP\User::getUser()).'/mount.php'; + $phpFile = OC_User::getHome(OCP\User::getUser()).'/mount.php'; + $jsonFile = OC_User::getHome(OCP\User::getUser()).'/mount.json'; } else { - $file = OC::$SERVERROOT.'/config/mount.php'; + $phpFile = OC::$SERVERROOT.'/config/mount.php'; + $jsonFile = OC::$SERVERROOT.'/config/mount.json'; } - if (is_file($file)) { - $mountPoints = $parser->parsePHP(file_get_contents($file)); + if (is_file($jsonFile)) { + $mountPoints = json_decode(file_get_contents($jsonFile), true); + if (is_array($mountPoints)) { + return $mountPoints; + } + } elseif (is_file($phpFile)) { + $mountPoints = $parser->parsePHP(file_get_contents($phpFile)); if (is_array($mountPoints)) { return $mountPoints; } @@ -301,35 +308,11 @@ class OC_Mount_Config { */ private static function writeData($isPersonal, $data) { if ($isPersonal) { - $file = OC_User::getHome(OCP\User::getUser()).'/mount.php'; + $file = OC_User::getHome(OCP\User::getUser()).'/mount.json'; } else { - $file = OC::$SERVERROOT.'/config/mount.php'; + $file = OC::$SERVERROOT.'/config/mount.json'; } - $content = " array (\n"; - foreach ($data[self::MOUNT_TYPE_GROUP] as $group => $mounts) { - $content .= "\t\t'".$group."' => array (\n"; - foreach ($mounts as $mountPoint => $mount) { - $content .= "\t\t\t'".addcslashes($mountPoint, "'")."' => ".str_replace("\n", '', var_export($mount, true)).", \n"; - - } - $content .= "\t\t),\n"; - } - $content .= "\t),\n"; - } - if (isset($data[self::MOUNT_TYPE_USER])) { - $content .= "\t'user' => array (\n"; - foreach ($data[self::MOUNT_TYPE_USER] as $user => $mounts) { - $content .= "\t\t'".$user."' => array (\n"; - foreach ($mounts as $mountPoint => $mount) { - $content .= "\t\t\t'".addcslashes($mountPoint, "'")."' => ".str_replace("\n", '', var_export($mount, true)).",\n"; - } - $content .= "\t\t),\n"; - } - $content .= "\t),\n"; - } - $content .= ");\n?>"; + $content = json_encode($data); @file_put_contents($file, $content); } diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php index 89a9ab2921..cba469e06c 100644 --- a/lib/files/filesystem.php +++ b/lib/files/filesystem.php @@ -218,8 +218,12 @@ class Filesystem { $parser = new \OC\ArrayParser(); // Load system mount points - if (is_file(\OC::$SERVERROOT . '/config/mount.php')) { - $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php')); + if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) { + if(is_file(\OC::$SERVERROOT . '/config/mount.json')){ + $mountConfig = json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mount.json'), true); + }elseif(is_file(\OC::$SERVERROOT . '/config/mount.php')){ + $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php')); + } if (isset($mountConfig['global'])) { foreach ($mountConfig['global'] as $mountPoint => $options) { self::mount($options['class'], $options['options'], $mountPoint); @@ -255,8 +259,12 @@ class Filesystem { // Load personal mount points $root = \OC_User::getHome($user); self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); - if (is_file($root . '/mount.php')) { - $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php')); + if (is_file($root . '/mount.php') or is_file($root . '/mount.json')) { + if (is_file($root . '/mount.json')){ + $mountConfig = json_decode(file_get_contents($root . '/mount.json'), true); + } elseif (is_file($root . '/mount.php')){ + $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php')); + } if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { self::mount($options['class'], $options['options'], $mountPoint);