rejetto forum

Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Mars on May 16, 2009, 11:21:50 PM

Title: bug corrected on macros 'move' 'delete' 'rename' with event [upload completed]
Post by: Mars on May 16, 2009, 11:21:50 PM
only two lines are necessary into main.pas, to allow the macro move to works in event section [upload completed], and the macro delete and rename the uploaded file

Quote
  function calcAverageSpeed(bytes:int64):integer;
  begin result:=round(safeDiv(bytes, (now()-data.fileXferStart)*SECONDS*1000)) end;

  procedure closeUploadingFile(); forward; //add by mars

  function runEventScript(event:string; table:array of string):string; overload;
  var
    md: TmacroData;
    pleaseFree: boolean;
  begin
   ...
    if assigned(md.f) and (md.folder = NIL) then
      md.folder:=md.f.getParent();

    if event='upload completed' then closeUploadingFile();  //add by mars

    tryApplyMacrosAndSymbols(result, md);
  finally
    if pleaseFree then
      freeIfTemp(md.f);
    end;
  end; // runEventScript

j'ai utilisé ici une instruction forward pour ne pas avoir à déplacer la procedure closeUploadingFile() . ;)
 Mais je suis sûr que toi , tu le feras. N'est-ce pas Oncle Max?  :D
Title: Re: bug corrected on macros 'move' 'delete' 'rename' with event [upload completed]
Post by: rejetto on May 17, 2009, 07:28:12 PM
c'est vrai ;D
your solution seems to be working mars, but it's a little dirty, so i decided to study a little more before to accept it.
our problem is closing the file a bit earlier, but to be still able to read the name of the file.
i noticed the name of the file is already kept in uploadDest, so every place where i used getFilename(data.f^) can be replaced by data.uploadDest.
...and now we can safely close the file before the event call :)
this solution seems to be better

Code: [Select]
  function runEventScript(event:string; table:array of string):string; overload;
...
  try
    if isReceivingFile(data) then
      begin
      // we must encapsulate it in a Tfile to expose file properties to the script. we don't need to cache the object because we need it only once.
      md.f:=Tfile.createTemp(data.uploadDest);

and clearly

closeUploadingFile();
if data.uploadFailed = '' then runEventScript('upload completed')
else runEventScript('upload failed');
Title: Re: bug corrected on macros 'move' 'delete' 'rename' with event [upload completed]
Post by: Mars on May 17, 2009, 11:36:50 PM
ta solution semble viable, elle me convient parfaitement ;)