'Move the file to the hash based filename and return the file id.'

def Finalize(self):

    self._fd.close()
    final_id = self.hasher.hexdigest()
    final_filename = FileUploadFileStore.PathForId(final_id)
    if (not os.path.exists(final_filename)):
        try:
            os.makedirs(os.path.dirname(final_filename))
        except (IOError, OSError):
            pass
        shutil.move(self.tmp_path, final_filename)
    else:
        os.remove(self.tmp_path)
    return final_id
