cross os symbolic link handling

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

cross os symbolic link handling

Marc Santhoff
Hi,

is there any function or set of functions for handling symbolic links
inside the file system at an os independant level in fpcs libraries?

Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk
files upt to XP and AFAIR Windows Vista has some other stuff I don't
know about yet.

What I'd need would be sth. like:

function IsLink(<filehandle or name>): boolean;
function GetLinkTarget(<filehandle or name>): <filehandle or name>;

Any help on this topic is welcome ... ;)

TIA,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: cross os symbolic link handling

Michael Van Canneyt


On Fri, 31 Oct 2008, Marc Santhoff wrote:

> Hi,
>
> is there any function or set of functions for handling symbolic links
> inside the file system at an os independant level in fpcs libraries?
>
> Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk
> files upt to XP and AFAIR Windows Vista has some other stuff I don't
> know about yet.
>
> What I'd need would be sth. like:
>
> function IsLink(<filehandle or name>): boolean;
> function GetLinkTarget(<filehandle or name>): <filehandle or name>;
>
> Any help on this topic is welcome ... ;)

Fpc 2.3.1 supports faSymLink in the FindFirst/FindNext series of calls.
If it is included in the attributes, then symbolic links are included as
symbolic links and not as the file/dir they refer to.

This works cross-platform. So you could do something like

function IsLink(AFileName : string): boolean;

Var
  Info : TSearchRec;

begin
  Result:=FindFirst(AFileName,faSymLink,info)=0;
  If Result then
    begin
    Result:=(info.attr and faSymLink)=faSymLink;
    FindClose(info);
    end;
end;


Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: cross os symbolic link handling

Marc Santhoff
Am Freitag, den 31.10.2008, 18:43 +0100 schrieb Michael Van Canneyt:

>
> On Fri, 31 Oct 2008, Marc Santhoff wrote:
>
> > Hi,
> >
> > is there any function or set of functions for handling symbolic links
> > inside the file system at an os independant level in fpcs libraries?
> >
> > Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk
> > files upt to XP and AFAIR Windows Vista has some other stuff I don't
> > know about yet.
> >
> > What I'd need would be sth. like:
> >
> > function IsLink(<filehandle or name>): boolean;
> > function GetLinkTarget(<filehandle or name>): <filehandle or name>;
> >
> > Any help on this topic is welcome ... ;)
>
> Fpc 2.3.1 supports faSymLink in the FindFirst/FindNext series of calls.
> If it is included in the attributes, then symbolic links are included as
> symbolic links and not as the file/dir they refer to.

That's the key part of the information, and good news to me. :)

> This works cross-platform. So you could do something like
>
> function IsLink(AFileName : string): boolean;
>
> Var
>   Info : TSearchRec;
>
> begin
>   Result:=FindFirst(AFileName,faSymLink,info)=0;
>   If Result then
>     begin
>     Result:=(info.attr and faSymLink)=faSymLink;
>     FindClose(info);
>     end;
> end;

That part is easily solvable if writing one function per od type is not
necessary.

Many thanks,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: cross os symbolic link handling

Tomas Hajny
In reply to this post by Marc Santhoff
On 31 Oct 08, at 17:49, Marc Santhoff wrote:

Hi,

> is there any function or set of functions for handling symbolic links
> inside the file system at an os independant level in fpcs libraries?
>
> Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk
> files upt to XP and AFAIR Windows Vista has some other stuff I don't
> know about yet.
 .
 .

.lnk files under Windows don't really work as symlinks and thus
wouldn't be supported at the RTL level (they aren't directly treated
like that by the Windows API level AFAIK, they're only handled by the
Windows GUI). NTFS links (available since Win2k IIRC) are another
story, those are much closer to the Unix symbolic link concept.

Tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: cross os symbolic link handling

Marc Santhoff
Am Samstag, den 01.11.2008, 10:09 +0100 schrieb Tomas Hajny:

> On 31 Oct 08, at 17:49, Marc Santhoff wrote:
>
> Hi,
>
> > is there any function or set of functions for handling symbolic links
> > inside the file system at an os independant level in fpcs libraries?
> >
> > Unix-like systems have soft symlinks (Linux, FreeBSD), Windows has .lnk
> > files upt to XP and AFAIR Windows Vista has some other stuff I don't
> > know about yet.
>  .
>  .
>
> .lnk files under Windows don't really work as symlinks and thus
> wouldn't be supported at the RTL level (they aren't directly treated
> like that by the Windows API level AFAIK, they're only handled by the
> Windows GUI).

I expected behaviour like that, but I need to retrieve some information
on the target file of the .lnk. I'm sure some shell- or winapi-funktion
will help me there.

>  NTFS links (available since Win2k IIRC) are another
> story, those are much closer to the Unix symbolic link concept.

I see, this is the new part. So I have to go searching Bills KB for that
stuff.

Thank you,
Marc



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal