Skip to content
Permalink
Browse files Browse the repository at this point in the history
Migration: On import of user accounts only import folders in home dir…
…, use OC_Helper::copyr

Check files when copying recursivley

Remove obsolete method

Dont count '.' and '..' as directories when importing.
  • Loading branch information
tomneedham committed Nov 8, 2012
1 parent 9c88857 commit e8a0cea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/helper.php
Expand Up @@ -305,7 +305,7 @@ static function copyr($src, $dest) {
self::copyr("$src/$file", "$dest/$file");
}
}
}elseif(file_exists($src)) {
}elseif(file_exists($src) && !OC_Filesystem::isFileBlacklisted($src)) {
copy($src, $dest);
}
}
Expand Down
46 changes: 12 additions & 34 deletions lib/migrate.php
Expand Up @@ -200,7 +200,7 @@ public static function import( $path, $type='user', $uid=null ) {
$scan = scandir( $extractpath );
// Check for export_info.json
if( !in_array( 'export_info.json', $scan ) ) {
OC_Log::write( 'migration', 'Invalid import file, export_info.json note found', OC_Log::ERROR );
OC_Log::write( 'migration', 'Invalid import file, export_info.json not found', OC_Log::ERROR );
return json_encode( array( 'success' => false ) );
}
$json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) );
Expand Down Expand Up @@ -235,8 +235,17 @@ public static function import( $path, $type='user', $uid=null ) {
return json_encode( array( 'success' => false ) );
}
// Copy data
if( !self::copy_r( $extractpath . $json->exporteduser, $datadir . '/' . self::$uid ) ) {
return json_encode( array( 'success' => false ) );
$userfolder = $extractpath . $json->exporteduser;
$newuserfolder = $datadir . '/' . self::$uid;
foreach(scandir($userfolder) as $file){
$success = true;
if($file !== '.' && $file !== '..' && is_dir($file)){
// Then copy the folder over
$success = OC_Helper::copyr($userfolder.'/'.$file, $newuserfolder.'/'.$file);
}
if(!$success){
return json_encode( array( 'success' => false ) );
}
}
// Import user app data
if( !$appsimported = self::importAppData( $extractpath . $json->exporteduser . '/migration.db', $json, self::$uid ) ) {
Expand Down Expand Up @@ -304,37 +313,6 @@ private static function unlink_r( $dir, $deleteRootToo=true ) {
return true;
}

/**
* @brief copies recursively
* @param $path string path to source folder
* @param $dest string path to destination
* @return bool
*/
private static function copy_r( $path, $dest ) {
if( is_dir($path) ) {
@mkdir( $dest );
$objects = scandir( $path );
if( sizeof( $objects ) > 0 ) {
foreach( $objects as $file ) {
if( $file == "." || $file == ".." || $file == ".htaccess")
continue;
// go on
if( is_dir( $path . '/' . $file ) ) {
self::copy_r( $path .'/' . $file, $dest . '/' . $file );
} else {
copy( $path . '/' . $file, $dest . '/' . $file );
}
}
}
return true;
}
elseif( is_file( $path ) ) {
return copy( $path, $dest );
} else {
return false;
}
}

/**
* @brief tries to extract the import zip
* @param $path string path to the zip
Expand Down

0 comments on commit e8a0cea

Please sign in to comment.