Revision
129
Author
emsmith
Date
2007-02-01 10:04:01 -0800 (Thu, 01 Feb 2007)

Log Message

Recursively mkdir our appdata folder, and some additional error handling

Modified Paths

Diff

Modified: trunk/lib/os.class.php (128 => 129)


--- trunk/lib/os.class.php	2007-02-01 17:54:09 UTC (rev 128)
+++ trunk/lib/os.class.php	2007-02-01 18:04:01 UTC (rev 129)
@@ -64,6 +64,7 @@
 		{
 			$temp = realpath(dirname($temp_file));
 			unlink($temp_file);
+			if (file_exists($temp) && is_dir($temp))
 			return $temp;
 		}
 		else
@@ -86,42 +87,42 @@
 			$env = $_ENV + $_SERVER;
 			if (isset($env['USERPROFILE']))
 			{
-				return $env['USERPROFILE'] . DS;
+				$profile = $env['USERPROFILE'] . DS;
 			}
 			elseif (isset($env['HOMEPATH']) && isset($env['HOMEDRIVE']))
 			{
-				return $env['HOMEPATH'] . $env['HOMEDRIVE'] . DS;
+				$profile = $env['HOMEPATH'] . $env['HOMEDRIVE'] . DS;
 			}
 			elseif (isset($env['USERNAME']) && file_exists('C:\Documents and Settings\\' . $env['USERNAME']))
 			{
-				return 'C:\Documents and Settings\\' . $env['USERNAME'] . DS;
+				$profile = 'C:\Documents and Settings\\' . $env['USERNAME'] . DS;
 			}
-			else
-			{
-				return CC::$dir;
-			}
 		}
 		else
 		{
 			if (isset($_ENV['HOME']))
 			{
-				return $_ENV['HOME'] . DS;
+				$profile = $_ENV['HOME'] . DS;
 			}
 			elseif ((stristr(PHP_OS, 'darwin') || stristr(PHP_OS, 'mac')) &&
 				isset($_ENV['USER']) && file_exists('/Users/' . $_ENV['USER']))
 			{
-				return '/Users/' . $_ENV['USER'] . DS;
+				$profile = '/Users/' . $_ENV['USER'] . DS;
 			}
 			elseif (isset($_ENV['USER']) &&
 				file_exists('/home/' . $_ENV['USER']))
 			{
-				return '/home/' . $_ENV['USER'] . DS;
+				$profile = '/home/' . $_ENV['USER'] . DS;
 			}
-			else
-			{
-				return CC::$dir;
-			}
 		}
+		if (isset($profile) && file_exists($profile) && is_dir($profile))
+		{
+			return $profile;
+		}
+		else
+		{
+			return CC::$dir;
+		}
 	}
 
 	/**
@@ -156,7 +157,7 @@
 		}
 		if (!file_exists($path))
 		{
-			mkdir($path);
+			mkdir($path, 077, true);
 		}
 		return $path;
 	}
@@ -176,20 +177,27 @@
 			$shell = new COM('WScript.Shell');
 			$documents = $shell->SpecialFolders('MyDocuments');
 			unset ($shell);
-			return $documents;
 		}
 		else
 		{
 			$home = $this->get_profile();
 			if (file_exists($home . 'Documents'))
 			{
-				return $home . 'Documents' . DS;
+				$documents = $home . 'Documents' . DS;
 			}
 			else
 			{
-				return $home;
+				$documents = $home;
 			}
 		}
+		if (file_exists($documents) && is_dir($documents))
+		{
+			return $documents;
+		}
+		else
+		{
+			return CC::$dir;
+		}
 	}
 
 	/**