def find_and_create_file_from_metadata(children, source, destination, destination_node, obj):
 for item in children:
  if (not item['materialized'].startswith('/')):
   item['materialized'] = ('/' + item['materialized'])
  if (item['kind'] == 'folder'):
   return find_and_create_file_from_metadata(item.get('children', []), source, destination, destination_node, obj)
  elif ((item['kind'] == 'file') and (item['materialized'].replace(destination['materialized'], source['materialized']) == obj.referent.materialized_path)):
   data = dict(item)
   new_file = FileNode.resolve_class(destination['provider'], FileNode.FILE).get_or_create(destination_node, item['path'])
   if (destination['provider'] != 'osfstorage'):
    new_file.update(revision=None, data=data)
   return new_file

def find_and_create_file_from_metadata ( children , source , destination , destination_node , obj ) : for item in children : if ( not item [ 'materialized' ] . startswith ( '/' ) ) : item [ 'materialized' ] = ( '/' + item [ 'materialized' ] ) if ( item [ 'kind' ] == 'folder' ) : return find_and_create_file_from_metadata ( item . get ( 'children' , [ ] ) , source , destination , destination_node , obj ) elif ( ( item [ 'kind' ] == 'file' ) and ( item [ 'materialized' ] . replace ( destination [ 'materialized' ] , source [ 'materialized' ] ) == obj . referent . materialized_path ) ) : data = dict ( item ) new_file = FileNode . resolve_class ( destination [ 'provider' ] , FileNode . FILE ) . get_or_create ( destination_node , item [ 'path' ] ) if ( destination [ 'provider' ] != 'osfstorage' ) : new_file . update ( revision = None , data = data ) return new_file
given a guid obj .