Skip to content

Commit

Permalink
Fix directory creation during metadata move
Browse files Browse the repository at this point in the history
  • Loading branch information
michitux committed Jan 19, 2013
1 parent 2167aea commit 51892c2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,26 @@ public function movemeta($opts) {
* @return bool If the files were moved successfully
*/
private function move_files($dir, $opts, $extregex) {
$old_path = $dir.'/';
if ($opts['ns'] != '') $old_path .= utf8_encodeFN(str_replace(':', '/', $opts['ns'])).'/';
$new_path = $dir.'/';
if ($opts['newns'] != '') $new_path .= utf8_encodeFN(str_replace(':', '/', $opts['newns'])).'/';
$old_path = $dir;
if ($opts['ns'] != '') $old_path .= '/'.utf8_encodeFN(str_replace(':', '/', $opts['ns']));
$new_path = $dir;
if ($opts['newns'] != '') $new_path .= '/'.utf8_encodeFN(str_replace(':', '/', $opts['newns']));
$regex = '/^'.preg_quote(utf8_encodeFN($opts['name'])).'('.$extregex.')$/u';

$dh = @opendir($old_path);
if($dh) {
while(($file = readdir($dh)) !== false) {
if (substr($file, 0, 1) == '.') continue;
$match = array();
if (is_file($old_path.$file) && preg_match($regex, $file, $match)) {
if (is_file($old_path.'/'.$file) && preg_match($regex, $file, $match)) {
if (!is_dir($new_path)) {
if (!io_mkdir_p($new_path)) {
msg('Creating directory '.hsc($new_path).' failed.', -1);
return false;
}
}
if (!io_rename($old_path.$file, $new_path.utf8_encodeFN($opts['newname'].$match[1]))) {
msg('Moving '.hsc($old_path.$file).' to '.hsc($new_path.utf8_encodeFN($opts['newname'].$match[1])).' failed.', -1);
if (!io_rename($old_path.'/'.$file, $new_path.'/'.utf8_encodeFN($opts['newname'].$match[1]))) {
msg('Moving '.hsc($old_path.'/'.$file).' to '.hsc($new_path.'/'.utf8_encodeFN($opts['newname'].$match[1])).' failed.', -1);
return false;
}
}
Expand Down

0 comments on commit 51892c2

Please sign in to comment.