[squeak-dev] FileDirectory from a relative path

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

[squeak-dev] FileDirectory from a relative path

Miguel Cobá
Is this the way to obtain a FileDirectory from a relative path on squeak
on linux:

FileDirectory on: (FileDirectory default fullNameFor: '../backup/')

Thanks
--
Miguel Cobá
http://miguel.leugim.com.mx


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: FileDirectory from a relative path

Andreas.Raab
Try this:

   (FileDirectory default uri  resolveRelativeURI: '../backup') path.

Cheers,
   - Andreas

Miguel Enrique Cobá Martinez wrote:
> Is this the way to obtain a FileDirectory from a relative path on squeak
> on linux:
>
> FileDirectory on: (FileDirectory default fullNameFor: '../backup/')
>
> Thanks


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: FileDirectory from a relative path

Miguel Cobá
El mié, 16-09-2009 a las 20:51 -0700, Andreas Raab escribió:
> Try this:
>
>    (FileDirectory default uri  resolveRelativeURI: '../backup') path.
>

Thanks Andreas, but this line outputs a string with the resolved
absolute path. That is ok but not what I need. I need a FileDirectory
object built from a string containing a relative unix path. Without the
path message I got a HierarchicalURI that inherits from URI that
inherits from Object.

I am trying to use a method that uses a FileDirectory as parameter and I
want to use a relative path, but the line I ended with it looked very
verbose for something so simple.

Thanks anyway.

> Cheers,
>    - Andreas
>
> Miguel Enrique Cobá Martinez wrote:
> > Is this the way to obtain a FileDirectory from a relative path on squeak
> > on linux:
> >
> > FileDirectory on: (FileDirectory default fullNameFor: '../backup/')
> >
> > Thanks
>
>
--
Miguel Cobá
http://miguel.leugim.com.mx


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: FileDirectory from a relative path

Andreas.Raab
Miguel Enrique Cobá Martinez wrote:

> El mié, 16-09-2009 a las 20:51 -0700, Andreas Raab escribió:
>> Try this:
>>
>>    (FileDirectory default uri  resolveRelativeURI: '../backup') path.
>
> Thanks Andreas, but this line outputs a string with the resolved
> absolute path. That is ok but not what I need. I need a FileDirectory
> object built from a string containing a relative unix path. Without the
> path message I got a HierarchicalURI that inherits from URI that
> inherits from Object.

I thought the answer to that part of the question was obvious, since you
had included it in your own message. Just prepend a "FileDirectory on:"
before the above, i.e.,

   FileDirectory on:
     (FileDirectory default uri  resolveRelativeURI: '../backup') path.

This will answer the FileDirectory for the path you've constructed.

Cheers,
   - Andreas

> I am trying to use a method that uses a FileDirectory as parameter and I
> want to use a relative path, but the line I ended with it looked very
> verbose for something so simple.
>
> Thanks anyway.
>
>> Cheers,
>>    - Andreas
>>
>> Miguel Enrique Cobá Martinez wrote:
>>> Is this the way to obtain a FileDirectory from a relative path on squeak
>>> on linux:
>>>
>>> FileDirectory on: (FileDirectory default fullNameFor: '../backup/')
>>>
>>> Thanks
>>


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: FileDirectory from a relative path

Randal L. Schwartz
In reply to this post by Miguel Cobá
>>>>> "Miguel" == Miguel Enrique Cobá Martinez <[hidden email]> writes:

Miguel> Thanks Andreas, but this line outputs a string with the resolved
Miguel> absolute path. That is ok but not what I need. I need a FileDirectory
Miguel> object built from a string containing a relative unix path.

The *real* question is are you dealing with abstract paths, or real
disks that might have symlinks.

The problem comes about when you ask to reduce:

    /xxx/yyy/../zzz

for which, if "yyy" was made with "ln -s /aaa/bbb /xxx/yyy",
then the proper answer is:

    /aaa/zzz

Yeah.  You can't just look at the text of the string to reduce it.  You have
to ask the operating system where the heck you are.

So again, are you dealing with abstract paths that will *never* go near
a filesystem, or are you dealing with an *actual* filesystem?   And
answer carefully, for if you answer wrong, you will be burned.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: FileDirectory from a relative path

Miguel Cobá
El mié, 16-09-2009 a las 22:49 -0700, Randal L. Schwartz escribió:

> >>>>> "Miguel" == Miguel Enrique Cobá Martinez <[hidden email]> writes:
>
> Miguel> Thanks Andreas, but this line outputs a string with the resolved
> Miguel> absolute path. That is ok but not what I need. I need a FileDirectory
> Miguel> object built from a string containing a relative unix path.
>
> The *real* question is are you dealing with abstract paths, or real
> disks that might have symlinks.
>
> The problem comes about when you ask to reduce:
>
>     /xxx/yyy/../zzz
>
> for which, if "yyy" was made with "ln -s /aaa/bbb /xxx/yyy",
> then the proper answer is:
>
>     /aaa/zzz
>
> Yeah.  You can't just look at the text of the string to reduce it.  You have
> to ask the operating system where the heck you are.
>
> So again, are you dealing with abstract paths that will *never* go near
> a filesystem, or are you dealing with an *actual* filesystem?   And
> answer carefully, for if you answer wrong, you will be burned.
>

Good points.
I didn't think about those factors. I just have a setup like this:

dirA
|-->dirB/squeak.image
|-->dirC/directory

and from squeak.image wanted to pass a FileDirectory parameter to a
method using the relative path:

'../dirC/directory'

