Esempio n. 1
0
def do_update_metadata(objroot, objID, version, meta, searchFile=None):
    """this is also called by merging incoming data in
    ProcessDiscs.deal_with_stub().  only there, we're going to worry
    about the optional incoming SearchFile argument. there,
    we're trying to re-use the searchFile argument without
    re-opening it over and over again."""

    if not searchFile:
        ryw.db_print('do_update_metadata: null searchFile', 11)
    else:
        ryw.db_print('do_update_metadata: reusing searchFile', 11)
    
    if not ryw_meta.rewrite_meta(objroot, objID, version, meta):
        ryw.give_bad_news('EditObject: rewrite_meta failed.', logging.error)
        return (False, None)

    if not searchFile:
        searchFile = ryw_meta.open_search_file(RepositoryRoot,
                                               grabWriteLock = True)
    if not searchFile:
        ryw.give_bad_news('EditObject: failed to open search file.',
                          logging.critical)
        return (False, None)
        
    searchFile.modify(meta)
    return (True, searchFile)
def do_delete(objID, version, searchFile=None):
    """the optional searchFile argument is for cases of calling this
    thing in a loop: the first time, searchFile is None, so we do
    an open of the searchFile, and this gets returned to the caller,
    and the caller (in a loop) gets to reuse the searchFile argument."""    

    if not searchFile:
        searchFile = ryw_meta.open_search_file(RepositoryRoot)
        ryw.db_print('DeleteObject.do_delete: opening searchFile.', 18)
    else:
        ryw.db_print('DeleteObject.do_delete: reusing searchFile.', 18)
        
    if not searchFile:
        return (False, None)

    meta,objroot = ryw_meta.get_meta(searchFile, objID, version,
                                     RepositoryRoot)
    if not meta and not objroot:
        ryw.give_bad_news('do_delete: no meta, no objroot, giving up...',
                          logging.critical)
        searchFile.done()
        return (False, searchFile)

    #
    # try to continue deletion even if we can't get metadata.
    #

    paths = ryw_meta.get_paths(objroot, objID, version, meta, RepositoryRoot)
    if not paths:
        ryw.give_bad_news('do_delete: failed to get paths.',
                          logging.critical)
        searchFile.done()
        return (False, searchFile)

    if meta:
        #
        # hack.  I had a bug when the following function crashed
        # with meta=None
        # I didn't bother to understand what's going on.
        #
        process_reverse_lists(objID, version, meta, searchFile)

    remove_from_search_file(searchFile, objID, version)
    remove_paths(paths)
    searchFile.done()
    return (True, searchFile)