anchor.diff:  -include("communication_protocol_pb.hrl").
   
   -define(LOCATION_VALIDITY, 60*15).
  +-define(FILE_NOT_FOUND_MESSAGE, "Error: file_not_found").
  +-define(FILE_ALREADY_EXISTS, "Error: file_already_exists").
   
   %% TODO zrobić okresowe sprawdzanie drskryptorów i usuwanie przestarzałych z bazy
   %% potrzebna w dao funkcja listująca wszystkie deskryptory
  -
  -%% TODO dodać mechanizm cachowania uuidów, które mogą być wielokrotnie użyte w krótkim czasie
  +%% TODO dodać wszędzie logowanie w przypadku błędów
   
   %% ====================================================================
   %% API functions
  
positive.code:           #filelocation{storage_helper = FileLoc#file_location.storage_helper_id, file_id = FileLoc#file_location.file_id, validity = Validity};
          _BadStatus2 -> #filelocation{storage_helper = TmpAns2, file_id = "Error", validity = 0}
        end;
      _BadStatus -> #filelocation{storage_helper = TmpAns, file_id = "Error", validity = 0}
    end;
  
  %% TODO zabezpieczyć na wypadek gdyby pytano o istniejący plik
  handle_fuse_message(ProtocolVersion, Record, FuseID) when is_record(Record, getnewfilelocation) ->
    {ParentFound, ParentInfo} = get_parent_and_name_from_path(Record#getnewfilelocation.file_logic_name, ProtocolVersion),
  
    case ParentFound of
      ok ->
        {FileName, Parent} = ParentInfo,
        Storage_helper = "helper1",
        File_id = "real_location_of" ++ FileName,
        FileLocation = #file_location{storage_helper_id = Storage_helper, file_id = File_id},
        File = #file{type = ?REG_TYPE, name = FileName, size = 0, parent = Parent, location = FileLocation},
  
        Pid = self(),
        Ans = gen_server:call(?Dispatcher_Name, {dao, ProtocolVersion, Pid, 1, {vfs, save_file, [File]}}),
        {Status, TmpAns} = wait_for_dao_ans(Ans, FileName, 1, "save_file"),
  
        Validity = ?LOCATION_VALIDITY,
        case Status of
          ok ->
            {Status2, TmpAns2} = save_file_descriptor(ProtocolVersion, File, FuseID, Validity),
            case Status2 of
              ok ->
                #filelocation{storage_helper = Storage_helper, file_id = File_id, validity = Validity};
              _BadStatus2 -> #filelocation{storage_helper = TmpAns2, file_id = "Error", validity = 0}
            end;
          _BadStatus -> #filelocation{storage_helper = TmpAns, file_id = "Error", validity = 0}
        end;
      _ParentError -> #filelocation{storage_helper = ParentInfo, file_id = "Error", validity = 0}
    end;
  
  handle_fuse_message(ProtocolVersion, Record, FuseID) when is_record(Record, filenotused) ->
    %% TODO - skasować desekryptor z bazy
    %% potrzebna w dao funkcja, która wyszukuje deskryptor po parze {plik, fuse_id},
    %% ewentualnie funkcja, która kasuje deskryptory posadające odpowiednią wartość pola {plik, fuse_id}
    #atom{value = "ok"};
  
  handle_fuse_message(ProtocolVersion, Record, FuseID) when is_record(Record, renewfilelocation) ->
    %% TODO - sprawdzić czy fuse ma prawa do pliku i jeśli tak to odnowić desekryptor w bazie
    %% potrzebna w dao funkcja, która wyszukuje deskryptor po parze {plik, fuse_id}
    #filelocationvalidity{answer = "ok", validity = ?LOCATION_VALIDITY};
  
  handle_fuse_message(ProtocolVersion, Record, FuseID) when is_record(Record, createdir) ->
    {ParentFound, ParentInfo} = get_parent_and_name_from_path(Record#createdir.dir_logic_name, ProtocolVersion),
  
negative.code:     ok ->
        receive
          {worker_answer, MessageId, {ok, DaoAns}} -> {ok, DaoAns};
          {worker_answer, MessageId, {error, file_not_found}} -> {error, file_not_found};
          Ans2 ->
            lager:error([{mod, ?MODULE}], "Error: wrong dao answer for: " ++ LogMessage ++ ", file: ~s, answer: ~p", [File, Ans2]),
            {error, "Error: wrong dao answer for: " ++ LogMessage}
  