Re: [PATCH 12/18] gitweb: Change file handles (in caching) to lexical variables as opposed to globs
From: Jakub Narebski <hidden>
Date: 2016-06-15 22:50:13
"John 'Warthog9' Hawley" [off-list ref] writes:
quoted hunk ↗ jump to hunk
This isn't a huge change, it just adds global variables for the file handles, an additional cleanup to localize the variable a bit more which should alleviate the issues that Jakub had with my original approach. Signed-off-by: John 'Warthog9' Hawley <warthog9@eaglescrag.net> --- gitweb/lib/cache.pl | 114 +++++++++++++++++++++++++++++++------------------- 1 files changed, 71 insertions(+), 43 deletions(-)diff --git a/gitweb/lib/cache.pl b/gitweb/lib/cache.pl index 5182a94..fafc028 100644 --- a/gitweb/lib/cache.pl +++ b/gitweb/lib/cache.pl@@ -14,6 +14,12 @@ use Digest::MD5 qw(md5 md5_hex md5_base64); use Fcntl ':flock'; use File::Copy; +# Global declarations +our $cacheFile; +our $cacheFileBG; +our $cacheFileBinWT; +our $cacheFileBin;
You are trading globs for global (well, package) variables. They are not lexical filehandles... though I'm not sure if it would be possible without restructuring code; note that if variable holding filehandle falls out of scope, then file would be automatically closed. BTW. Do you really need all those types/variables?
quoted hunk ↗ jump to hunk
+ sub cache_fetch { my ($action) = @_; my $cacheTime = 0;@@ -49,9 +55,9 @@ sub cache_fetch { }else{ #if cache is out dated, update #else displayCache(); - open(cacheFile, '<', "$fullhashpath"); - stat(cacheFile); - close(cacheFile); + open($cacheFile, '<', "$fullhashpath"); + stat($cacheFile); + close($cacheFile);
[...] -- Jakub Narebski Poland ShadeHawk on #git