Skip to content

Commit 3d611e1

Browse files
authored
Merge branch 'final' into final
2 parents 21b3a49 + ac789d3 commit 3d611e1

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/phpFastCache/Core/PathSeekerTrait.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,20 @@ public function getPath($readonly = false)
8282
if (!isset($this->tmp[ $full_path_hash ]) || (!@file_exists($full_path) || !@is_writable($full_path))) {
8383
if (!@file_exists($full_path)) {
8484
@mkdir($full_path, $this->setChmodAuto(), true);
85-
}else if (!@is_writable($full_path)) {
86-
@chmod($full_path, $this->setChmodAuto());
87-
}
88-
if (!@is_writable($full_path)) {
89-
/**
90-
* Switch back to tmp dir
91-
* again if the path is not writable
92-
*/
93-
$full_path = $full_path_tmp;
94-
if (!@file_exists($full_path)) {
95-
@mkdir($full_path, $this->setChmodAuto(), true);
85+
}elseif (!@is_writable($full_path)) {
86+
if (!@chmod($full_path, $this->setChmodAuto()))
87+
{
88+
/**
89+
* Switch back to tmp dir
90+
* again if the path is not writable
91+
*/
92+
$full_path = $full_path_tmp;
93+
if (!@file_exists($full_path)) {
94+
@mkdir($full_path, $this->setChmodAuto(), true);
95+
}
9696
}
9797
}
98+
9899
/**
99100
* In case there is no directory
100101
* writable including tye temporary

src/phpFastCache/Util/Directory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ public static function rrmdir($source, $removeOnlyChildren = false)
120120
*/
121121
public static function getAbsolutePath($path)
122122
{
123-
$path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
124-
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
123+
$parts = preg_split('~[/\\\\]+~', $path, 0, PREG_SPLIT_NO_EMPTY);
125124
$absolutes = [];
126125
foreach ($parts as $part) {
127126
if ('.' === $part) {
@@ -133,6 +132,8 @@ public static function getAbsolutePath($path)
133132
$absolutes[] = $part;
134133
}
135134
}
136-
return implode(DIRECTORY_SEPARATOR, $absolutes);
135+
$__FILE__ = __FILE__; // allows to dereference char
136+
$prefix = $__FILE__[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : '';
137+
return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes);
137138
}
138139
}

0 commit comments

Comments
 (0)