[Mapbender-commits] r2759 - branches/spsneo_dev/mapbender/update
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Aug 8 16:06:52 EDT 2008
Author: spsneo
Date: 2008-08-08 16:06:52 -0400 (Fri, 08 Aug 2008)
New Revision: 2759
Added:
branches/spsneo_dev/mapbender/update/verify_checksum.php
Log:
function to verify checksum of files
Added: branches/spsneo_dev/mapbender/update/verify_checksum.php
===================================================================
--- branches/spsneo_dev/mapbender/update/verify_checksum.php (rev 0)
+++ branches/spsneo_dev/mapbender/update/verify_checksum.php 2008-08-08 20:06:52 UTC (rev 2759)
@@ -0,0 +1,75 @@
+<?php
+
+function verify_checksum($dir_path) {
+
+ global $customized_modules;
+ $file_arr = array();
+ $checksum_array = array();
+
+ //remove slash if it is there at the end of the path
+ if(substr($dir_path, -1) == '/') {
+ $dir_path = substr($dir_path, 0 , -1);
+ }
+
+
+ if(!is_readable($dir_path)) {
+ echo $dir_path." is not readable.\nPlease make sure you have privilege to update.\nAborting...\n";
+ exit();
+ }
+
+
+ if(!is_file($dir_path.'/checksum.json')) {
+ echo "The checksum.json file does not exist in ".$dir_path.". Probably the administrator has customized the installation.\n";
+ $customized_modules[] = $dir_path;
+ return False;
+ } else {
+ $file_string = file_get_contents($dir_path.'/checksum.json');
+ $checksum_array = json_decode($file_string, true);
+ }
+
+ $directory = dir($dir_path);
+ while(false !== ($file = $directory->read())) {
+ $file_path = $dir_path.'/'.$file;
+ if(is_file($file_path) && $file != 'checksum.json' && !preg_match("/~$/", $file) && !preg_match("/^\./", $file)) {
+ if(is_readable($file_path)) {
+ $file_arr[$file] = sha1_file($file_path);
+ } else {
+ echo $file_path."is not readable.\nPlease make sure you have privilege to update.\nAborting...\n";
+ exit();
+ }
+ } else if (is_dir($file_path) && !preg_match("/^\./", $file)) {
+ if($file != '.' && $file != '..' ) {
+ verify_checksum($file_path);
+ }
+ } else {
+
+ }
+ }
+
+ //Compare the checksums
+ //Compare the number of elements
+ $old_count = count($checksum_array);
+ $new_count = count($file_arr);
+ if($old_count > $new_count) {
+ $difference = $old_count - $new_count;
+ echo $difference." file/files has been deleted.in ".$dir_path."directory\n";
+ $customized_modules[] = $dir_path;
+ return False;
+ } else if($old_count < $new_count) {
+ $difference = $new_count - $old_count;
+ echo $difference." new file/files has been added in ".$dir_path."directory\n";
+ $customized_modules[] = $dir_path;
+ return False;
+ } else {
+ foreach($checksum_array as $file => $checksum) {
+ if($file_arr[$file] != $checksum) {
+ $customized_modules[] = $dir_path;
+ return False;
+ }
+ }
+ }
+ return TRUE;
+}
+
+
+?>
More information about the Mapbender_commits
mailing list