Re: [PATCH 1/3] Git.pm: Add faculties to allow temp files to be cached

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Junio C Hamano
Date: Wednesday, August 13, 2008 - 1:38 pm

Lea Wiemann <lewiemann@gmail.com> writes:


Ouch.  Thanks for being extra careful.

Unfortunately I've already pulled these changes via Eric.

Among the existing Perl scripts, cvsexportcommit and cvsimport already do
use it, so do svnimport and cidaemon in contrib.


Hmm, wouldn't something like this (untested) be more contained?

---
 perl/Git.pm |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 405f68f..2a92945 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -95,14 +95,26 @@ increase notwithstanding).
 
 =cut
 
+my $tmpdir;
 
 use Carp qw(carp croak); # but croak is bad - throw instead
 use Error qw(:try);
 use Cwd qw(abs_path);
 use IPC::Open2 qw(open2);
 use File::Temp ();
-require File::Spec;
 use Fcntl qw(SEEK_SET SEEK_CUR);
+
+	eval { require File::Spec; };
+	if ($@) {
+		for (@ENV{qw(TMPDIR TEMP TMP)}, "/tmp") {
+			if (test -d $_) {
+				$tmpdir = $_;
+				last;
+			}
+		}
+	} else {
+		$tmpdir = File::Spec->tmpdir;
+	}
 }
 
 
@@ -1023,7 +1035,7 @@ sub _temp_cache {
 		}
 		$$temp_fd = File::Temp->new(
 			TEMPLATE => 'Git_XXXXXX',
-			DIR => File::Spec->tmpdir
+			DIR => $tmpdir,
 			) or throw Error::Simple("couldn't open new temp file");
 		$$temp_fd->autoflush;
 		binmode $$temp_fd;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/3] git-svn and temporary file improvements, Marcus Griep, (Mon Aug 11, 8:53 am)
Re: [PATCH 1/3] Git.pm: Add faculties to allow temp files ..., Junio C Hamano, (Wed Aug 13, 1:38 pm)
[PATCH] Git.pm: require Perl 5.6.1, Lea Wiemann, (Wed Aug 13, 3:30 pm)