mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Backed out 2 changesets (bug 1773186, bug 1772742) for causing mochitest failures in dom/system/tests/ioutils/test_ioutils_hashfile.html
Backed out changeset ef49b1ddf9f1 (bug 1772742) Backed out changeset 8ec51be873d4 (bug 1773186)
This commit is contained in:
parent
c2f658a2a5
commit
3a496831ac
@ -253,17 +253,6 @@ namespace IOUtils {
|
||||
[NewObject]
|
||||
Promise<DOMString> createUniqueDirectory(DOMString parent, DOMString prefix, optional unsigned long permissions = 0755);
|
||||
|
||||
/**
|
||||
* Compute the hash of a file as a hex digest.
|
||||
*
|
||||
* @param path The absolute path of the file to hash.
|
||||
* @param method The hashing method to use.
|
||||
*
|
||||
* @return A promise that resolves to the hex digest of the file's hash in lowercase.
|
||||
*/
|
||||
[NewObject]
|
||||
Promise<UTF8String> computeHexDigest(DOMString path, HashAlgorithm method);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
/**
|
||||
* Return the Windows-specific file attributes of the file at the given path.
|
||||
@ -590,11 +579,6 @@ dictionary FileInfo {
|
||||
unsigned long permissions;
|
||||
};
|
||||
|
||||
/**
|
||||
* The supported hash algorithms for |IOUtils.hashFile|.
|
||||
*/
|
||||
enum HashAlgorithm { "sha1", "sha256", "sha384", "sha512" };
|
||||
|
||||
#ifdef XP_WIN
|
||||
/**
|
||||
* Windows-specific file attributes.
|
||||
|
@ -41,11 +41,8 @@
|
||||
#include "nsIDirectoryEnumerator.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsLocalFile.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsString.h"
|
||||
@ -57,8 +54,6 @@
|
||||
#include "prio.h"
|
||||
#include "prtime.h"
|
||||
#include "prtypes.h"
|
||||
#include "ScopedNSSTypes.h"
|
||||
#include "secoidt.h"
|
||||
|
||||
#if defined(XP_UNIX) && !defined(ANDROID)
|
||||
# include "nsSystemInfo.h"
|
||||
@ -812,32 +807,6 @@ already_AddRefed<Promise> IOUtils::CreateUnique(GlobalObject& aGlobal,
|
||||
});
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Promise> IOUtils::ComputeHexDigest(
|
||||
GlobalObject& aGlobal, const nsAString& aPath,
|
||||
const HashAlgorithm aAlgorithm, ErrorResult& aError) {
|
||||
const bool nssInitialized = EnsureNSSInitializedChromeOrContent();
|
||||
|
||||
return WithPromiseAndState(
|
||||
aGlobal, aError, [&](Promise* promise, auto& state) {
|
||||
if (!nssInitialized) {
|
||||
RejectJSPromise(promise,
|
||||
IOError(NS_ERROR_UNEXPECTED)
|
||||
.WithMessage("Could not initialize NSS"));
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> file = new nsLocalFile();
|
||||
REJECT_IF_INIT_PATH_FAILED(file, aPath, promise);
|
||||
|
||||
DispatchAndResolve<nsCString>(state->mEventQueue, promise,
|
||||
[file = std::move(file), aAlgorithm]() {
|
||||
return ComputeHexDigestSync(file,
|
||||
aAlgorithm);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
||||
/* static */
|
||||
@ -1750,86 +1719,6 @@ Result<nsString, IOUtils::IOError> IOUtils::CreateUniqueSync(
|
||||
return path;
|
||||
}
|
||||
|
||||
/* static */
|
||||
Result<nsCString, IOUtils::IOError> IOUtils::ComputeHexDigestSync(
|
||||
nsIFile* aFile, const HashAlgorithm aAlgorithm) {
|
||||
static constexpr size_t BUFFER_SIZE = 8192;
|
||||
|
||||
SECOidTag alg;
|
||||
switch (aAlgorithm) {
|
||||
case HashAlgorithm::Sha1:
|
||||
alg = SEC_OID_SHA1;
|
||||
break;
|
||||
|
||||
case HashAlgorithm::Sha256:
|
||||
alg = SEC_OID_SHA256;
|
||||
break;
|
||||
|
||||
case HashAlgorithm::Sha384:
|
||||
alg = SEC_OID_SHA384;
|
||||
break;
|
||||
|
||||
case HashAlgorithm::Sha512:
|
||||
alg = SEC_OID_SHA512;
|
||||
break;
|
||||
|
||||
default:
|
||||
MOZ_RELEASE_ASSERT(false, "Unexpected HashAlgorithm");
|
||||
}
|
||||
|
||||
Digest digest;
|
||||
if (nsresult rv = digest.Begin(alg); NS_FAILED(rv)) {
|
||||
return Err(IOError(rv).WithMessage("Could not hash file at %s",
|
||||
aFile->HumanReadablePath().get()));
|
||||
}
|
||||
|
||||
RefPtr<nsIInputStream> stream;
|
||||
if (nsresult rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), aFile);
|
||||
NS_FAILED(rv)) {
|
||||
return Err(IOError(rv).WithMessage("Could not open the file at %s",
|
||||
aFile->HumanReadablePath().get()));
|
||||
}
|
||||
|
||||
char buffer[BUFFER_SIZE];
|
||||
uint32_t read = 0;
|
||||
for (;;) {
|
||||
if (nsresult rv = stream->Read(buffer, BUFFER_SIZE, &read); NS_FAILED(rv)) {
|
||||
return Err(IOError(rv).WithMessage(
|
||||
"Encountered an unexpected error while reading file(%s)",
|
||||
aFile->HumanReadablePath().get()));
|
||||
}
|
||||
if (read == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (nsresult rv =
|
||||
digest.Update(reinterpret_cast<unsigned char*>(buffer), read);
|
||||
NS_FAILED(rv)) {
|
||||
return Err(IOError(rv).WithMessage("Could not hash file at %s",
|
||||
aFile->HumanReadablePath().get()));
|
||||
}
|
||||
}
|
||||
|
||||
AutoTArray<uint8_t, SHA512_LENGTH> rawDigest;
|
||||
if (nsresult rv = digest.End(rawDigest); NS_FAILED(rv)) {
|
||||
return Err(IOError(rv).WithMessage("Could not hash file at %s",
|
||||
aFile->HumanReadablePath().get()));
|
||||
}
|
||||
|
||||
nsCString hexDigest;
|
||||
if (!hexDigest.SetCapacity(2 * rawDigest.Length(), fallible)) {
|
||||
return Err(IOError(NS_ERROR_OUT_OF_MEMORY));
|
||||
}
|
||||
|
||||
const char HEX[] = "0123456789abcdef";
|
||||
for (uint8_t b : rawDigest) {
|
||||
hexDigest.Append(HEX[(b >> 4) & 0xF]);
|
||||
hexDigest.Append(HEX[b & 0xF]);
|
||||
}
|
||||
|
||||
return hexDigest;
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
||||
Result<uint32_t, IOUtils::IOError> IOUtils::GetWindowsAttributesSync(
|
||||
|
@ -157,10 +157,6 @@ class IOUtils final {
|
||||
ErrorResult& aError);
|
||||
|
||||
public:
|
||||
static already_AddRefed<Promise> ComputeHexDigest(
|
||||
GlobalObject& aGlobal, const nsAString& aPath,
|
||||
const HashAlgorithm aAlgorithm, ErrorResult& aError);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
static already_AddRefed<Promise> GetWindowsAttributes(GlobalObject& aGlobal,
|
||||
const nsAString& aPath,
|
||||
@ -455,17 +451,6 @@ class IOUtils final {
|
||||
static Result<nsString, IOError> CreateUniqueSync(
|
||||
nsIFile* aFile, const uint32_t aFileType, const uint32_t aPermissions);
|
||||
|
||||
/**
|
||||
* Compute the hash of a file.
|
||||
*
|
||||
* @param aFile The file to hash.
|
||||
* @param aAlgorithm The hashing algorithm to use.
|
||||
*
|
||||
* @return The hash of the file, as a hex digest.
|
||||
*/
|
||||
static Result<nsCString, IOError> ComputeHexDigestSync(
|
||||
nsIFile* aFile, const HashAlgorithm aAlgorithm);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
/**
|
||||
* Return the Windows-specific attributes of the file.
|
||||
|
@ -7,7 +7,6 @@ support-files =
|
||||
[test_ioutils_copy_move.html]
|
||||
[test_ioutils_create_unique.html]
|
||||
[test_ioutils_dir_iteration.html]
|
||||
[test_ioutils_hashfile.html]
|
||||
[test_ioutils_mac_xattr.html]
|
||||
skip-if = (os != "mac")
|
||||
[test_ioutils_mkdir.html]
|
||||
|
@ -1,55 +0,0 @@
|
||||
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test the IOUtils file I/O API</title>
|
||||
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
<script src="file_ioutils_test_fixtures.js"></script>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
add_task(async function test_hashFile() {
|
||||
const tempDir = PathUtils.join(PathUtils.tempDir, "ioutils-test-hashfile.tmp.d");
|
||||
await createDir(tempDir);
|
||||
|
||||
const path = PathUtils.join(tempDir, "file");
|
||||
await IOUtils.writeUTF8(path, "hello world\n");
|
||||
|
||||
const DIGESTS = [
|
||||
"22596363b3de40b06f981fb85d82312e8c0ed511",
|
||||
"a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447",
|
||||
"6b3b69ff0a404f28d75e98a066d3fc64fffd9940870cc68bece28545b9a75086b343d7a1366838083e4b8f3ca6fd3c80",
|
||||
"db3974a97f2407b7cae1ae637c0030687a11913274d578492558e39c16c017de84eacdc8c62fe34ee4e12b4b1428817f09b6a2760c3f8a664ceae94d2434a593",
|
||||
];
|
||||
const ALGORITHMS = ["sha1", "sha256", "sha384", "sha512"];
|
||||
|
||||
for (let i = 0; i < ALGORITHMS.length; i++) {
|
||||
const alg = ALGORITHMS[i];
|
||||
const expected = DIGESTS[i];
|
||||
|
||||
Assert.equal(
|
||||
await IOUtils.hashFile(path, alg),
|
||||
expected,
|
||||
`IOUtils.hashFile() has expected value for ${alg}`);
|
||||
}
|
||||
|
||||
await cleanup(tempDir);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -44,7 +44,7 @@ add_task(async function skipDialogAndDownloadFile() {
|
||||
BrowserTestUtils.removeTab(loadingTab);
|
||||
|
||||
Assert.ok(
|
||||
await IOUtils.exists(download.target.path),
|
||||
await OS.File.exists(download.target.path),
|
||||
"The file should have been downloaded."
|
||||
);
|
||||
|
||||
|
@ -61,7 +61,7 @@ async function aDownloadLaunchedWithAppIsSavedInFolder(downloadDir) {
|
||||
);
|
||||
|
||||
Assert.ok(
|
||||
await IOUtils.exists(download.target.path),
|
||||
await OS.File.exists(download.target.path),
|
||||
"The file should not have been deleted."
|
||||
);
|
||||
|
||||
|
@ -13,6 +13,7 @@ var { AppConstants } = ChromeUtils.import(
|
||||
);
|
||||
var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
|
||||
var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
var { OS, require } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
@ -34,7 +35,7 @@ XPCOMUtils.defineLazyServiceGetter(
|
||||
|
||||
do_get_profile();
|
||||
|
||||
let jsonPath = PathUtils.join(PathUtils.profileDir, "handlers.json");
|
||||
let jsonPath = OS.Path.join(OS.Constants.Path.profileDir, "handlers.json");
|
||||
|
||||
/**
|
||||
* Unloads the nsIHandlerService data store, so the back-end file can be
|
||||
@ -57,7 +58,7 @@ let unloadHandlerStore = async function() {
|
||||
let deleteHandlerStore = async function() {
|
||||
await unloadHandlerStore();
|
||||
|
||||
await IOUtils.remove(jsonPath, { ignoreAbsent: true });
|
||||
await OS.File.remove(jsonPath, { ignoreAbsent: true });
|
||||
|
||||
Services.prefs.clearUserPref("gecko.handlerService.defaultHandlersVersion");
|
||||
};
|
||||
@ -68,7 +69,7 @@ let deleteHandlerStore = async function() {
|
||||
let copyTestDataToHandlerStore = async function() {
|
||||
await unloadHandlerStore();
|
||||
|
||||
await IOUtils.copy(do_get_file("handlers.json").path, jsonPath);
|
||||
await OS.File.copy(do_get_file("handlers.json").path, jsonPath);
|
||||
|
||||
Services.prefs.setIntPref("gecko.handlerService.defaultHandlersVersion", 100);
|
||||
};
|
||||
|
@ -654,7 +654,7 @@ add_task(async function test_store_keeps_unknown_properties() {
|
||||
gHandlerService.store(handlerInfo);
|
||||
|
||||
await unloadHandlerStore();
|
||||
let data = await IOUtils.readJSON(jsonPath);
|
||||
let data = JSON.parse(new TextDecoder().decode(await OS.File.read(jsonPath)));
|
||||
Assert.equal(
|
||||
data.mimeTypes["example/type.handleinternally"].unknownProperty,
|
||||
"preserved"
|
||||
@ -743,7 +743,7 @@ add_task(async function test_store_gioHandlerApp() {
|
||||
possibleApplicationHandlers: [expectedGIOMimeHandlerApp, webHandlerApp],
|
||||
});
|
||||
|
||||
await IOUtils.remove(dummyHandlerFile.path);
|
||||
await OS.File.remove(dummyHandlerFile.path);
|
||||
|
||||
// After removing dummyHandlerFile, the handler should disappear from the
|
||||
// list of possibleApplicationHandlers and preferredAppHandler should be null.
|
||||
|
Loading…
Reference in New Issue
Block a user