Closed
Bug 72129
Opened 25 years ago
Closed 25 years ago
nsLocalFile::OpenANSIFileDesc() won't create new files
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
mozilla0.9
People
(Reporter: beard, Assigned: ccarlen)
Details
(Whiteboard: need status update. needed for 0.8.1??)
Attachments
(2 files)
|
1.48 KB,
patch
|
Details | Diff | Splinter Review | |
|
1.56 KB,
patch
|
Details | Diff | Splinter Review |
If I call nsLocalFile::OpenANSIFileDesc() with mode = "wb", and the file doesn't
exist, the file doesn't get created. The problem is that mTargetSpec is invalid
if the file doesnt' exist. Here's a patch that fixes the problem.
Index: mozilla/xpcom/io/nsLocalFileMac.cpp
===================================================================
RCS file: /cvsroot/mozilla/xpcom/io/nsLocalFileMac.cpp,v
retrieving revision 1.55
diff -b -u -2 -r1.55 nsLocalFileMac.cpp
--- nsLocalFileMac.cpp 2001/03/02 09:26:45 1.55
+++ nsLocalFileMac.cpp 2001/03/15 23:26:06
@@ -1098,15 +1098,5 @@
return rv;
-
- // Resolve the alias to the original file.
- FSSpec spec = mTargetSpec;
- Boolean targetIsFolder;
- Boolean wasAliased;
- OSErr err = ::ResolveAliasFile(&spec, TRUE, &targetIsFolder, &wasAliased);
- if (err != noErr)
- return MacErrorMapper(err);
-
-
- *_retval = FSp_fopen(&spec, mode);
+ *_retval = FSp_fopen(&mResolvedSpec, mode);
if (*_retval)
| Reporter | ||
Comment 1•25 years ago
|
||
The new disk cache needs this to work.
Severity: normal → blocker
Target Milestone: --- → mozilla0.8.1
| Assignee | ||
Updated•25 years ago
|
Status: NEW → ASSIGNED
| Assignee | ||
Comment 3•25 years ago
|
||
mTargetSpec should be valid even if the file doesn't exist (the leaf anyway). I
think the problem is in OpenANSIFileDesc():
OSErr err = ::ResolveAliasFile(&spec, TRUE, &targetIsFolder, &wasAliased);
if (err != noErr)
return MacErrorMapper(err);
If the leaf doesn't exist, ResolveAliasFile will return -43 which means the spec
is valid but this method will die on that.
Should be: if (err != noErr && err != fnfErr)
I think we should resolve aliases in this method but using mResolvedSpec instead
of mTargetSpec, we won't.
| Assignee | ||
Comment 4•25 years ago
|
||
Hmm, on second thought, if more than the leaf does not exist, calling
ResolveAndStat won't do the job. It's no going to create missing dirs in the
path. For any kind of "w" permission, OpenANSIFileDesc() should check for
existence and, if not, call Create(). That will work whether the leaf or most of
the path does not exist.
Comment 5•25 years ago
|
||
do we need this for 0.8.1 or just for the 0.9 landing of cache next week.
lets set the milestone appropriately..
Whiteboard: need status update. needed for 0.8.1??
Target Milestone: mozilla0.8.1 → mozilla0.9
| Reporter | ||
Comment 6•25 years ago
|
||
This needs to be fixed to land the new cache.
| Assignee | ||
Comment 7•25 years ago
|
||
I'll have a patch shortly...
| Assignee | ||
Comment 8•25 years ago
|
||
| Assignee | ||
Comment 9•25 years ago
|
||
This patch does the complete job. If we are opening with write access, it
ensures the the whole file path as well as the leaf exists first. Also, if we
create the file, we get to do our suffix->file type/creator stuff. If we let
StdCLib do it, we just get a CW text file.
Comment 10•25 years ago
|
||
Is it good to test like this?
+ if (mode[0] == 'w')
Can people open files with "wb" as well as "bw"? I'm not sure if order matters.
| Reporter | ||
Comment 11•25 years ago
|
||
Take a look at int __get_file_modes(const char * mode, __file_modes * modes) in
file_io.c in MSL. It seems to assume that if the mode starts with 'r', then the
file must exist. But if it starts with 'w' or 'a' then the file needs to be
created automatically. However, we don't need to do this in nsLocalFileMac,
FSp_fopen() will take care of it. Of course, if we create it, then we get a
chance to put our creator/type imprint on it. Ideally, if we open the file using
a binary mode, it shouldn't have a type of 'TEXT', otherwise it should
| Reporter | ||
Comment 12•25 years ago
|
||
Re-reading Conrad's last comment, yes, using extension mapping is good here, but
also looking at the mode "wb" vs. "w" should use a different file type if
possible.
| Assignee | ||
Comment 13•25 years ago
|
||
> Take a look at int __get_file_modes
That's where I just was :-)
> looking at the mode "wb" vs. "w" should use a different file type if possible.
I'll look at this.
| Assignee | ||
Comment 14•25 years ago
|
||
For consistency's sake, we should let Create() be able to determine the type and
creator given the file's suffix. But, for the case of a file with no suffix,
that will have no effect. I say we initialize mType based on the access mode
right before calling Create():
mType = (mode[1] == 'b') ? 'BiNA' : 'TEXT';
Then, if the suffix -> type/creator stuff can come up with better info, great.
But, we'll be initialized to better defaults if not.
'BiNA' I chose by looking in our bundle... Any better types?
Comment 15•25 years ago
|
||
'BiNA' is good. That was intended for random binary files.
| Assignee | ||
Comment 16•25 years ago
|
||
Patrick, Simon - Can I get review on this so I can get it in before the cache?
Comment 17•25 years ago
|
||
sr=sfraser
| Reporter | ||
Comment 18•25 years ago
|
||
I don't see a new patch which reflects our last comments, such as mode == "a"? Or
the decision about the creator and type?
| Assignee | ||
Comment 19•25 years ago
|
||
| Assignee | ||
Comment 20•25 years ago
|
||
Here's a new patch in which the type defaults to 'BiNA' for files opened with
"b" and "TEXT" otherwise. This is just default. If Create() can find a better
type/creator, it still will. Also, the file is checked or existence for "a" as
well as "w" mode.
| Reporter | ||
Comment 21•25 years ago
|
||
r=beard
| Assignee | ||
Comment 22•25 years ago
|
||
Fix checked in.
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
•