anchor.diff:  -author("Michal Stanisz").
   
   -behaviour(gen_server).
  +% fixme not needed (and maybe whole behaviour and callbacks not needed)
  +-behaviour(qos_caller_behaviour).
   
   -include("modules/datastore/qos.hrl").
   -include("modules/fslogic/fslogic_common.hrl").
  
positive.code: -export([debug/0]).
  -export([xd/2]).
  
  -define(SERVER, ?MODULE).
  
  -define(START(SpaceId, StorageId), {start, SpaceId, StorageId}).
  
negative.code: get_next_stage(wait_for_dbsync) -> clean_database;
  get_next_stage(clean_database) -> finished.
  
  execute_stage(#state{current_stage = init} = State, SpaceId, StorageId) ->
      % fixme inform zone space unsupported
      % fixme start blockades
      % fixme stop all incoming transfers
      % fixme kill handles
      % fixme mozna zrownoleglić (+ qos) -> uzyc traversu 
      next_stage(SpaceId, StorageId),
      State;
  execute_stage(#state{current_stage = qos} = State, SpaceId, StorageId) ->
      SpaceGuid = fslogic_uuid:spaceid_to_space_dir_guid(SpaceId),
      % fixme if preferred provider replace AllStorages with provider Id (not really if other providers still allowed)
      Expression = <<?ALL_STORAGES/binary, " - storage_id = ", StorageId/binary>>,
      {ok, QosEntryId} = lfm:add_qos_entry(?ROOT_SESS_ID, {guid, SpaceGuid}, Expression, 1, ?MODULE),
      ?notice("QosEntry: ~p", [QosEntryId]),
      spawn(fun() -> wait_for_qos(QosEntryId, SpaceId, StorageId) end),
      State#state{id = QosEntryId};
  execute_stage(#state{current_stage = clear_storage} = State, SpaceId, StorageId) ->
      % fixme do not clean storage if import is on
      {ok, TaskId} = unsupport_traverse:start(SpaceId, StorageId),
      ?notice("TaskId: ~p", [TaskId]),
      % fixme delete space root dir
      State#state{id = TaskId};
  execute_stage(#state{current_stage = wait_for_dbsync} = State, SpaceId, StorageId) ->
      % fixme
      % fixme wait for all docs to be saved on disc
      timer:sleep(timer:seconds(60)),
      % fixme stop dbsync
      next_stage(SpaceId, StorageId),
      State;
  execute_stage(#state{current_stage = clean_database} = State, SpaceId, StorageId) ->
      % fixme do it in init (inform zone, that space is being unsupported)
      storage_logic:revoke_space_support(StorageId, SpaceId),
      xd(SpaceId, StorageId),
      % fixme find which local documents are to be deleted and to it here (storage:space_unsupported?), space_quota
  