]> git.pld-linux.org Git - packages/cacti-plugin-rrdclean.git/blame - rrdmove-fixes.patch
- fix rrdmove, it was totally broken, i.e created only parent dir of parent dir of...
[packages/cacti-plugin-rrdclean.git] / rrdmove-fixes.patch
CommitLineData
ed55a777
ER
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
3@@ -137,31 +137,36 @@
4
5 /* now scan the files */
6 foreach ($file_array as $file) {
7+ $source_file = $rra_path . "/" . $file["name"];
8 switch ($file['action']) {
9 case "1" :
10- if (unlink($rra_path . "/" . $file["name"])) {
11+ if (unlink($source_file)) {
12 cacti_log("Deleted: " . $file["name"], true, "RRDCLEAN");
13 } else {
14 cacti_log($file["name"] . " Error: unable to delete from $rra_path!", true, "RRDCLEAN");
15 }
16 break;
17 case "2" :
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);
24 }
25
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");
29 } else {
30 cacti_log($file["name"] . " Error: unable to save to $rrd_backup!", true, "RRDCLEAN");
31 }
32 break;
33 case "3" :
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);
40 }
41
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");
45 } else {
46 cacti_log($file["name"] . " Error: unable to move to $rrd_archive!", true, "RRDCLEAN");
47@@ -224,25 +229,24 @@
48 function rrdclean_create_path($path) {
49 global $config;
50
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"]);
58
59- if ((chown(dirname($path), $owner_id)) &&
60- (chgrp(dirname($path), $group_id))) {
61- return TRUE;
62- }else{
63- cacti_log("ERROR: Unable to set directory permissions for '" . dirname($path) . "'", FALSE);
64- }
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);
69 }
70 }else{
71- cacti_log("ERROR: Unable to create directory '" . dirname($path) . "'", FALSE);
72+ cacti_log("ERROR: Unable to create directory '" . $path . "'", FALSE);
73 }
74 }
75
76- return FALSE;
77+ // if path existed, we can return true
78+ return is_dir($path) && is_writable($path);
79 }
80
81 /*
This page took 0.061328 seconds and 4 git commands to generate.