comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Atomic file creation
Date: Mon, 04 Jan 2010 23:16:48 -0500
Date: 2010-01-04T23:16:48-05:00	[thread overview]
Message-ID: <u4on1b2z3.fsf@stephe-leake.org> (raw)
In-Reply-To: be17a931-d9c4-47b6-8ede-c20e144f3af7@a6g2000yqm.googlegroups.com

vlc <just.another.spam.account@googlemail.com> writes:

> I also tried something like this:
>
>  1  Ada.Text_IO.Create (Handle, Out_File);
>  2  declare
>  3     Temp_File : String := Ada.Text_IO.Name (Handle);
>  4  begin
>  5     Ada.Text_IO.Close (Handle);
>  6     Ada.Text_IO.Rename (Temp_File, "file");
>  7     Ada.Text_IO.Put_Line ("Success");
>  8  exception
>  9     when Ada.IO_Exceptions.Use_Error =>
> 10        Ada.Text_IO.Put_Line ("Failure");
> 11     when others =>
> 12        raise;
> 13  end;
>
> But Ada.Text_IO.Rename always raises Ada.IO_Exceptions.Use_Error, even
> if the file does not exist. 

Ada.Text_IO.Rename is not in the LRM. Ada.Directories.Rename is.

Some OS's don't allow renaming files across devices; if you are on
Unix, and Temp_File is /tmp/.., while "file" is /usr/..., and /tmp is
mounted to disk1, while /usr is mounted to disk2, that might explain
the use error.

In fact, the ALRM for Ada.Directories.Rename says:

67.a/2
          Implementation Note: This operation is expected to work
          within a a single directory, and implementers are encouraged
          to support it across directories on a single device. Copying
          files from one device to another is discouraged (that's what
          Copy_File is for). However, there is no requirement to detect
          file copying by the target system. If the target system has
          an API that gives that for "free", it can be used. For
          Windows®, for instance, MoveFile can be used to implement
          Rename.

> But if I replace line 1 with
>
>  1  Ada.Text_IO.Create (Handle, Out_File, "my_temp_file");
>
> it works. It seems that Ada.Text_IO.Rename cannot rename temporary
> files for whatever reason.
>
> Using Ada.Directories.Copy_File instead of Ada.Text_IO.Rename does not
> help as Ada.Directories.Copy_File overwrites files without raising an
> exception. Bad luck ...

It does seem you need to use an OS specific Form parameter to
Copy_File.

I think it's a bug that Rename raises Use_Error if Target_Name exists,
but Copy_File does not, since Copy_File is supposed to be used to
rename a file across devices.

-- 
-- Stephe



  parent reply	other threads:[~2010-01-05  4:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-04 13:40 Atomic file creation vlc
2010-01-04 14:24 ` vlc
2010-01-04 15:52   ` Jean-Pierre Rosen
2010-01-04 16:45     ` vlc
2010-01-04 17:12       ` Jean-Pierre Rosen
2010-01-04 22:38         ` Ludovic Brenta
2010-01-04 23:00           ` Dmitry A. Kazakov
2010-01-05  9:15     ` Jacob Sparre Andersen
2010-01-05  4:16   ` Stephen Leake [this message]
2010-01-05 14:48     ` vlc
2010-01-09 15:23       ` Stephen Leake
2010-01-04 14:25 ` Georg Bauhaus
2010-01-04 14:45   ` vlc
2010-01-04 14:49 ` Jacob Sparre Andersen
2010-01-04 15:07   ` vlc
2010-01-04 17:14     ` Jacob Sparre Andersen
2010-01-05 14:43       ` vlc
2010-01-06  2:28     ` Brad Moore
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox