1 --- cacti-plugin-rrdclean-0.40/rrdmove.php~ 2010-12-14 10:10:59.431054842 +0200
2 +++ cacti-plugin-rrdclean-0.40/rrdmove.php 2010-12-14 10:32:23.984260340 +0200
5 /* now scan the files */
6 foreach ($file_array as $file) {
7 + $source_file = $rra_path . "/" . $file["name"];
8 switch ($file['action']) {
10 - if (unlink($rra_path . "/" . $file["name"])) {
11 + if (unlink($source_file)) {
12 cacti_log("Deleted: " . $file["name"], true, "RRDCLEAN");
14 cacti_log($file["name"] . " Error: unable to delete from $rra_path!", true, "RRDCLEAN");
18 - if (!is_dir(dirname($rrd_backup . "/" . $file["name"]))) {
19 - rrdclean_create_path(dirname($rrd_backup . "/" . $file["name"]));
20 + $target_file = $rrd_backup . "/" . $file["name"];
21 + $target_dir = dirname($target_file);
22 + if (!is_dir($target_dir)) {
23 + rrdclean_create_path($target_dir);
26 - if (copy($rra_path . "/" . $file["name"], $rrd_backup . "/" . $file["name"])) {
27 + if (copy($source_file, $target_file)) {
28 cacti_log("Copied: " . $file["name"] . " to: " . $rrd_backup, true, "RRDCLEAN");
30 cacti_log($file["name"] . " Error: unable to save to $rrd_backup!", true, "RRDCLEAN");
34 - if (!is_dir(dirname($rrd_archive . "/" . $file["name"]))) {
35 - rrdclean_create_path(dirname($rrd_archive . "/" . $file["name"]));
36 + $target_file = $rrd_archive . "/" . $file["name"];
37 + $target_dir = dirname($target_file);
38 + if (!is_dir($target_dir)) {
39 + rrdclean_create_path($target_dir);
42 - if (rename($rra_path . "/" . $file["name"], $rrd_archive . "/" . $file["name"])) {
43 + if (rename($source_file, $target_file)) {
44 cacti_log("Moved: " . $file["name"] . " to: " . $rrd_archive, true, "RRDCLEAN");
46 cacti_log($file["name"] . " Error: unable to move to $rrd_archive!", true, "RRDCLEAN");
48 function rrdclean_create_path($path) {
51 - if (!is_dir(dirname($path))) {
52 - if (mkdir(dirname($path), 0775)) {
53 + if (!is_dir($path)) {
54 + if (mkdir($path, 0775)) {
55 if ($config["cacti_server_os"] != "win32") {
56 $owner_id = fileowner($config["rra_path"]);
57 $group_id = filegroup($config["rra_path"]);
59 - if ((chown(dirname($path), $owner_id)) &&
60 - (chgrp(dirname($path), $group_id))) {
63 - cacti_log("ERROR: Unable to set directory permissions for '" . dirname($path) . "'", FALSE);
65 + // NOTE: chown/chgrp fails for non-root users, checking their
66 + // result is therefore irrevelevant
67 + @chown($path, $owner_id);
68 + @chgrp($path, $group_id);
71 - cacti_log("ERROR: Unable to create directory '" . dirname($path) . "'", FALSE);
72 + cacti_log("ERROR: Unable to create directory '" . $path . "'", FALSE);
77 + // if path existed, we can return true
78 + return is_dir($path) && is_writable($path);