Bug 1751840 - Make nsLocalFileWin::Equals compare long names before trying 8.3 names. r=bobowen

Differential Revision: https://phabricator.services.mozilla.com/D137339
This commit is contained in:
Masatoshi Kimura 2022-02-19 12:37:10 +00:00
Родитель 790bca80ca
Коммит 97d32e6c03
1 изменённых файлов: 42 добавлений и 26 удалений

Просмотреть файл

@ -2999,43 +2999,59 @@ nsLocalFile::Equals(nsIFile* aInFile, bool* aResult) {
return NS_ERROR_INVALID_ARG;
}
EnsureShortPath();
nsCOMPtr<nsILocalFileWin> lf(do_QueryInterface(aInFile));
if (!lf) {
*aResult = false;
return NS_OK;
}
nsAutoString inFilePath;
lf->GetCanonicalPath(inFilePath);
bool inUseDOSDevicePathSyntax;
lf->GetUseDOSDevicePathSyntax(&inUseDOSDevicePathSyntax);
// Remove the prefix for both inFilePath and mShortWorkingPath if the
// useDOSDevicePathSyntax from them are not the same.
// This is added because of Omnijar. It compare files from different moduals
// with itself
nsAutoString shortWorkingPath;
if (inUseDOSDevicePathSyntax == mUseDOSDevicePathSyntax) {
shortWorkingPath = mShortWorkingPath;
} else if (inUseDOSDevicePathSyntax &&
StringBeginsWith(inFilePath, kDevicePathSpecifier)) {
MOZ_ASSERT(!StringBeginsWith(mShortWorkingPath, kDevicePathSpecifier));
shortWorkingPath = mShortWorkingPath;
inFilePath = Substring(inFilePath, kDevicePathSpecifier.Length());
} else if (mUseDOSDevicePathSyntax &&
StringBeginsWith(mShortWorkingPath, kDevicePathSpecifier)) {
MOZ_ASSERT(!StringBeginsWith(inFilePath, kDevicePathSpecifier));
shortWorkingPath =
Substring(mShortWorkingPath, kDevicePathSpecifier.Length());
// If useDOSDevicePathSyntax are different remove the prefix from the one that
// might have it. This is added because of Omnijar. It compares files from
// different modules with itself.
bool removePathPrefix, removeInPathPrefix;
if (inUseDOSDevicePathSyntax != mUseDOSDevicePathSyntax) {
removeInPathPrefix = inUseDOSDevicePathSyntax;
removePathPrefix = mUseDOSDevicePathSyntax;
} else {
removePathPrefix = removeInPathPrefix = false;
}
// Ok : Win9x
*aResult = _wcsicmp(shortWorkingPath.get(), inFilePath.get()) == 0;
nsAutoString inFilePath, workingPath;
aInFile->GetPath(inFilePath);
workingPath = mWorkingPath;
constexpr static auto equalPath =
[](nsAutoString& workingPath, nsAutoString& inFilePath,
bool removePathPrefix, bool removeInPathPrefix) {
if (removeInPathPrefix &&
StringBeginsWith(inFilePath, kDevicePathSpecifier)) {
MOZ_ASSERT(!StringBeginsWith(workingPath, kDevicePathSpecifier));
inFilePath = Substring(inFilePath, kDevicePathSpecifier.Length());
} else if (removePathPrefix &&
StringBeginsWith(workingPath, kDevicePathSpecifier)) {
MOZ_ASSERT(!StringBeginsWith(inFilePath, kDevicePathSpecifier));
workingPath = Substring(workingPath, kDevicePathSpecifier.Length());
}
return _wcsicmp(workingPath.get(), inFilePath.get()) == 0;
};
if (equalPath(workingPath, inFilePath, removePathPrefix,
removeInPathPrefix)) {
*aResult = true;
return NS_OK;
}
EnsureShortPath();
lf->GetCanonicalPath(inFilePath);
workingPath = mShortWorkingPath;
*aResult =
equalPath(workingPath, inFilePath, removePathPrefix, removeInPathPrefix);
return NS_OK;
}