Skip to content

Commit

Permalink
Make TmpNameAllArchs obsolete by enhancing TmpName
Browse files Browse the repository at this point in the history
Essentially, we move the added logic from TmpNameAllArchs to TmpName, but
slightly tweaked, so that it matches the behavior of TmpDirectory.

Also merge some Windows specific code in the GAP function `DirectoryTemporary`
into the kernel function `FuncTmpDirectory`
  • Loading branch information
fingolfin committed Mar 19, 2020
1 parent a42d827 commit a55149e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 41 deletions.
8 changes: 0 additions & 8 deletions lib/files.gd
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,6 @@ BIND_GLOBAL( "DirectoryTemporary", function( arg )
if dir = fail then
return fail;
fi;
if ARCH_IS_WINDOWS() then
# We want to deliver a Windows path
if dir{[1..10]} = "/cygdrive/" then
drive := dir[11];
dir := Concatenation("C:",dir{[12..Length(dir)]});
dir[1] := drive;
fi;
fi;

# remember directory name
Add( GAPInfo.DirectoriesTemporary, dir );
Expand Down
9 changes: 9 additions & 0 deletions lib/obsolete.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,12 @@ end );
##
BindGlobal("R_N", fail);
BindGlobal("R_X", fail);



#############################################################################
##
#F TmpNameAllArchs( )
##
## Still used in guava (10/2019)
DeclareObsoleteSynonym( "TmpNameAllArchs", "TmpName" );
9 changes: 0 additions & 9 deletions lib/process.gd
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,6 @@ UNBIND_GLOBAL( "Process" );
DeclareOperation( "Process",
[ IsDirectory, IsString, IsInputStream, IsOutputStream, IsList ] );

#############################################################################
##
#F TmpNameAllArchs( )
##
## returns a temporary file name based on the output of a call to TmpName
## but with adjusted temporary directory path for Window architectures
##
DeclareGlobalFunction("TmpNameAllArchs");

#############################################################################
##
#F Exec( <cmd>, <option1>, ..., <optionN> ) . . . . . . . execute a command
Expand Down
22 changes: 2 additions & 20 deletions lib/process.gi
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function( dir, prg, input, output, args )
PROCESS_INPUT_TEMPORARY:=fail;
fi;
while PROCESS_INPUT_TEMPORARY = fail do
PROCESS_INPUT_TEMPORARY := TmpNameAllArchs();
PROCESS_INPUT_TEMPORARY := TmpName();
od;
name_input := PROCESS_INPUT_TEMPORARY;
new := OutputTextFile( name_input, true );
Expand All @@ -191,7 +191,7 @@ function( dir, prg, input, output, args )
PROCESS_OUTPUT_TEMPORARY:=fail;
fi;
while PROCESS_OUTPUT_TEMPORARY = fail do
PROCESS_OUTPUT_TEMPORARY := TmpNameAllArchs();
PROCESS_OUTPUT_TEMPORARY := TmpName();
od;
name_output := PROCESS_OUTPUT_TEMPORARY;
new_output := OutputTextFile( name_output, true );
Expand Down Expand Up @@ -224,24 +224,6 @@ function( dir, prg, input, output, args )

end );

#############################################################################
##
#F TmpNameAllArchs( )
##
InstallGlobalFunction( TmpNameAllArchs, function( )
local filename, a;

filename := TmpName( );
if ARCH_IS_WINDOWS( ) then
# replace leading /tmp/ by C:/WINDOWS/Temp/
a := SplitString(filename, "/");
a := a[Length(a)]; # is "/tmp/gaptempfile.kS4uyj", get rid of /tmp/ bit

filename := Concatenation("C:/WINDOWS/Temp/", a);
fi;

return filename;
end);

#############################################################################
##
Expand Down
6 changes: 5 additions & 1 deletion src/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,11 @@ static Obj FuncREAD_GAP_ROOT(Obj self, Obj filename)
*/
static Obj FuncTmpName(Obj self)
{
#ifdef SYS_IS_CYGWIN32
char name[] = "C:/WINDOWS/Temp/gaptempfile.XXXXXX";
#else
char name[] = "/tmp/gaptempfile.XXXXXX";
#endif
close(mkstemp(name));
return MakeString(name);
}
Expand All @@ -1058,7 +1062,7 @@ static Obj FuncTmpDirectory(Obj self)
}
else {
#ifdef SYS_IS_CYGWIN32
strxcpy(name, "/cygdrive/c/WINDOWS/Temp/", sizeof(name));
strxcpy(name, "C:/WINDOWS/Temp/", sizeof(name));
#else
strxcpy(name, "/tmp/", sizeof(name));
#endif
Expand Down
6 changes: 3 additions & 3 deletions tst/testinstall/kernel/streams.tst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gap> CLOSE_LOG_TO();
Error, LogTo: can not close the logfile
gap> LOG_TO(fail);
Error, LogTo: <filename> must be a string (not the value 'fail')
gap> LOG_TO(TmpNameAllArchs());
gap> LOG_TO(TmpName());
true
gap> CLOSE_LOG_TO();
true
Expand All @@ -25,7 +25,7 @@ gap> CLOSE_INPUT_LOG_TO();
Error, InputLogTo: can not close the logfile
gap> INPUT_LOG_TO(fail);
Error, InputLogTo: <filename> must be a string (not the value 'fail')
gap> INPUT_LOG_TO(TmpNameAllArchs());
gap> INPUT_LOG_TO(TmpName());
true
gap> CLOSE_INPUT_LOG_TO();
true
Expand All @@ -42,7 +42,7 @@ gap> CLOSE_OUTPUT_LOG_TO();
Error, OutputLogTo: can not close the logfile
gap> OUTPUT_LOG_TO(fail);
Error, OutputLogTo: <filename> must be a string (not the value 'fail')
gap> OUTPUT_LOG_TO(TmpNameAllArchs());
gap> OUTPUT_LOG_TO(TmpName());
true
gap> CLOSE_OUTPUT_LOG_TO();
true
Expand Down

0 comments on commit a55149e

Please sign in to comment.