Patchwork [Ada] gnatname and temporary files

login
register
mail settings
Submitter Arnaud Charlet
Date April 11, 2013, 12:46 p.m.
Message ID <20130411124634.GA2669@adacore.com>
Download mbox | patch
Permalink /patch/235729/
State New
Headers show

Comments

Arnaud Charlet - April 11, 2013, 12:46 p.m.
Instead of creating then deleting multiple times the same temporary file,
gnatname now creates then deletes temporary files with distinct names.
In addition, if environment variable TMPDIR exists, the temporary files
are created in this directory.
No change in gnatname behavior, so no test.

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-04-11  Vincent Celier  <celier@adacore.com>

	* prj-makr.adb (Process_Directory): Create a new temporary
	file for each invocation of the compiler, in directory pointed
	by environment variable TMPDIR if it exists.

Patch

Index: prj-makr.adb
===================================================================
--- prj-makr.adb	(revision 197752)
+++ prj-makr.adb	(working copy)
@@ -38,6 +38,7 @@ 
 with Sdefault;
 with Snames;   use Snames;
 with Table;    use Table;
+with Tempdir;
 
 with Ada.Characters.Handling;   use Ada.Characters.Handling;
 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
@@ -1235,6 +1236,7 @@ 
                         Success : Boolean;
                         Saved_Output : File_Descriptor;
                         Saved_Error  : File_Descriptor;
+                        Tmp_File     : Path_Name_Type;
 
                      begin
                         --  If we don't have the path of the compiler yet,
@@ -1256,19 +1258,17 @@ 
                            end if;
                         end if;
 
-                        --  If we don't have yet the file name of the
-                        --  temporary file, get it now.
+                        --  Create the temporary file
 
-                        if Temp_File_Name = null then
-                           Create_Temp_File (FD, Temp_File_Name);
+                        Tempdir.Create_Temp_File (FD, Tmp_File);
 
-                           if FD = Invalid_FD then
-                              Prj.Com.Fail
-                                ("could not create temporary file");
-                           end if;
+                        if FD = Invalid_FD then
+                           Prj.Com.Fail
+                             ("could not create temporary file");
 
-                           Close (FD);
-                           Delete_File (Temp_File_Name.all, Success);
+                        else
+                           Temp_File_Name :=
+                             new String'(Get_Name_String (Tmp_File));
                         end if;
 
                         Args (Args'Last) := new String'
@@ -1276,16 +1276,6 @@ 
                            Directory_Separator &
                            Str (1 .. Last));
 
-                        --  Create the temporary file
-
-                        FD := Create_Output_Text_File
-                          (Name => Temp_File_Name.all);
-
-                        if FD = Invalid_FD then
-                           Prj.Com.Fail
-                             ("could not create temporary file");
-                        end if;
-
                         --  Save the standard output and error
 
                         Saved_Output := Dup (Standout);
@@ -1331,7 +1321,8 @@ 
 
                            if not Is_Valid (File) then
                               Prj.Com.Fail
-                                ("could not read temporary file");
+                                ("could not read temporary file " &
+                                 Temp_File_Name.all);
                            end if;
 
                            Save_Last_Source_Index := Sources.Last;