Symbolic Links

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Symbolic Links

Andre Schnoor
Does a solution exist for OSX / Unixes? I mean, something like this

    Filename>>isSymbolicLink
    Filename>>createSymbolicLinkTo: aTargetFilename
    Filename>>symbolicLinkTarget

Programatically creating a directory tree with (relative) symbolic links
seems to be a really difficult task. I have no idea how to do that
efficiently. Invoking external shell commands wouldn't be my first choice.

Andre

Reply | Threaded
Open this post in threaded view
|

Re: Symbolic Links

Andre Schnoor
Thanks Nick, that seems to be a nice approach. Although implementing the stat() and lstat() calls with their structs might be a little more work.

I am currently using the Cocoa interface on OSX as a workaround, which also works fine. This solution however, will not run on other Unixes (see below). A clean stat() and lstat() implementation would probably be better.

Andre



    MacOSXFilename>>createSymbolicLink: targetFilename
        ^NSFileManager defaultManager
            createSymbolicLinkAtPath: self
            pathContent: targetFilename

    MacOSXFilename>>isSymbolicLink
        ^(NSFileManager defaultManager
            pathContentOfSymbolicLinkAtPath: self asString) notNil

    MacOSXFilename>>symbolicLinkTarget
        | str |
        str := NSFileManager defaultManager
            pathContentOfSymbolicLinkAtPath: self asString.
        ^str isNil
            ifTrue:[ nil ]
            ifFalse:[ str asFilename ]




Nick Yannakoyorgos wrote:
Andre,

Try the attached which simply implements the symlink() Unix call. Use as:

(Filename named: '/tmp/sourcefile') linkTo: (Filename named: '/tmp/targetlink')

A very quick look through the engine code didn't show an implementation of symlink().

Nick

Andre Schnoor wrote:
Does a solution exist for OSX / Unixes? I mean, something like this

   Filename>>isSymbolicLink
   Filename>>createSymbolicLinkTo: aTargetFilename
   Filename>>symbolicLinkTarget

Programatically creating a directory tree with (relative) symbolic links seems to be a really difficult task. I have no idea how to do that efficiently. Invoking external shell commands wouldn't be my first choice.

Andre



<?xml version="1.0"?> <st-source> <time-stamp>From VisualWorks®, 7.4 of December 5, 2005 on June 17, 2007 at 10:40:17 am</time-stamp> <methods> <class-id>OS.UnixSystemSupport</class-id> <category>procedures</category> <body package="Standard IO Streams" selector="symlink:to:">symlink: oldpath to: newpath &lt;C: int symlink(char * oldpath, char * newpath)&gt; ^self externalAccessFailedWith: _errorCode</body> </methods> <methods> <class-id>OS.Filename</class-id> <category>file utilities</category> <body package="OS-Support" selector="linkTo:">linkTo: anotherFilename OSSystemSupport concreteClass new symlink: (self class encodeFilename: self asString) to: (self class encodeFilename: anotherFilename asString)</body> </methods> </st-source>

-- 
Andre Schnoor
Cognitone GmbH
www.cognitone.com
Reply | Threaded
Open this post in threaded view
|

Re: Symbolic Links

Dave Stevenson-2
I don't know how applicable it would be to non-linux plats, but in case
it is helpful at least as a starting point I thought I'd mention that
some years ago Pete wrote some code for the packaging tool to use, which
is found here:
        $VISUALWORKS/contributed/LinuxSymlinkSupport.pcl
and the client code is here:
        $VISUALWORKS/contributed/PackingListTool.pcl

I believe he may have more general code somewhere that he plans to
integrate at some point, but I could be wrong.

Dave

Andre Schnoor wrote:

> Thanks Nick, that seems to be a nice approach. Although implementing the
> stat() and lstat() calls with their structs might be a little more work.
>
> I am currently using the Cocoa interface on OSX as a workaround, which
> also works fine. This solution however, will not run on other Unixes
> (see below). A clean stat() and lstat() implementation would probably be
> better.
>
> Andre
>
>
>
>     MacOSXFilename>>createSymbolicLink: targetFilename
>         ^NSFileManager defaultManager
>             createSymbolicLinkAtPath: self
>             pathContent: targetFilename
>
>     MacOSXFilename>>isSymbolicLink
>         ^(NSFileManager defaultManager
>             pathContentOfSymbolicLinkAtPath: self asString) notNil
>
>     MacOSXFilename>>symbolicLinkTarget
>         | str |
>         str := NSFileManager defaultManager
>             pathContentOfSymbolicLinkAtPath: self asString.
>         ^str isNil
>             ifTrue:[ nil ]
>             ifFalse:[ str asFilename ]
>
>
>
>
> Nick Yannakoyorgos wrote:
>> Andre,
>>
>> Try the attached which simply implements the symlink() Unix call. Use as:
>>
>> (Filename named: '/tmp/sourcefile') linkTo: (Filename named:
>> '/tmp/targetlink')
>>
>> A very quick look through the engine code didn't show an
>> implementation of symlink().
>>
>> Nick
>>
>> Andre Schnoor wrote:
>>> Does a solution exist for OSX / Unixes? I mean, something like this
>>>
>>>    Filename>>isSymbolicLink
>>>    Filename>>createSymbolicLinkTo: aTargetFilename
>>>    Filename>>symbolicLinkTarget
>>>
>>> Programatically creating a directory tree with (relative) symbolic
>>> links seems to be a really difficult task. I have no idea how to do
>>> that efficiently. Invoking external shell commands wouldn't be my
>>> first choice.
>>>
>>> Andre
>>>
>>
>> ------------------------------------------------------------------------
>>
>> <?xml version="1.0"?>
>>
>> <st-source>
>> <time-stamp>From VisualWorks®, 7.4 of December 5, 2005 on June 17, 2007 at 10:40:17 am</time-stamp>
>>
>>
>> <methods>
>> <class-id>OS.UnixSystemSupport</class-id> <category>procedures</category>
>>
>> <body package="Standard IO Streams" selector="symlink:to:">symlink: oldpath to: newpath
>>
>> &lt;C: int symlink(char * oldpath, char * newpath)&gt;
>> ^self externalAccessFailedWith: _errorCode</body>
>> </methods>
>> <methods>
>> <class-id>OS.Filename</class-id> <category>file utilities</category>
>>
>> <body package="OS-Support" selector="linkTo:">linkTo: anotherFilename
>>
>> OSSystemSupport concreteClass new
>> symlink: (self class encodeFilename: self asString)
>> to: (self class encodeFilename: anotherFilename asString)</body>
>> </methods>
>>
>> </st-source>
>>  
>
> --
> Andre Schnoor
> Cognitone GmbH
> www.cognitone.com
>