Thread (41 messages) flat view 41 messages, 4 authors, 2016-06-15

[PATCHv5 12/17] gitweb/lib - No need for File::Temp when locking

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:49:43
Subsystem: the rest · Maintainer: Linus Torvalds

When using locking to ensure that only one process is generating data
and updating cache, there is no need to use File::Temp for temporary
file.  This should improve performance.

Signed-off-by: Jakub Narebski <redacted>
---
This patch was not present in previous v4 version of this series.  It
brings this solution closer to the one in J.H. patch, because with
locking it does not use File::Temp; the locking is safety enough by
itself.

 gitweb/lib/GitwebCache/FileCacheWithLocking.pm |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/gitweb/lib/GitwebCache/FileCacheWithLocking.pm b/gitweb/lib/GitwebCache/FileCacheWithLocking.pm
index c91c0ee..e69047e 100644
--- a/gitweb/lib/GitwebCache/FileCacheWithLocking.pm
+++ b/gitweb/lib/GitwebCache/FileCacheWithLocking.pm
@@ -38,6 +38,22 @@ sub get_lockname {
 	return $self->path_to_key(@_) . '.lock';
 }
 
+# ----------------------------------------------------------------------
+# "private" utility functions and methods
+
+# take a file path to cache entry, and its directory
+# return filehandle and filename of open temporary file,
+# like File::Temp::tempfile
+sub _tempfile_to_path {
+	my ($file, $dir) = @_;
+
+	my $tempname = "$file.tmp";
+	open my $temp_fh, '>', $tempname
+		or die "Couldn't open temporary file '$tempname' for writing: $!";
+
+	return ($temp_fh, $tempname);
+}
+
 # ......................................................................
 # interface methods
 
-- 
1.7.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help