From: jkc
Subject: Question about 'rename-file
Date: 
Message-ID: <pan.2006.11.25.01.33.49.815513@makewavs.com>
I read in the hyperspec that rename-file does a merge-pathnames on the
input which if applied to this case

(rename-file #P"/tmp/somefile" #p"relative/file.name")

would fail because it would be trying to write to
#p"/tmp/relative/file.name" where that directory doesn't exist. 

This would seem to imply that the function can only be used to moved files
in rather limited circumstances. What is the preferred Lisp way to move a
file on the same filesystem?

Thanks
-Jeff

From: Zach Beane
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <m3bqmwdzbf.fsf@unnamed.xach.com>
jkc <·······@makewavs.com> writes:

> I read in the hyperspec that rename-file does a merge-pathnames on the
> input which if applied to this case
> 
> (rename-file #P"/tmp/somefile" #p"relative/file.name")
> 
> would fail because it would be trying to write to
> #p"/tmp/relative/file.name" where that directory doesn't exist. 
> 
> This would seem to imply that the function can only be used to moved files
> in rather limited circumstances. What is the preferred Lisp way to move a
> file on the same filesystem?

If you don't want to merge against the input, pre-emptively merge with
*default-pathname-defaults*.

   (rename-file #p"/tmp/somefile" 
                (merge-pathnames #p"relative/file.name"))

Zach
From: Pascal Bourguignon
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <87y7q0gr0a.fsf@thalassa.informatimago.com>
Zach Beane <····@xach.com> writes:

> jkc <·······@makewavs.com> writes:
>
>> I read in the hyperspec that rename-file does a merge-pathnames on the
>> input which if applied to this case
>> 
>> (rename-file #P"/tmp/somefile" #p"relative/file.name")
>> 
>> would fail because it would be trying to write to
>> #p"/tmp/relative/file.name" where that directory doesn't exist. 
>> 
>> This would seem to imply that the function can only be used to moved files
>> in rather limited circumstances. What is the preferred Lisp way to move a
>> file on the same filesystem?
>
> If you don't want to merge against the input, pre-emptively merge with
> *default-pathname-defaults*.
>
>    (rename-file #p"/tmp/somefile" 
>                 (merge-pathnames #p"relative/file.name"))

That said, this helps only with respect to the directory, but not for
the type.

 (rename-file #p"/tmp/somefile.sometype" (merge-pathnames #p"relative/file"))

will still merge them to #p"/some/absolute/relative/file.sometype"


At best, you can put an empty type:

 (rename-file #p"/tmp/somefile.sometype" (merge-pathnames #p"relative/file."))

and get: #p"/some/absolute/relative/file."


If you want to handle the details of host files, you'll need to use an
implementations specific API.  For example, a CFFI to POSIX functions.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
        Un chat errant
se soulage
        dans le jardin d'hiver
                                        Shiki
From: Pascal Bourguignon
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <873b88i9d0.fsf@thalassa.informatimago.com>
jkc <·······@makewavs.com> writes:

> I read in the hyperspec that rename-file does a merge-pathnames on the
> input which if applied to this case
>
> (rename-file #P"/tmp/somefile" #p"relative/file.name")
>
> would fail because it would be trying to write to
> #p"/tmp/relative/file.name" where that directory doesn't exist. 
>
> This would seem to imply that the function can only be used to moved files
> in rather limited circumstances. What is the preferred Lisp way to move a
> file on the same filesystem?

Use absolute pathnames. 


C/USER[21]> (rename-file  #P"/tmp/src/source-file" #P"/tmp/dst/file.name")
#P"/tmp/dst/file.name" ;
#P"/tmp/src/source-file" ;
#P"/tmp/dst/file.name"
C/USER[22]> 


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The mighty hunter
Returns with gifts of plump birds,
Your foot just squashed one.
From: jkc
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <pan.2006.11.25.21.22.18.114618@makewavs.com>
On Sat, 25 Nov 2006 02:49:15 +0100, Pascal Bourguignon wrote:

> jkc <·······@makewavs.com> writes:
> 
>> I read in the hyperspec that rename-file does a merge-pathnames on the
>> input which if applied to this case
>>
>> (rename-file #P"/tmp/somefile" #p"relative/file.name")
>>
>> would fail because it would be trying to write to
>> #p"/tmp/relative/file.name" where that directory doesn't exist. 
>>
>> This would seem to imply that the function can only be used to moved files
>> in rather limited circumstances. What is the preferred Lisp way to move a
>> file on the same filesystem?
> 
> Use absolute pathnames. 
> 
> 
> C/USER[21]> (rename-file  #P"/tmp/src/source-file" #P"/tmp/dst/file.name")
> #P"/tmp/dst/file.name" ;
> #P"/tmp/src/source-file" ;
> #P"/tmp/dst/file.name"
> C/USER[22]>

That doesn't satisfy my posed requirement: I want to move the file to
another path altogether:

(rename-file #p"/tmp/src/file" #p"/permanent/dest/file")

This does not work. Seems like a natural thing to want to do without
resorting to POSIX functions. 

Regards,
--Jeff
From: Harald Hanche-Olsen
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <pcohcwn9o8n.fsf@shuttle.math.ntnu.no>
+ jkc <·······@makewavs.com>:

| I want to move the file to another path altogether:
|
| (rename-file #p"/tmp/src/file" #p"/permanent/dest/file")
|
| This does not work. Seems like a natural thing to want to do without
| resorting to POSIX functions.

Assuming that these are on different filesystems, as they will be on
many unix systems, then rename-file would have to actually copy the
file to its new location, set all its attributes at the new location
to be the same as at the old location, and delete the original.  This
is quite a lot of work, maybe better done by calling an external
program like /usr/bin/mv to do the job for you.  Hopefully, that
program will be aware of any idiosyncrasies of your particular system
and know how to deal with them.

A better alternative, if you can do it, may be to create the temporary
file in a the destination filesystem to begin with.  Either in a
special directory created for the purpose, or with a filename that
makes its temporary nature obvious, so you can easily sweep up any
detritus left over from system crashes and the like.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell
From: jkc
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <pan.2006.11.26.17.32.26.29130@makewavs.com>
On Sat, 25 Nov 2006 23:04:56 +0100, Harald Hanche-Olsen wrote:

> Assuming that these are on different filesystems, as they will be on
> many unix systems, then rename-file would have to actually copy the
> file to its new location, set all its attributes at the new location
> to be the same as at the old location, and delete the original.  This
> is quite a lot of work, maybe better done by calling an external
> program like /usr/bin/mv to do the job for you.  Hopefully, that
> program will be aware of any idiosyncrasies of your particular system
> and know how to deal with them.
> 
> A better alternative, if you can do it, may be to create the temporary
> file in a the destination filesystem to begin with.  Either in a
> special directory created for the purpose, or with a filename that
> makes its temporary nature obvious, so you can easily sweep up any
> detritus left over from system crashes and the like.

I see what the problem is now. Thanks for explaining it. So, why isn't
there a 'copy-file function in Lisp? 

--Jeff
From: Pascal Bourguignon
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <87bqmudrmo.fsf@thalassa.informatimago.com>
jkc <·······@makewavs.com> writes:

> On Sat, 25 Nov 2006 23:04:56 +0100, Harald Hanche-Olsen wrote:
>
>> Assuming that these are on different filesystems, as they will be on
>> many unix systems, then rename-file would have to actually copy the
>> file to its new location, set all its attributes at the new location
>> to be the same as at the old location, and delete the original.  This
>> is quite a lot of work, maybe better done by calling an external
>> program like /usr/bin/mv to do the job for you.  Hopefully, that
>> program will be aware of any idiosyncrasies of your particular system
>> and know how to deal with them.
>> 
>> A better alternative, if you can do it, may be to create the temporary
>> file in a the destination filesystem to begin with.  Either in a
>> special directory created for the purpose, or with a filename that
>> makes its temporary nature obvious, so you can easily sweep up any
>> detritus left over from system crashes and the like.
>
> I see what the problem is now. Thanks for explaining it. So, why isn't
> there a 'copy-file function in Lisp? 

There is:

    (COM.INFORMATIMAGO.COMMON-LISP.FILE:COPY-FILE src-path dst-path
             :if-exists :error
             :external-format :default
             :element-type '(unsigned-byte 8))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

IMPORTANT NOTICE TO PURCHASERS: The entire physical universe,
including this product, may one day collapse back into an
infinitesimally small space. Should another universe subsequently
re-emerge, the existence of this product in that universe cannot be
guaranteed.
From: jkc
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <pan.2006.11.26.18.09.40.762088@makewavs.com>
On Sun, 26 Nov 2006 18:50:23 +0100, Pascal Bourguignon wrote:

>> I see what the problem is now. Thanks for explaining it. So, why isn't
>> there a 'copy-file function in Lisp? 
> 
> There is:
> 
>     (COM.INFORMATIMAGO.COMMON-LISP.FILE:COPY-FILE src-path dst-path
>              :if-exists :error
>              :external-format :default
>              :element-type '(unsigned-byte 8))

Got it. Thanks!

Is there some reason this paper is password protected?:
"The Planning and Scheduling Working Group Report on Programming Languages"

--Jeff
From: Harald Hanche-Olsen
Subject: Re: Question about 'rename-file
Date: 
Message-ID: <pcod57b9nsg.fsf@shuttle.math.ntnu.no>
+ jkc <·······@makewavs.com>:

| (rename-file #p"/tmp/src/file" #p"/permanent/dest/file")
|
| This does not work.

In my previous reply, I assumed that these were on different
filesystems.  Now I notice from your original post that they are in
fact on the same filesystem.  (Or at least, you believe this to be the
case.)  If it is indeed so, I think you need to tell us what you mean
by "does not work".  (Does it not work because the destination
directory does not exist?  If so, make use of the useful function
ensure-directories-exist.  It returns the pathname given to it, so the
call can be used in place of the original pathname.)

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell