[Mapbender-commits] r2724 - branches/spsneo_dev/build

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Sat Jul 26 02:12:56 EDT 2008


Author: spsneo
Date: 2008-07-26 02:12:52 -0400 (Sat, 26 Jul 2008)
New Revision: 2724

Added:
   branches/spsneo_dev/build/checksum-utils.inc
Log:
Function to scan and create json files

Added: branches/spsneo_dev/build/checksum-utils.inc
===================================================================
--- branches/spsneo_dev/build/checksum-utils.inc	                        (rev 0)
+++ branches/spsneo_dev/build/checksum-utils.inc	2008-07-26 06:12:52 UTC (rev 2724)
@@ -0,0 +1,55 @@
+<?php
+
+function build_checksum($dir_path) {
+	
+	$file_arr = 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_dir($dir_path)) {
+		echo $dir_path." is not a valid directory\n";
+		return FALSE;
+	}
+	
+	if(!is_readable($dir_path)) {
+		echo $dir_path." is not readable.\nPlease make sure you have privilege to build.\nAborting...";
+		exit();
+	}
+	
+	$directory = dir($dir_path);
+	while(false !== ($file = $directory->read())) {
+		$file_path = $dir_path.'/'.$file;
+		if(is_file($file_path)) {
+			if(is_readable($file_path)) {
+				if($file != 'checksum.json'){
+					$file_arr[$file] = sha1_file($file_path);
+					echo "Checksum of ".$file." created.\n";
+				}
+			} else {
+				echo $file_path." is not readable.\nPlease make sure you have privelege to build.\nAborting...";
+				exit();
+			}
+		} else if (is_dir($file_path)) {
+			if($file != '.' && $file != '..' ) {
+				echo "Scanning directory: ".$file_path."\n";
+				build_checksum($file_path);
+			}
+		} else {
+			
+		}
+	}
+	
+	$file_json_string = json_encode($file_arr);
+	$file_json_name = $dir_path."/checksum.json";
+	$file_json_handle = fopen($file_json_name, "w");
+	if(!file_json_handle) {
+		echo "Error creating file checksum.json\nPlease execute this script again.\nAborting...\n ";
+		exit();
+	}
+	fwrite($file_json_handle, $file_json_string);
+	echo "Succesfully created checksums of files in directory: ".$dir_path."\n";
+	return TRUE;
+}



More information about the Mapbender_commits mailing list