From 9a447a83bd456acd0734483c12a433a74fd7fb3a Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sun, 12 Aug 2012 15:43:33 +0200 Subject: [PATCH] Adds renaming. --- src/_h5ai/config.js | 7 +++++++ src/_h5ai/php/api.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/_h5ai/config.js b/src/_h5ai/config.js index 17e3117b..9020bb90 100644 --- a/src/_h5ai/config.js +++ b/src/_h5ai/config.js @@ -247,6 +247,13 @@ var H5AI_CONFIG = { "size": 150 }, + /* + Allow to rename files. + */ + "rename": { + "enabled": false + }, + /* Make entries selectable. At the moment only needed for packaged download and delete. */ diff --git a/src/_h5ai/php/api.php b/src/_h5ai/php/api.php index 3e8aef5b..2b8659c4 100644 --- a/src/_h5ai/php/api.php +++ b/src/_h5ai/php/api.php @@ -193,13 +193,40 @@ else if ($action === "delete") { } if ($errors->size) { - json_fail(1, "deletion failed for some"); + json_fail(2, "deletion failed for some"); } else { json_exit(); } } +else if ($action === "rename") { + + json_fail(1, "renaming disabled", !$options["rename"]["enabled"]); + + list($href, $name) = check_keys(array("href", "name")); + + $d = H5ai::normalize_path(dirname($href), true); + $n = basename($href); + + $code = $h5ai->getHttpCode($d); + if ($code == 401) { + } + + if ($code == "h5ai" && !$h5ai->is_ignored($n)) { + + $absPath = $h5ai->getAbsPath($href); + $folder = H5ai::normalize_path(dirname($absPath)); + + if (!rename($absPath, $folder . "/" . $name)) { + json_fail(2, "renaming failed"); + } + } + + json_exit(); +} + + else { json_fail(100, "unsupported action"); }