Closed
Bug 269813
Opened 20 years ago
Closed 19 years ago
getZip() returns open nsIZipReader
Categories
(Core :: Networking, defect)
Tracking
()
RESOLVED
FIXED
mozilla1.9alpha1
People
(Reporter: md2perpe, Assigned: asqueella)
References
()
Details
Attachments
(2 files, 1 obsolete file)
1.27 KB,
patch
|
darin.moz
:
review+
bzbarsky
:
superreview+
|
Details | Diff | Splinter Review |
816 bytes,
patch
|
asqueella
:
review+
asqueella
:
superreview+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.7.5) Gecko/20041108 Firefox/1.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.7.5) Gecko/20041108 Firefox/1.0
The documentation for nsIZipReaderCache doesn't say that getZip() returns an
*open* nsIZipReader.
Calling open() for the already opened zipreader makes every entry appear twice
in the enumerator returned by findEntries and the file isn't released (unless
the zipreader is closed twice, I suppose).
Reproducible: Always
Steps to Reproduce:
1.
2.
3.
Comment 1•19 years ago
|
||
So I guess something has to be documented here:
http://lxr.mozilla.org/seamonkey/source/modules/libjar/nsIZipReader.idl#128
Comment 2•19 years ago
|
||
Could somebody add this quick "property" of nsIZipReader to the IDL file? It took me a long time to understand why I got the entries twice! Wouldn't it be better, when the Zip is already open, to just return successfully? Something like:
RCS file: /cvsroot/mozilla/modules/libjar/nsJAR.cpp,v
retrieving revision 1.120
diff -u -r1.120 nsJAR.cpp
--- modules/libjar/nsJAR.cpp 29 Mar 2006 22:10:37 -0000 1.120
+++ modules/libjar/nsJAR.cpp 5 Apr 2006 15:39:19 -0000
@@ -213,6 +213,10 @@
NS_IMETHODIMP
nsJAR::Open()
{
+ /* if already open, nothing to do */
+ if (mFd)
+ return NS_OK;
+
nsresult rv;
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(mZipFile, &rv);
if (NS_FAILED(rv)) return rv;
Assignee | ||
Comment 3•19 years ago
|
||
Yes, the current behavior makes little sense, but we should document that the returned zip reader is already open, even if we plan to fix the double-open() issue.
Assignee: endico → asqueella
Status: NEW → ASSIGNED
Assignee | ||
Updated•19 years ago
|
Assignee: asqueella → nobody
Status: ASSIGNED → NEW
Component: Mozilla Developer → Networking
Product: Documentation → Core
QA Contact: imajes → networking
Version: unspecified → Trunk
Assignee | ||
Updated•19 years ago
|
Attachment #217841 -
Flags: superreview?(bzbarsky)
Attachment #217841 -
Flags: review?(darin)
Assignee | ||
Updated•19 years ago
|
Assignee: nobody → asqueella
Assignee | ||
Comment 4•19 years ago
|
||
Attachment #217842 -
Flags: superreview?(bzbarsky)
Attachment #217842 -
Flags: review?(darin)
![]() |
||
Comment 5•19 years ago
|
||
Comment on attachment 217841 [details] [diff] [review]
document the fact that getZip returns an open zipreader
sr=bzbarsky, but could we maybe make this behave sanely? What consumers of this do we have in our code? Where do we use the sharing?
Attachment #217841 -
Flags: superreview?(bzbarsky) → superreview+
![]() |
||
Comment 6•19 years ago
|
||
Comment on attachment 217842 [details] [diff] [review]
throw NS_ERROR_ALREADY_INITIALIZED when someone tries to open the reader twice
Is it better to do this, or to just be a no-op?
Assignee | ||
Comment 7•19 years ago
|
||
(In reply to comment #5)
> (From update of attachment 217841 [details] [diff] [review] [edit])
> sr=bzbarsky, but could we maybe make this behave sanely? What consumers of
> this do we have in our code? Where do we use the sharing?
>
I think we use sharing only in nsJARChannel, nsXPTZipLoader, and nsChromeRegistry (rdf/chrome version). I think this should be treated as a "private" interface with all consumers being careful about shared zipreaders. (Is there a way to enforce the "privateness" of the interface?)
> Is it better to do this, or to just be a no-op?
I made it throw for because I don't think it's useful to be able to open the reader twice, it is impossible currently, and the problem of opening a zipreader twice, closing it once, then trying to use it will be easier to catch. Did I miss something and it's better to make this return NS_OK?
![]() |
||
Comment 8•19 years ago
|
||
> (Is there a way to enforce the "privateness" of the interface?)
Make it noscript?
That said, people are clearly using it; which part do you feel should be private?
> and the problem of opening a zipreader twice, closing it once, then trying to
> use it will be easier to catch.
Ah, good point. Ok, that makes the throw solution better. ;)
![]() |
||
Updated•19 years ago
|
Attachment #217842 -
Flags: superreview?(bzbarsky) → superreview+
Comment 9•19 years ago
|
||
I think we should fix nsIZipReaderCache to return some proxy object that does the right thing when open or close are called. It should not be possible to call getZip and get a closed nsIZipReader instance.
Assignee | ||
Comment 10•19 years ago
|
||
(In reply to comment #8)
> That said, people are clearly using it; which part do you feel should be
> private?
Oops, I didn't think of the people who use it already. It's just that the whole nsIZipReaderCache thing seemed to me an optimization of our chrome-loading mechanism (JAR channels in particular). Is it really useful as a part of the platform? I don't think so.
This is also the reason I don't think additional complexity should be added to this code. If you feel this should be a robust public component, I can file a separate bug for Darin's suggestion in comment 9.
Comment 11•19 years ago
|
||
The whole jar nsZipReaderCache/jarCache thing is not really working optimally.
nsChromeRegistry creates its own instance just to test for existance of entries (using 'GetZip / GetEntry') nsJARChannel uses its own jarCache to cache all channel requests for a jar entry or for a directory entry.
This results in two separate caches.
See also bug 333202 where there is also some suspicion on the working of the cache.
Why not define a new servie (say 'JarStreamFactory') which can be queried with: 'ContainsEntry(jarname, entryname)', 'GetJarInputStream(jarname, entryname)', 'GetJarDirStream(jarname, entryname)'.
This allows that service to manage a cache of 'ZipReader' at will (on demand, as we say it... ;-)), without exposing these 'internal) ZipReaders to others to misuse. It also allows for more flexible cache mechanism's, for example to use a timer to close any zipreader not used for more than a certain period (see nsRecyclingAllocator...)
Bij keeping the existing nsIZipReader, one can still directly manipulate zipfile directly.
This is all more work and more impact than this bug intended, so possibly something for a new bug, and close this one as 'fixed' with the extra comment and check?
Comment 12•19 years ago
|
||
Alfred: I like your suggestion. If you'd be willing to help spearhead that (after your current libjar patch lands), that'd be awesome.
Comment 13•19 years ago
|
||
Two more notes:
1. Currently the libjar code assumes that the ZipReader remains open as long as the JarInputStream is open. So closing the first before the second is finished WILL crash! See bug 214672!
2. The new setup will also allow to forcely clear the jarcache (whilst allowing the streams to continue, see above) in case of memory shortage or in case of switching themes or so (as long as the old file remains existing, renamed, then reading will not fail).
Updated•19 years ago
|
Attachment #217841 -
Flags: review?(darin) → review+
Comment 14•19 years ago
|
||
Comment on attachment 217842 [details] [diff] [review]
throw NS_ERROR_ALREADY_INITIALIZED when someone tries to open the reader twice
NS_ENSURE_TRUE(!mFD, NS_ERROR_ALREADY_INITIALIZED) would be even better.
Attachment #217842 -
Flags: review?(darin) → review+
Assignee | ||
Comment 15•19 years ago
|
||
Right. Carrying reviews over.
Attachment #217842 -
Attachment is obsolete: true
Attachment #218064 -
Flags: superreview+
Attachment #218064 -
Flags: review+
Updated•19 years ago
|
Whiteboard: [checkin needed]
Comment 16•19 years ago
|
||
Both attachment 217841 [details] [diff] [review] and attachment 218064 [details] [diff] [review] need to be checked in, right?
Assignee | ||
Comment 17•19 years ago
|
||
> Both attachment 217841 [details] [diff] [review] [edit] and attachment 218064 [details] [diff] [review] [edit] need to be checked in, right?
Yes, please.
Comment 18•19 years ago
|
||
Checking in nsIZipReader.idl;
/cvsroot/mozilla/modules/libjar/nsIZipReader.idl,v <-- nsIZipReader.idl
new revision: 1.19; previous revision: 1.18
done
Checking in modules/libjar/nsJAR.cpp;
/cvsroot/mozilla/modules/libjar/nsJAR.cpp,v <-- nsJAR.cpp
new revision: 1.121; previous revision: 1.120
done
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
Target Milestone: --- → mozilla1.9alpha
You need to log in
before you can comment on or make changes to this bug.
Description
•