From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,17f674692867d416 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Atomic file creation References: From: Stephen Leake Date: Mon, 04 Jan 2010 23:16:48 -0500 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (windows-nt) Cancel-Lock: sha1:S6fm12ZAVbLc5hL8ulgPmSPJzzU= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 242144b42bd73e197caa719887 Xref: g2news1.google.com comp.lang.ada:8607 Date: 2010-01-04T23:16:48-05:00 List-Id: vlc 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