mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Backed out changeset f154c83412cf (bug 1660328) for build bustages on IOUtils.cpp CLOSED TREE
This commit is contained in:
parent
bfefe67857
commit
b342cdb618
@ -145,18 +145,6 @@ namespace IOUtils {
|
||||
* DOMException.
|
||||
*/
|
||||
Promise<long long> touch(DOMString path, optional long long modification);
|
||||
/**
|
||||
* Retrieves a (possibly empty) list of immediate children of the directory at
|
||||
* |path|. If the file at |path| is not a directory, this method resolves with
|
||||
* an empty list.
|
||||
*
|
||||
* @param path An absolute file path.
|
||||
*
|
||||
* @return Resolves with a sequence of absolute file paths representing the
|
||||
* children of the directory at |path|, otherwise rejects with a
|
||||
* DOMException.
|
||||
*/
|
||||
Promise<sequence<DOMString>> getChildren(DOMString path);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -5,15 +5,12 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/IOUtils.h"
|
||||
#include "ErrorList.h"
|
||||
#include "mozilla/dom/IOUtilsBinding.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/ErrorNames.h"
|
||||
#include "mozilla/ResultExtensions.h"
|
||||
#include "mozilla/Span.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIDirectoryEnumerator.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nspr/prerror.h"
|
||||
#include "nspr/prio.h"
|
||||
@ -78,16 +75,13 @@ namespace dom {
|
||||
* @see nsLocalFileUnix.cpp
|
||||
*/
|
||||
static bool IsFileNotFound(nsresult aResult) {
|
||||
return aResult == NS_ERROR_FILE_NOT_FOUND ||
|
||||
aResult == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
||||
}
|
||||
/**
|
||||
* Like |IsFileNotFound|, but checks for known results that suggest a file
|
||||
* is not a directory.
|
||||
*/
|
||||
static bool IsNotDirectory(nsresult aResult) {
|
||||
return aResult == NS_ERROR_FILE_DESTINATION_NOT_DIR ||
|
||||
aResult == NS_ERROR_FILE_NOT_DIRECTORY;
|
||||
switch (aResult) {
|
||||
case NS_ERROR_FILE_NOT_FOUND:
|
||||
case NS_ERROR_FILE_TARGET_DOES_NOT_EXIST:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -433,20 +427,6 @@ already_AddRefed<Promise> IOUtils::Touch(
|
||||
return RunOnBackgroundThread<int64_t>(promise, &TouchSync, path, newTime);
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Promise> IOUtils::GetChildren(GlobalObject& aGlobal,
|
||||
const nsAString& aPath) {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
RefPtr<Promise> promise = CreateJSPromise(aGlobal);
|
||||
NS_ENSURE_TRUE(!!promise, nullptr);
|
||||
|
||||
REJECT_IF_RELATIVE_PATH(aPath, promise);
|
||||
nsAutoString path(aPath);
|
||||
|
||||
return RunOnBackgroundThread<nsTArray<nsString>>(promise, &GetChildrenSync,
|
||||
path);
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<nsISerialEventTarget> IOUtils::GetBackgroundEventTarget() {
|
||||
if (sShutdownStarted) {
|
||||
|
@ -94,9 +94,6 @@ class IOUtils final {
|
||||
GlobalObject& aGlobal, const nsAString& aPath,
|
||||
const Optional<int64_t>& aModification);
|
||||
|
||||
static already_AddRefed<Promise> GetChildren(GlobalObject& aGlobal,
|
||||
const nsAString& aPath);
|
||||
|
||||
static bool IsAbsolutePath(const nsAString& aPath);
|
||||
|
||||
private:
|
||||
@ -328,17 +325,6 @@ class IOUtils final {
|
||||
*/
|
||||
static Result<int64_t, IOError> TouchSync(const nsAString& aPath,
|
||||
const Maybe<int64_t>& aNewModTime);
|
||||
|
||||
/**
|
||||
* Returns the immediate children of the file at |aPath|, if any.
|
||||
*
|
||||
* @param aPath The location of the file as an absolute path string.
|
||||
*
|
||||
* @return An array of absolute paths identifying the children of |aPath|.
|
||||
* If there are no children, an empty array. Otherwise, an error.
|
||||
*/
|
||||
static Result<nsTArray<nsString>, IOError> GetChildrenSync(
|
||||
const nsAString& aPath);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,6 @@ support-files =
|
||||
|
||||
[test_ioutils.html]
|
||||
[test_ioutils_copy_move.html]
|
||||
[test_ioutils_dir_iteration.html]
|
||||
[test_ioutils_mkdir.html]
|
||||
[test_ioutils_read_write.html]
|
||||
[test_ioutils_read_write_utf8.html]
|
||||
|
@ -1,84 +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 { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
|
||||
const tmpDir = OS.Constants.Path.tmpDir;
|
||||
|
||||
add_task(async function iterate_dir_failure() {
|
||||
let notExists = OS.Path.join(tmpDir, 'does_not_exist_dir.tmp.d');
|
||||
|
||||
await Assert.rejects(
|
||||
IOUtils.getChildren(notExists),
|
||||
/Could not get children of file\(.*\) because it does not exist/,
|
||||
"IOUtils::getChildren rejects if the file does not exist"
|
||||
);
|
||||
ok(!await fileExists(notExists), `Expected ${notExists} not to exist`);
|
||||
|
||||
info('Try to get the children of a regular file');
|
||||
|
||||
let tmpFileName = OS.Path.join(tmpDir, 'iterator_file.tmp');
|
||||
await createFile(tmpFileName)
|
||||
await Assert.rejects(IOUtils.getChildren(tmpFileName),
|
||||
/Could not get children of file\(.*\) because it is not a directory/,
|
||||
"IOUtils::getChildren rejects if the file is not a dir"
|
||||
);
|
||||
|
||||
await cleanup(tmpFileName);
|
||||
});
|
||||
|
||||
add_task(async function iterate_dir() {
|
||||
info('Try to get the children of a multi-level directory hierarchy');
|
||||
|
||||
let root = OS.Path.join(tmpDir, 'iterator.tmp.d');
|
||||
let child1 = OS.Path.join(root, 'child1.tmp');
|
||||
let child2 = OS.Path.join(root, 'child2.tmp');
|
||||
let grandchild = OS.Path.join(child1, 'grandchild.tmp');
|
||||
|
||||
await createDir(grandchild); // Ancestors will be created.
|
||||
await createDir(child2);
|
||||
|
||||
let entries = await IOUtils.getChildren(root);
|
||||
|
||||
is(entries.length, 2, `Expected 2 entries below the path at ${root}`);
|
||||
ok(!entries.includes(grandchild), "IOUtils::getChildren does not enter subdirectories");
|
||||
|
||||
await cleanup(root);
|
||||
});
|
||||
|
||||
add_task(async function iterate_empty_dir() {
|
||||
info('Try to get the children of an empty directory');
|
||||
|
||||
let emptyDir = OS.Path.join(tmpDir, 'iterator_empty_dir.tmp.d');
|
||||
await createDir(emptyDir);
|
||||
|
||||
is(
|
||||
(await IOUtils.getChildren(emptyDir)).length,
|
||||
0,
|
||||
"IOUtils::getChildren return an empty array when called on an empty dir"
|
||||
);
|
||||
|
||||
await cleanup(emptyDir);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user