and not having the image a hardcoded path to the dirC/directory.

The lines that I found, and also the line that Andreas provided both
work. It is just that I wanted to know if there were a shorter, more
concise way, something along the lines:

FileDirectory on: '../dirC/directory/'.

But hey, the code works, it is just two lines instead of one.
Thanks


--
Miguel Cobá
http://miguel.leugim.com.mx


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: FileDirectory from a relative path

K. K. Subramaniam
On Thursday 17 Sep 2009 11:37:16 am Miguel Enrique Cobá Martinez wrote:
> The lines that I found, and also the line that Andreas provided both
> work. It is just that I wanted to know if there were a shorter, more
> concise way, something along the lines:
>
> FileDirectory on: '../dirC/directory/'.
(FileDirectory on: '../dirC/directory/') pathName returns
         '/../dirC/directory/'

I would think this is a bug. UnixFileDirectory>>setPathName:pathString
prepends '/' for a relative path. It should be prepending DefaultDirectory.

Subbu


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: FileDirectory from a relative path

Bert Freudenberg
In reply to this post by Miguel Cobá

On 17.09.2009, at 08:07, Miguel Enrique Cobá Martinez wrote:

> El mié, 16-09-2009 a las 22:49 -0700, Randal L. Schwartz escribió:
>>>>>>> "Miguel" == Miguel Enrique Cobá Martinez  
>>>>>>> <[hidden email]> writes:
>>
>> Miguel> Thanks Andreas, but this line outputs a string with the  
>> resolved
>> Miguel> absolute path. That is ok but not what I need. I need a  
>> FileDirectory
>> Miguel> object built from a string containing a relative unix path.
>>
>> The *real* question is are you dealing with abstract paths, or real
>> disks that might have symlinks.
>>
>> The problem comes about when you ask to reduce:
>>
>>    /xxx/yyy/../zzz
>>
>> for which, if "yyy" was made with "ln -s /aaa/bbb /xxx/yyy",
>> then the proper answer is:
>>
>>    /aaa/zzz
>>
>> Yeah.  You can't just look at the text of the string to reduce it.  
>> You have
>> to ask the operating system where the heck you are.
>>
>> So again, are you dealing with abstract paths that will *never* go  
>> near
>> a filesystem, or are you dealing with an *actual* filesystem?   And
>> answer carefully, for if you answer wrong, you will be burned.
>>
>
> Good points.
> I didn't think about those factors. I just have a setup like this:
>
> dirA
> |-->dirB/squeak.image
> |-->dirC/directory
>
> and from squeak.image wanted to pass a FileDirectory parameter to a
> method using the relative path:
>
> '../dirC/directory'
>
> and not having the image a hardcoded path to the dirC/directory.
>
> The lines that I found, and also the line that Andreas provided both
> work. It is just that I wanted to know if there were a shorter, more
> concise way, something along the lines:
>
> FileDirectory on: '../dirC/directory/'.
>
> But hey, the code works, it is just two lines instead of one.
> Thanks

The canonical and portable way would be

(FileDirectory default containingDirectory directoryNamed: 'dirC')  
directoryNamed: 'directory'

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: FileDirectory from a relative path

Miguel Cobá
El jue, 17-09-2009 a las 16:44 +0200, Bert Freudenberg escribió:

> On 17.09.2009, at 08:07, Miguel Enrique Cobá Martinez wrote:
>
> > El mié, 16-09-2009 a las 22:49 -0700, Randal L. Schwartz escribió:
> >>>>>>> "Miguel" == Miguel Enrique Cobá Martinez  
> >>>>>>> <[hidden email]> writes:
> >>
> >> Miguel> Thanks Andreas, but this line outputs a string with the  
> >> resolved
> >> Miguel> absolute path. That is ok but not what I need. I need a  
> >> FileDirectory
> >> Miguel> object built from a string containing a relative unix path.
> >>
> >> The *real* question is are you dealing with abstract paths, or real
> >> disks that might have symlinks.
> >>
> >> The problem comes about when you ask to reduce:
> >>
> >>    /xxx/yyy/../zzz
> >>
> >> for which, if "yyy" was made with "ln -s /aaa/bbb /xxx/yyy",
> >> then the proper answer is:
> >>
> >>    /aaa/zzz
> >>
> >> Yeah.  You can't just look at the text of the string to reduce it.  
> >> You have
> >> to ask the operating system where the heck you are.
> >>
> >> So again, are you dealing with abstract paths that will *never* go  
> >> near
> >> a filesystem, or are you dealing with an *actual* filesystem?   And
> >> answer carefully, for if you answer wrong, you will be burned.
> >>
> >
> > Good points.
> > I didn't think about those factors. I just have a setup like this:
> >
> > dirA
> > |-->dirB/squeak.image
> > |-->dirC/directory
> >
> > and from squeak.image wanted to pass a FileDirectory parameter to a
> > method using the relative path:
> >
> > '../dirC/directory'
> >
> > and not having the image a hardcoded path to the dirC/directory.
> >
> > The lines that I found, and also the line that Andreas provided both
> > work. It is just that I wanted to know if there were a shorter, more
> > concise way, something along the lines:
> >
> > FileDirectory on: '../dirC/directory/'.
> >
> > But hey, the code works, it is just two lines instead of one.
> > Thanks
>
> The canonical and portable way would be
>
> (FileDirectory default containingDirectory directoryNamed: 'dirC')  
> directoryNamed: 'directory'
>
> - Bert -

Thanks Bert


>
>
--
Miguel Cobá
http://miguel.leugim.com.mx