Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix:

helper fs_relative_path didn't work with symbolic link.
  • Loading branch information...
commit ef77c4c4d2f1c12ccbdd7adbf33e12a4216698fc 1 parent 3a3319c
@djalmaoliveira authored
View
21 framework/class/BasicDb.php
@@ -19,15 +19,18 @@ static function getInstance($app_mode=null) {
}
if ( isset(Liber::$aDbConfig[$app_mode]) ) {
$config = Liber::$aDbConfig[$app_mode];
- $host = ($config[0][0]=='/')?"unix_socket=".$config[0]:"host={$config[0]}";
- $dsn = $config[4].":$host;dbname={$config[1]}";
+ switch( $config[4] ) {
+ case 'mysql':
+ $host = ($config[0][0]=='/')?"unix_socket=".$config[0]:"host={$config[0]}";
+ $dsn = $config[4].":$host;dbname={$config[1]}";
+ $options = array(
+ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
+ );
+ break;
+ default:
+ }
try {
- $o = new PDO($dsn, $config[2], $config[3]);
- if ($o) {
- if ($config[4] == 'mysql') {
- $o->exec("set names 'utf8'");
- }
- }
+ $o = new PDO($dsn, $config[2], $config[3], $options);
return $o;
} catch(PDOException $e) {
trigger_error("No database connection."); // Caution: Exception message show password on stack trace.
@@ -41,4 +44,4 @@ static function getInstance($app_mode=null) {
}
-?>
+?>
View
16 framework/helper/FS.php
@@ -2,11 +2,11 @@
/**
*
* @package core.helpers
- * @author djalmaoliveira@gmail.com
- * @copyright djalmaoliveira@gmail.com
+ * @author djalmaoliveira@gmail.com
+ * @copyright djalmaoliveira@gmail.com
* @license
* @link
- * @since Version 1.0
+ * @since Version 1.0
*/
@@ -18,13 +18,13 @@
* Example: $dest_path = '/home/user/myfolder/dest_path';
* $source_path = '/home/user/oldfolder/source';
* The path will consider that you are on '/home/user/myfolder' and will return '../oldfolder/source'.
- * @param string $source_path
- * @param string $dest_path
- * @return string
+ * @param string $source_path
+ * @param string $dest_path
+ * @return string
*/
function fs_relative_path_($source_path, $dest_path) {
- $source_path = trim($source_path);
- $dest_path = trim($dest_path);
+ $source_path = realpath(trim($source_path).'/');
+ $dest_path = realpath(trim($dest_path).'/');
$aS = array_filter(explode('/', $source_path));
$aD = array_filter(explode('/', $dest_path));
View
23 tests/Helpers/FSTest.php
@@ -5,11 +5,11 @@
class FSTest extends PHPUnit_Framework_TestCase {
function SetUp() {
-
+ Liber::loadHelper('FS');
}
function testRelativePath() {
-
+
/*
source - dest => result expected
/h/a - /h/b => a
@@ -17,13 +17,26 @@ function testRelativePath() {
/h/a - /a/b => ../h/a
/h/c - /h/a/b => ../c
*/
-
+
$this->assertTrue( true , 'texto.');
}
+
+ function testRelativePathOnSymlinkPath() {
+ $source = '/tmp/test_rp/d1/d2/d3/d4';
+ $dest = '/tmp/test_rp/test';
+ if ( !file_exists('/tmp/test_rp') ) {
+ mkdir($source, 0777, true);
+ symlink('/tmp/test_rp/d1/d2/', $dest);
+ }
+ $relative = fs_relative_path_('/tmp/', '/tmp/test_rp/d1/d2/d3/d4/');
+ $this->assertEquals('../../../../', $relative, "You should be $source to reach /tmp/");
+ }
+
+
function test_Fs_scan_recursive() {
- Liber::loadHelper('FS');
+
if ( !file_exists('/tmp/test_fs') ) {
mkdir('/tmp/test_fs/d1/d2/d3', 0777, true);
}
@@ -33,6 +46,6 @@ function test_Fs_scan_recursive() {
$out = fs_scan_(realpath('/tmp/test_fs'),$func, true);
$this->assertEquals(count($out), 3, "Recursive scan seems have a problem.");
}
-
+
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.