Recent

Author Topic: CopyFile() bug ?????  (Read 8206 times)

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
CopyFile() bug ?????
« on: June 30, 2013, 05:47:04 pm »
Just wandering if its just me or does CopyFile() have a flag set for  WaitOnExit

because this does not work as one would expect it too.

Test file is 2.4 gig, in this case its a Live Linux.iso

so with that said. tmp.iso = 2.4 gb file

once CopyFile() is started the loop is not even acknowledge untill after the complete operation:



Code: [Select]

procedure TForm1.Button1Click(Sender: TObject);
var
  x: Integer;
begin
   x := 0;
   CopyFile('/root/tmp.iso','/root/tmp2.iso');

   Repeat
   application.ProcessMessages;

   Inc(x);
 
  label1.caption := IntToStr(x);

  until x = 100000;     // Set high for test purpose
end;         
« Last Edit: June 30, 2013, 06:00:35 pm by wjackson153 »
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: CopyFile() bug ?????
« Reply #1 on: June 30, 2013, 06:48:39 pm »
Maybe you need to make a TThread for the file copying yourself, if you want application to remain responsive.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: CopyFile() bug ?????
« Reply #2 on: June 30, 2013, 06:54:49 pm »
Just curious but have you looked at the copyfile procedure and what it does? From your code I assume you expect it to call the console command copy or something along those lines while in fact it handles both files it self and has a loop to copy data from one file to the other. There is no flag WaintOnExit and there is no way that such a flag can be used from that procedure. You have 2 choises as far as I can see
1) create a thread and run the copy from there setting the destroyOnTErminate to true and attaching an event handler to the OnFree/destroy (don't remember the event name) event of the thread you will get informed when the copy finishes leaving your application free to continue working.
2) Use Tprocess or TAsyncProcess and call the console command to copy the file where you can let it do its business but I have no idea if there is a way to get informed when the operation finishes other than pulling the Isrunning value at standard intervals.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: CopyFile() bug ?????
« Reply #3 on: June 30, 2013, 07:07:59 pm »
Yes I know I can use Tprocess and commandline parameters to do this.

That was not my point, my point is only that the CopyFIle()  does not use the OS copy dialog, nor does it have anyway of letting the user know the prcess is doing anyting until after the copy job has completed.


for ex on delphi for windows  when you call the CopyFile()  it uses the systems os copy dialog.

See what im getting at ?
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: CopyFile() bug ?????
« Reply #4 on: June 30, 2013, 08:14:10 pm »
Sorry but no, the last time I checked the delphi's copyfile was a few years back and it did not use the system dialog I know that there are a few libraries that use the so called shCopyfiledlg or something along those lines that uses the shell to execute the copy but this is windows only feature, an IDE designed for multi platform, especially the low level libraries that do not use or know (and they shouldn't use ) a GUI Library.

If you want something like that for windows only you better use the one that comes with your delphi or search around for an alternative.

Any way this is as designed and can't be considered as a bug.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: CopyFile() bug ?????
« Reply #5 on: June 30, 2013, 08:27:29 pm »
I Figured as much oh well guess that concludes my theory.
That CopyFile()  was not designed  for use with large file copy procedures.

anything over 300 meg on SSD will appear to be non responcive until copy has completed
anything over 100 meg on Sata  72000 rpm will be non responcive until copy has completed
anything over 10 meg on USB 2.0 will be non responcive until copy has completed , other then
your usb drive having data lights signaling there is operations occurring.

Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12715
  • FPC developer.
Re: CopyFile() bug ?????
« Reply #6 on: June 30, 2013, 08:32:18 pm »
Could you please post the Delphi code that shows the dialog?

eny

  • Hero Member
  • *****
  • Posts: 1658
Re: CopyFile() bug ?????
« Reply #7 on: June 30, 2013, 08:36:32 pm »
anything over 10 meg on USB 2.0 will be non responcive until copy has completed , other then
your usb drive having data lights signaling there is operations occurring.
Anything over 1B on any floppy drive will be non responsive until the floppy drive has stopped spinning (although the noise of the spinning disk is a dead giveaway).
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: CopyFile() bug ?????
« Reply #8 on: June 30, 2013, 09:15:12 pm »
I don't have it anymore  but the code was a custum function, that wrapped around
the win api for the file copy process.

back when I used windows 95 I tinkered with Delphi 3, and remember doing something simular
so I was merley playing around with CopyFile()  on my linux machine and discovered that it is
not viable to use for large files. Because you can not deligate the progress of the operation.

I figured instead of 23 lines of code I could simplify and downsize to 6 lines of code, to help
make my programs file  size smaller lol.



im currently using TProcess and piping the output through pv, and works great  I was just currious
if I could shorten my code to use the system copy dialog rather then having to create my own :)

Code: [Select]
   hProcess := TProcess.Create(nil);
   hProcess.Executable := '/bin/sh';
   hprocess.Parameters.Add('-c');
   hprocess.Parameters.add('pv -pf ' + srcFile + ' | dd of=' + srcTarget +' bs=512k');
   hProcess.Options := hProcess.Options + [PoUsePipes, poStderrToOutPut];
   hProcess.Execute;
   xData :=  TStringList.Create;

  while (hProcess.Running) or (hProcess.Active) do
  begin
  application.ProcessMessages;
  xData.LoadFromStream(hProcess.Output);
   fPOS := POS(']',xData[0]);
  sPOS := POS('%',xData[0]);

  if fPOS <> 0  then
    begin
  sData := Copy(xData[0],fPos + 1 , sPos - fPos - 1);
  lblProgressPercent.Caption := sData + '%';

  // I always found using a shape componient works great for a progress bar substitute.
  // Multiplied by 5 because the width is 500
  ProgressBar.Width :=  StrToInt(sData) * 5 ;
    end;
  end;

  hProcess.free;
  xData.Free;

  if hProcess.Running = false then
     begin
  // do sumthing here etc calculate md5 hash on file etc
     runcommand('/bin/sh',['-c','pv -pf ' + srcTarget + ' | md5sum'],NewData);

     end;
  end;                           
« Last Edit: June 30, 2013, 09:19:17 pm by wjackson153 »
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: CopyFile() bug ?????
« Reply #9 on: June 30, 2013, 11:32:42 pm »
I'm sorry my QT knowledge is very close to 0. I do not know if they provide such a service either as QT or KDE function.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: CopyFile() bug ?????
« Reply #10 on: July 01, 2013, 03:40:00 am »
maybe you should look at rsync software (linux,mac OS, windows) . It has gui interface.
For example of use, on Ubuntu with gtkrsync ( gnome gui) :
Code: [Select]
var hprocess : Tprocess;
    srcFile,srcTarget : String;
begin
   srcFile := '/home/user/open.bin';
   srcTarget := '/home/user/temp';
   hProcess := TProcess.Create(nil);
   hProcess.Executable := '/bin/sh';
   hprocess.Parameters.Add('-c');
   hprocess.Parameters.add('gtkrsync ' + srcFile + ' ' + srcTarget );
   hProcess.Execute;
  while (hProcess.Running) or (hProcess.Active) do
  begin
  application.ProcessMessages;
  sleep(100);
  end;
 // Showmessage('copy terminated');

end;
the good -> you can see transfer in a gtk window 
the bad   -> you must click on close button in the gtk window when the transfer is terminated.
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018