Recent

Author Topic: [SOLVED] FileExists doesn't always work in Windows  (Read 25205 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #45 on: September 11, 2020, 04:04:20 pm »
@DJMaster: would you please test whether the attached patch makes FileExists work correctly for you?

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #46 on: September 11, 2020, 07:07:24 pm »
Windows only
Win 10 (64 bits) , fpc 64 bits (3.0.4), these functions tested OK with this code
isfile and isfolder.
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. program fileexists;
  4.  
  5.  function stats(p1:pchar; p2:pointer):integer; cdecl external 'msvcrt.dll' name '_stat';
  6.  
  7.  
  8.  type     // 36 bytes in memory
  9.  stat =object
  10.  st_dev: longword;
  11.  st_ino: word;
  12.  st_mode:word;
  13.  st_nlink: smallint;
  14.  st_uid :smallint;
  15.  st_gid:smallint;
  16.  st_rdev:longword;
  17.  st_size:longint;
  18.  st_atime:longint;
  19.  st_mtime:longint;
  20.  st_ctime:longint;
  21. end;
  22.  
  23.  
  24.  function isfolder(path:pchar):integer;
  25.   var
  26.  statbuf:stat;
  27.  begin
  28.    if stats(path,@statbuf)<>0 then exit(0);
  29.    if (statbuf.st_mode) And 61440 = 16384 then exit(1);
  30.    exit(0);
  31.  end;
  32.  
  33.  function isfile(path:pchar):integer;
  34.   var
  35.  statbuf:stat;
  36.  begin
  37.  if isfolder(path)<>0 then exit(0);
  38.    if stats(path,@statbuf)<>0 then exit(0);
  39.    if (statbuf.st_atime) <>0 then exit(1);
  40.    exit(0);
  41.  end;
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  begin
  48.   writeln(isfolder('C:\Users\Computer\Desktop\fb\pascal\graphics')) ;  // enter your own path of course
  49.   writeln(isfile('C:\Users\Computer\Desktop\fb\pascal\empty.txt')) ;
  50.   writeln('Press a key to end . . .');
  51.  readln;
  52.  
  53.  end.
  54.  
  55.  
« Last Edit: September 11, 2020, 08:03:00 pm by BobDog »

DJMaster

  • New Member
  • *
  • Posts: 44
    • DJMaster on GitHub
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #47 on: September 11, 2020, 08:10:15 pm »
@DJMaster: would you please test whether the attached patch makes FileExists work correctly for you?

@PascalDragon: symlinks.patch solves the issue, please apply to trunk and branches/fixes_3_2, thank you!

DJMaster

  • New Member
  • *
  • Posts: 44
    • DJMaster on GitHub
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #48 on: September 11, 2020, 09:22:31 pm »
Windows only
Win 10 (64 bits) , fpc 64 bits (3.0.4), these functions tested OK with this code
isfile and isfolder.

@BobDog: Your example works with OneDrive for Business files too (FPC 3.2.0 / FPC fixes_3_2).

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #49 on: September 11, 2020, 10:08:04 pm »

DJMaster

  • New Member
  • *
  • Posts: 44
    • DJMaster on GitHub
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #50 on: September 11, 2020, 10:19:46 pm »
Oh, you discuss "my bug"
https://github.com/Alexey-T/CudaText/issues/2836

In my case it happens with OneDrive for Business files only, it doesn't happen with OneDrive Personal files.

https://forum.lazarus.freepascal.org/index.php/topic,42155.msg376162.html#msg376162

Unfortunately it is a FPC bug, introduced in version 3.2.0 and the worst thing is that this issue affects production if you moved from 3.0.4 to 3.2.0.

IMHO it should be declared as KNOWN BUG to avoid headaches to many FPC 3.2.0 Windows developers.
« Last Edit: September 11, 2020, 10:22:20 pm by DJMaster »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #51 on: September 12, 2020, 10:08:41 am »
@DJMaster: would you please test whether the attached patch makes FileExists work correctly for you?

@PascalDragon: symlinks.patch solves the issue, please apply to trunk and branches/fixes_3_2, thank you!

Thank you for testing. Applied to trunk in 46855 and I've requested a merge to 3.2.1.

DJMaster

  • New Member
  • *
  • Posts: 44
    • DJMaster on GitHub
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #52 on: September 17, 2020, 08:03:01 pm »
Thank you PascalDragon for your trunk patch. Any news about merging into 3.2.1?

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #53 on: September 17, 2020, 08:37:52 pm »
Yes, I need that merge too, please.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #54 on: September 17, 2020, 09:30:13 pm »
Scheduled:

http://www.stack.nl/~marcov/mergelogs32/tomerge.html

will do asap, probably coming weekend

AlexTP

  • Hero Member
  • *****
  • Posts: 2406
    • UVviewsoft
Re: [SOLVED] FileExists doesn't always work in Windows
« Reply #55 on: October 10, 2020, 07:23:51 pm »
@marcov
No progress with merging "reparse points" win32 fix?

 

TinyPortal © 2005-2018