Closed
Bug 81927
Opened 25 years ago
Closed 25 years ago
nsIFile isSymlink() is broken [PATCH]
Categories
(Core :: XPCOM, defect, P3)
Tracking
()
RESOLVED
FIXED
mozilla0.9.3
People
(Reporter: pete, Assigned: pete)
Details
Attachments
(3 files)
|
584 bytes,
patch
|
Details | Diff | Splinter Review | |
|
582 bytes,
patch
|
Details | Diff | Splinter Review | |
|
623 bytes,
patch
|
Details | Diff | Splinter Review |
nsIFile isSymlink() is broken.
Attaching patch
--pete
| Assignee | ||
Updated•25 years ago
|
Summary: nsIFile isSymlink() si broken → nsIFile isSymlink() is broken [PATCH]
| Assignee | ||
Comment 1•25 years ago
|
||
| Assignee | ||
Comment 2•25 years ago
|
||
Output of test to verify fix:
js> var p='/tmp/foo_link';
js> const File=new Components.Constructor("@mozilla.org/file/local;1",
"nsILocalFile");
js> var f=new File();
js> f.initWithPath(p);
js> f.exists();
true
js> f.path;
/tmp/foo_link
js> f.isSymlink();
true
js> p='/tmp/foo';
/tmp/foo
js> f.initWithPath(p);
js> f.exists();
true
js> f.path;
/tmp/foo
js> f.isSymlink();
false
js>
| Assignee | ||
Comment 3•25 years ago
|
||
This method has been broken for as long as i can remember.
The problem it seems that in order for S_ISLNK() to work, you need to initialize
the stat struct w/ lstat() not stat.
--pete
| Assignee | ||
Updated•25 years ago
|
Wouldn't it be better to redefine S_ISLNK? For example, look at isSpecial just
below isSymlink.
I suggest extreme caution here. You generally do NOT want to know if a file is
a symlink.
| Assignee | ||
Comment 5•25 years ago
|
||
> wouldn't it be better to redefine S_ISLNK? For example, look at isSpecial just
> below isSymlink.
S_ISLNK is a stdlib call which looks like it is being used wrong in isSpecial.
!S_ISLNK(mCachedStat.st_mode)
This will never return true if initialized w/ stat() instead of lstat()
> I suggest extreme caution here. You generally do NOT want to know if a file is
> a symlink.
I'm not sure i understand? There is a member method called isSymlink() which
returns a bool based on if the file is a symlink or not.
It is broken. This patch fixes it . . .
What is there to be cautionary about a method that is specifically designed to
inform if the file is a symlink or not?
--pete
I thought mozilla had redefined S_ISLNK somewhere. I guess I'm wrong.
What concerns me is that the procedure in IsSymlink will be replicated
in other places in teh code where it will, almost always, be the wrong
thing to do. Look at the IsSpecial method just below IsSymlink. the
S_ISLNK test doesn't belong there at all. You care whether the link
target is a special file, not the link itself.
Would you consider adding a comment in the code about why IsSymlink is
special?
I'll file another bug about IsSpecial.
| Assignee | ||
Comment 7•25 years ago
|
||
I think ::IsSpecial should be implemented something like this:
NS_IMETHODIMP
nsLocalFile::IsSymlink(PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
VALIDATE_STAT_CACHE();
CHECK_mPath();
struct stat symStat;
lstat(mPath, &symStat);
*_retval=S_ISLNK(symStat.st_mode);
return NS_OK;
}
I can post that patch if you open up another bug.
--pete
| Assignee | ||
Comment 8•25 years ago
|
||
Duh, sorry
like this:
NS_IMETHODIMP
nsLocalFile::IsSpecial(PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
VALIDATE_STAT_CACHE();
CHECK_mPath();
struct stat symStat;
lstat(mPath, &symStat);
*_retval = !S_ISLNK(symStat.st_mode) &&
!S_ISREG(mCachedStat.st_mode) &&
!S_ISDIR(mCachedStat.st_mode);
return NS_OK;
}
I filed bug 82205 on IsSpecial but I took a completely opposite approach to
yours. Feel free to call me an idiot.
Comment 10•25 years ago
|
||
Thanks for the patch. It appears to be a simple fix, though I do not know this
code, nor why it did not work in the first place. Is there a way within the
product to verify that this works? Is there code that depends on this being
"broken"? Thanks.
Status: NEW → ASSIGNED
| Assignee | ||
Comment 11•25 years ago
|
||
> Is there a way within the product to verify that this works?
I posted the output of a js test that validates the fix.
Just run it in xpcshell youself to verify . . .
> Is there code that depends on this being "broken"?
Heh, i guess a search in lxr would show you client code using this method.
--pete
| Assignee | ||
Comment 12•25 years ago
|
||
| Assignee | ||
Comment 13•25 years ago
|
||
| Assignee | ||
Comment 14•25 years ago
|
||
you can assign this bug to me if you want, i will be maintaining this patch
--pete
Priority: -- → P3
Target Milestone: --- → mozilla0.9.3
| Assignee | ||
Comment 15•25 years ago
|
||
This patch still works and doesn't need updating
--pete
| Assignee | ||
Comment 16•25 years ago
|
||
Taking bug.
--pete
Assignee: kandrot → petejc
Status: ASSIGNED → NEW
| Assignee | ||
Updated•25 years ago
|
Status: NEW → ASSIGNED
Comment 17•25 years ago
|
||
r=blizzard
Comment 18•25 years ago
|
||
sr=jst
| Assignee | ||
Comment 19•25 years ago
|
||
checked in this mornng. Marking fixed.
--pete
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•