Closed
Bug 300692
Opened 20 years ago
Closed 13 years ago
Win32 nsLocalFile::Create returns not found if no access and a directory hierarchy is needed
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
mozilla9
People
(Reporter: robert.strong.bugs, Assigned: bbondy)
References
Details
Attachments
(1 file, 1 obsolete file)
(deleted),
patch
|
bbondy
:
review+
|
Details | Diff | Splinter Review |
Here it is:
http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsLocalFileWin.cpp#762
This appears to affect nsIFile.createUnique in that if access is denied it
thinks a file already exists and then tries to create the file 10,000 times
before giving up.
Reporter | ||
Comment 1•20 years ago
|
||
This came to light in bug 300265
Comment 2•20 years ago
|
||
FWIW, I changed the return to use ConvertWinError, and createUnique started
behaving much more sensibly (though I found one odd side-effect[1]), but
obviously all call sites would need to be carefully checked for how they handle
the return code.
[1] If the "Access Privileges Test" file exists when createUnique tries to test
it, and the user has permission to delete it... it deletes it! I assume this is
because it got an unexpected error, and assumed it had worked, and that it was
ok to delete the file. Oops.
Updated•20 years ago
|
Assignee: file-handling → dougt
Component: File Handling → XPCOM
QA Contact: ian → xpcom
Comment 3•20 years ago
|
||
line 763 seams very broken. Don't we want something like:
PRFileDesc* file = PR_Open(mResolvedPath.get(), PR_RDONLY | PR_CREATE_FILE |
PR_APPEND | PR_EXCL, attributes);
if (file) {
PR_Close(file);
return NS_ERROR_FILE_ALREADY_EXISTS;
}
Reporter | ||
Comment 4•20 years ago
|
||
I would think we'd want the return value from ConvertWinError as is used when
creating a directory since this won't properly handle when access is denied. As
was pointed out it appears that not all call sites properly handle a return of a
value other than NS_ERROR_FILE_ALREADY_EXISTS.
Assignee | ||
Comment 6•13 years ago
|
||
I tested this and the only time it returns that value is if the file does already exist. I think this is expected behaviour and this bug was fixed somewhere along the line. I'd like to nominate that we resolve this as invalid.
Reporter | ||
Comment 7•13 years ago
|
||
It was returning NS_ERROR_FILE_ALREADY_EXISTS when failing to create the file. For example, in bug 300265 (see comment #1) this was happening when trying to write to a read only share. If this has been fixed since this bug was filed then YAY!
Assignee | ||
Comment 8•13 years ago
|
||
ah ok I'll check, thanks for the info.
Assignee | ||
Comment 9•13 years ago
|
||
For writing a file to a read only share we return:
NS_ERROR_FILE_ACCESS_DENIED which is correct.
When we create a file with a directory hierarchy that doesn't exist though, we usually create the whole directory hierarchy.
For writing a file to a read only share that has a directory that doesn't exist, this returns NS_ERROR_FILE_NOT_FOUND. So in that case NS_ERROR_FILE_ACCESS_DENIED should be used.
Assignee | ||
Updated•13 years ago
|
Assignee: nobody → netzen
Assignee | ||
Updated•13 years ago
|
Summary: Win32 nsIFile.create always returns NS_ERROR_FILE_ALREADY_EXISTS → Win32 nsLocalFile::Create returns already exists if no access and a directory hierarchy is needed
Assignee | ||
Updated•13 years ago
|
Summary: Win32 nsLocalFile::Create returns already exists if no access and a directory hierarchy is needed → Win32 nsLocalFile::Create returns not found if no access and a directory hierarchy is needed
Assignee | ||
Updated•13 years ago
|
Assignee | ||
Comment 10•13 years ago
|
||
So the problem is, if you have an empty read only share:
\\computername\myshare
And you try to do something like create a file inside a subfolder:
\\computername\myshare\1\2\3\file.txt
Then the first create directory returns access denied, which keeps going trying to create the other directories.
But the others return file not found and return at that point.
The real error is that access is denied though not that the directory doesn't exist.
Attachment #556265 -
Flags: review?(benjamin)
Assignee | ||
Comment 11•13 years ago
|
||
Example code you can run to reproduce:
var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("\\\\rhesus\\readonlyshare\\1\\2\\3\\test.txt");
file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0777);
Comment 12•13 years ago
|
||
Comment on attachment 556265 [details] [diff] [review]
Patch for wrong error code when access denied on Create operations
>diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp
>+ nsresult directoryCreateError = 0;
This should be NS_OK;
> if (slash)
> {
> // skip the first '\\'
> ++slash;
> slash = wcschr(slash, L'\\');
>
> while (slash)
> {
> *slash = L'\0';
>
> if (!::CreateDirectoryW(mResolvedPath.get(), NULL)) {
> rv = ConvertWinError(GetLastError());
>+ if (rv == NS_ERROR_FILE_NOT_FOUND &&
>+ directoryCreateError == NS_ERROR_FILE_ACCESS_DENIED) {
>+ // If a previous CreateDirectory failed due to access, return that.
>+ return NS_ERROR_FILE_ACCESS_DENIED;
>+ }
As a style nit, it would be better to put the constant on the left side of the ==, i.e.:
if (NS_ERROR_FILE_NOT_FOUND == rv &&
NS_ERROR_FILE_ACCESS_DENIED == directoryCreateError)
That way any accidentally mistyped "=" become compile errors. But since the surrounding code doesn't use that style currently, I won't insist on it.
Attachment #556265 -
Flags: review?(benjamin) → review+
Assignee | ||
Comment 13•13 years ago
|
||
Fixed coding style on if conditions and NS_OK instead of 0.
Attachment #556265 -
Attachment is obsolete: true
Assignee | ||
Updated•13 years ago
|
Attachment #557006 -
Flags: review+
Assignee | ||
Comment 14•13 years ago
|
||
Assignee | ||
Comment 15•13 years ago
|
||
Pushed to inbound:
http://hg.mozilla.org/integration/mozilla-inbound/rev/65f0640bf316
Comment 16•13 years ago
|
||
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla9
You need to log in
before you can comment on or make changes to this bug.
Description
•