Closed
Bug 442401
Opened 16 years ago
Closed 16 years ago
nsILocalFile::IsPackage does not consider a keynote bundle (.key) to be a package
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: hwaara, Assigned: hwaara)
References
Details
Attachments
(2 files, 5 obsolete files)
938 bytes,
patch
|
Details | Diff | Splinter Review | |
135.24 KB,
patch
|
roc
:
superreview+
|
Details | Diff | Splinter Review |
The implementation of IsPackage is really hacky. It does not consider a keynote package to be a package, for example. It works on apps because it's cheating and checking for the ".app" suffix. The reason is that we're using a bad API that, from what I understand, only checks if the bundle bit of a file - which may or may not be set. This is a widely known problem (see for example http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-11/2075.html). There are two ways to do this correctly: 1) Use Carbon and Launch Services. All Apple sample code that wants to find out if a file/folder is a package, uses LSCopyItemInfoForRef() and checks if the kLSItemInfoIsPackage bit is set. (Example: http://developer.apple.com/technotes/tn/tn2017.html#Section6) 2) Simply use NSWorkspace and isFilePackageAtPath:(NSString *)path I've tried both approaches and both solve the problem. #2 is much neater and simpler, and since we're moving in the direction of Cocoafying these implementations anyway, I prefer it.
Assignee | ||
Comment 1•16 years ago
|
||
Here's approach number one, for reference.
Assignee | ||
Comment 2•16 years ago
|
||
Approach #2 which uses Cocoa. This is slick. Requesting review on this one, and would like to get it into mozilla-central.
Attachment #327201 -
Flags: review?(joshmoz)
Assignee | ||
Comment 3•16 years ago
|
||
I'm gonna be away for a while, but I've been thinking about also providing a unit test which would include a (small) .key file that it could check for package-ness. Does that sound reasonable?
Assignee | ||
Comment 4•16 years ago
|
||
roc or bsmedberg, is there someone else that can review the patch (Approach #2) above? I hear that josh is really busy, and the patch has been sitting for one and a half month... nsILocalFile::IsPackage is basically broken, and the fix is really simple, because we defer all work to Cocoa.
Assignee | ||
Comment 5•16 years ago
|
||
Comment on attachment 327200 [details] [diff] [review] Approach #1: Use Carbon (ugh) and Launch Services Because I strongly doubt anyone wants this Carbon approach, I'm gonna mark it obsolete. It's mainly attached for comparison's sake.
Attachment #327200 -
Attachment is obsolete: true
Attachment #327201 -
Flags: superreview+
Attachment #327201 -
Flags: review?(joshmoz)
Attachment #327201 -
Flags: review+
Assignee | ||
Updated•16 years ago
|
Attachment #327201 -
Flags: superreview+ → superreview?(benjamin)
Assignee | ||
Comment 6•16 years ago
|
||
Here's also a xpcshell testcase for this bug. Feel free to review. I've added a new directory "data" in xpcom/tests/unit with two bundles to be used as resources for this test: * "dummy.app" which is a minimal mac application * "presentation.key" which is a minimal Keynote presentation The keynote presentation fails to be recognized as a bundle without my fix.
Assignee: nobody → hwaara
Status: NEW → ASSIGNED
Assignee | ||
Comment 7•16 years ago
|
||
Comment on attachment 327201 [details] [diff] [review] Approach #2: Use Cocoa Josh, please have a look. I'm using NSWorkspace's isFilePackageAtPath: which will correctly determine bundleness for us. I already attached xpcshell a testcase that with this patch will pass.
Attachment #327201 -
Flags: superreview?(benjamin) → superreview?(joshmoz)
Comment on attachment 327201 [details] [diff] [review] Approach #2: Use Cocoa The old code used "GetFSRefInternal" to get the path in the form of an FSRef. Obviously we don't want an FSRef but part of what that function did is resolve filesystem links like this: CFURLRef whichURLRef = mFollowLinks ? mTargetRef : mBaseRef; Your new code uses mBaseRef every time. Please fix this or explain why you think what you're doing is right.
Attachment #327201 -
Flags: superreview?(joshmoz)
Assignee | ||
Comment 9•16 years ago
|
||
Good point. So this is about the nsILocalFile attribute "followLinks" which determines if some nsILocalFile[Mac] APIs should work on the file at hand, or - if it is an alias - on the target of that alias. I can make it work on the target, like the old version.
Assignee | ||
Comment 10•16 years ago
|
||
This one also follows links.
Attachment #327201 -
Attachment is obsolete: true
Attachment #333201 -
Flags: review?(joshmoz)
Comment 11•16 years ago
|
||
Comment on attachment 333201 [details] [diff] [review] Patch v1.1: also support mac aliases + ::CFURLCopyFileSystemPath((mFollowLinks ? mTargetRef : mBaseRef), kCFURLPOSIXPathStyle); Are you sure you don't need to null check mTargetRef or mBaseRef?
Assignee | ||
Comment 12•16 years ago
|
||
> Are you sure you don't need to null check mTargetRef or mBaseRef?
Good call.
This patch also checks both mBaseRef and mTargetRef for null-ness before using any of them.
Attachment #333201 -
Attachment is obsolete: true
Attachment #334123 -
Flags: review?(joshmoz)
Attachment #333201 -
Flags: review?(joshmoz)
Comment 13•16 years ago
|
||
Comment on attachment 334123 [details] [diff] [review] Patch v1.2 + CFURLRef whichURLRef = (mFollowLinks && mTargetRef) ? mTargetRef : mBaseRef; I think you should return an error if mFollowLinks is true but there is no mTargetRef rather potentially targeting the wrong file (mBaseRef) in that error condition. Maybe you should just use the existing nsLocalFile::GetCFURL. If you do that be sure to release the result as GetCFURL retains.
Assignee | ||
Comment 14•16 years ago
|
||
This patch uses GetCFURL instead, which further simplifies the code. I could also convert the ugly CF API call to get the URL's path as a string to a simple objc message because NSURL and CFURLRef are toll-free bridged.
Attachment #334123 -
Attachment is obsolete: true
Attachment #335299 -
Flags: review?(joshmoz)
Attachment #334123 -
Flags: review?(joshmoz)
Attachment #335299 -
Flags: superreview?(roc)
Attachment #335299 -
Flags: review?(joshmoz)
Attachment #335299 -
Flags: review+
Comment 15•16 years ago
|
||
Comment on attachment 335299 [details] [diff] [review] Patch v1.5 The r+ applies to the part of the patch you meant to include - you accidentally included a whole bunch of other stuff. Please post a new patch without the extra stuff and then request sr.
Attachment #335299 -
Flags: superreview?(roc)
Assignee | ||
Comment 16•16 years ago
|
||
(In reply to comment #15) > (From update of attachment 335299 [details] [diff] [review]) > The r+ applies to the part of the patch you meant to include - you accidentally > included a whole bunch of other stuff. Please post a new patch without the > extra stuff and then request sr. The extra stuff are testcase resources: * one sample application ("dummy.app") * one sample keynote file ("presentation.key") these are used in the testcase as bundles that are checked. They can also be reused in the future in other mac xpcom testcases if needed (for example, a testcase for opening apps? or testing whether an nsIFile (dummy.app) is executable?).
Is dummy.app/Contents/Resources/English.lproj/MainMenu.nib/designable.nib really as small as it can be? If there's an easy way to shrink it, let's do that.
Assignee | ||
Comment 18•16 years ago
|
||
I managed to cut the size of the binary by around ~100K by removing all resources possible in it (menus etc). Is that alright?
Attachment #335299 -
Attachment is obsolete: true
Attachment #335496 -
Flags: superreview?(roc)
Comment on attachment 335496 [details] [diff] [review] Patch v2 That'll do. If there was a way to shrink the Keynote file, I'd do that too, but this is OK as is.
Attachment #335496 -
Flags: superreview?(roc) → superreview+
Assignee | ||
Comment 20•16 years ago
|
||
Pushed eb9386fca111 and f400cbec8311 for a fixup of the test.
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•