Skip Menu |

This queue is for tickets about the XML-Compile CPAN distribution.

Report information
The Basics
Id: 92090
Status: resolved
Priority: 0/
Queue: XML-Compile

People
Owner: Nobody in particular
Requestors: mrevil [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: XML::Compile::Schema::_parseFile sometimes caches two different schema as one
Date: Mon, 13 Jan 2014 12:23:12 +0800
To: bug-XML-Compile [...] rt.cpan.org
From: Brendan Knox <mrevil [...] gmail.com>
Hi, I've encountered a small bug in the _parseFile() method when loading two schema with the same file size, mtime and basename. Caching will hit on two different files. Schema file list: #-rw-r--r-- 1 bknox bknox 455 2014-01-13 03:24 ../xmlschema/1.0/Shared.xsd #-rw-r--r-- 1 bknox bknox 455 2014-01-13 03:24 ../xmlschema/2.0/Shared.xsd Script: use XML::Compile::Schema; my $xsd1 = '../xmlschema/1.0/Shared.xsd'; my $xsd2 = '../xmlschema/2.0/Shared.xsd'; my $xcs = XML::Compile::Schema->new(); say "Importing $xsd1"; $xcs->importDefinitions( $xsd1 ); say "Loaded so far: $_" for ($xcs->namespaces->list); say "Importing $xsd2"; $xcs->importDefinitions( $xsd2 ); say "Loaded so far: $_" for ($xcs->namespaces->list); Output: Importing ../xmlschema/1.0/Shared.xsd Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd Importing ../xmlschema/2.0/Shared.xsd Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd Potential patch: --- Schema.pm 2014-01-13 04:20:29.000000000 +0000 +++ Schema.pm.fix 2014-01-13 04:20:11.000000000 +0000 @@ -16,8 +16,8 @@ use List::Util qw/first/; use XML::LibXML (); use File::Spec (); -use File::Basename qw/basename/; use Digest::MD5 qw/md5_hex/; +use Cwd (); use XML::Compile::Schema::Specs; use XML::Compile::Schema::Instance; @@ -468,7 +468,7 @@ my $self = $thing; my ($mtime, $size) = (stat $fn)[9,7]; - my $filestamp = basename($fn) . '-'. $mtime . '-' . $size; + my $filestamp = Cwd::abs_path($fn) . '-'. $mtime . '-' . $size; if($self->{_cache_file}{$filestamp}) { trace "reusing schemas from file $filestamp"; Output after patch: Importing ../xmlschema/1.0/Shared.xsd Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd Importing ../xmlschema/2.0/Shared.xsd Loaded so far: http://www.snoutlabs.net/xmlschema/1.0/Shared.xsd Loaded so far: http://www.snoutlabs.net/xmlschema/2.0/Shared.xsd Cheers, Brendan
Subject: Re: [rt.cpan.org #92090] XML::Compile::Schema::_parseFile sometimes caches two different schema as one
Date: Mon, 13 Jan 2014 09:47:43 +0100
To: Brendan Knox via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Brendan Knox via RT (bug-XML-Compile@rt.cpan.org) [140113 04:23]: Show quoted text
> Sun Jan 12 23:23:22 2014: Request 92090 was acted upon. > Transaction: Ticket created by mrevil@gmail.com > Queue: XML-Compile > Subject: XML::Compile::Schema::_parseFile sometimes caches two different schema as one > > I've encountered a small bug in the _parseFile() method when loading two > schema with the same file size, mtime and basename. Caching will hit on > two different files. > > Schema file list: > #-rw-r--r-- 1 bknox bknox 455 2014-01-13 03:24 ../xmlschema/1.0/Shared.xsd > #-rw-r--r-- 1 bknox bknox 455 2014-01-13 03:24 ../xmlschema/2.0/Shared.xsd
I expected this to be too rare to happen, but now I think of it: with different versions, the may see the same name. And when packages are installed, you may see the same time. So, it may be less rare. Show quoted text
> - my $filestamp = basename($fn) . '-'. $mtime . '-' . $size; > + my $filestamp = Cwd::abs_path($fn) . '-'. $mtime . '-' . $size;
Often I use device number and inode number for this, but that does not work on all platforms. I will use File::Spec->rel2abs for this. Good idea. -- Thanks for the patch, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Got fixed in 1.43