mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1443651
: Don't return failure for access denied from createUnique() if file exists. r=Mossop
There are ways for Create() to return access denied for files which already exist, particularly in the case of locked files. When it does, createUnique() should check whether the file exists before considering the attempt a failure. MozReview-Commit-ID: FyJTghk04jH --HG-- extra : rebase_source : 10e6f2cb7da18e8e6d410b52a593b7455f0d76fa
This commit is contained in:
parent
2faddce683
commit
afc3918d22
@ -61,11 +61,19 @@ nsLocalFile::CreateUnique(uint32_t aType, uint32_t aAttributes)
|
||||
return rv;
|
||||
}
|
||||
|
||||
auto FailedBecauseExists = [&] (nsresult aRv) {
|
||||
if (aRv == NS_ERROR_FILE_ACCESS_DENIED) {
|
||||
bool exists;
|
||||
return NS_SUCCEEDED(Exists(&exists)) && exists;
|
||||
}
|
||||
return aRv == NS_ERROR_FILE_ALREADY_EXISTS;
|
||||
};
|
||||
|
||||
longName = (pathName.Length() + kMaxSequenceNumberLength >
|
||||
kMaxFilenameLength);
|
||||
if (!longName) {
|
||||
rv = Create(aType, aAttributes);
|
||||
if (rv != NS_ERROR_FILE_ALREADY_EXISTS) {
|
||||
if (!FailedBecauseExists(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@ -128,7 +136,7 @@ nsLocalFile::CreateUnique(uint32_t aType, uint32_t aAttributes)
|
||||
SetNativeLeafName(rootName + suffix);
|
||||
#endif
|
||||
nsresult rvCreate = Create(aType, aAttributes);
|
||||
if (rvCreate != NS_ERROR_FILE_ALREADY_EXISTS) {
|
||||
if (!FailedBecauseExists(rvCreate)) {
|
||||
return rvCreate;
|
||||
}
|
||||
}
|
||||
@ -143,7 +151,7 @@ nsLocalFile::CreateUnique(uint32_t aType, uint32_t aAttributes)
|
||||
SetNativeLeafName(rootName + nsPrintfCString("-%d", indx) + suffix);
|
||||
#endif
|
||||
rv = Create(aType, aAttributes);
|
||||
if (NS_SUCCEEDED(rv) || rv != NS_ERROR_FILE_ALREADY_EXISTS) {
|
||||
if (NS_SUCCEEDED(rv) || !FailedBecauseExists(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user